W3C home > Mailing lists > Public > public-device-apis-log@w3.org > February 2017

Re: [sensors] Batching API for sensor readings

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
Message-ID: <issue_comment.created-282003666-1487859732-sysbot+gh@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

This archive was generated by hypermail 2.4.0 : Monday, 4 July 2022 12:47:53 UTC