- From: Mikhail Pozdnyakov via GitHub <sysbot+gh@w3.org>
- Date: Thu, 23 Feb 2017 14:22:14 +0000
- To: public-device-apis-log@w3.org
I would like to propose the following approach:
```
interface MotionSensor : Sensor {
/**
* Populates the passed array with the latest readings recorded
right before the next
* repaint.
*
* The array length must be equal to Reading Size * N, where N is
the desired number
* of readings to collect.
* Note: calling of this method can be expensive as it might require
starting of a
* high frequency timer.
*/
void collectLatestReadings(Float64Array array);
}
```
example usage:
```
let gyro = Gyroscope({frequency: 240});
const readingSize = 4; // tymestamp, x, y, z
let buffer = Float64Array(readingSize * 4);
gyro.start();
gyro.collectLatestReadings(buffer);
function step(timestamp) {
// Now 'buffer' contains recorded readings.
gyro.collectLatestReadings(buffer); // Collect further.
window.requestAnimationFrame(step);
}
window.requestAnimationFrame(step);
```
Also I would drop 'onchnage' event for motion sensors as it does not
bring much benefits there and on the other hand it is called too often
draining CPU and battery.
--
GitHub Notification of comment by pozdnyakov
Please view or discuss this issue at
https://github.com/w3c/sensors/issues/171#issuecomment-282003666 using
your GitHub account
Received on Thursday, 23 February 2017 14:22:20 UTC