What is the real meaning of :period and :sampleRate in Sensor.registerSensorDataListener? According to the documentation:
What is the real meaning of :period and :sampleRate in Sensor.registerSensorDataListener? According to the documentation:
A callback event is triggered once every "period" seconds and that callback data contains period seconds worth of data at the sample rate.
If period = 1 and sampleRate = 25 Hz, then callback is called every second and there are 25 samples in that data
if period = 4 and sampleRate = 25 Hz, the callback occurs each 4 seconds and there are 100 samples in that data.
R U guessing? If you read my examples above or better try it for yourself in the simulator then you'll see that what you wrote is not what's happening. At least in the simulator. If that's the way it is supposed to work, then there's a bug in the simulator.
No matter what the period is set to the callback function is being called once a second.
I get a Callback every 4 seconds when period is 4, and every 1 second when period is 1.
Ok - the above screenshots are from an Epix2 running in the simulator. I just tried on a 245 and you are correct, the event is triggered every 1 seconds even though the period is set to 4 seconds. The other strange thing I'm seeing is that the callback is fired multiple times within the same second.
With period set to 1 second, the callback fires 4 times within the same second
With period set to 2 seconds, the callback fires 2 times within the same second
With period set to 3 seconds, it does this - 1 callback each second for 2 seconds followed by 2 callbacks in 1 second
With period set to 4 seconds,the callback fires each second
Very weird - but everything works in the SIM for me on Epix and Fenix 5,6,7 which is my target audience.
OK!!!!! Great! So now it makes sense, and I'll open a bug for the fr245 on the simulator. It's such a shame how much time can be wasted by randomly choosing the wrong device...