w3c / sensors

Generic Sensor API
https://www.w3.org/TR/generic-sensor/
Other
127 stars 59 forks source link

Interface for user-involving calibration? #324

Open martijnthe opened 6 years ago

martijnthe commented 6 years ago

I'm wondering what your thoughts are w.r.t. sensors that require a calibration process involving the user (for example the well known "compass calibration dance").

Is the environment that hosts the Sensor interface supposed to take care of presenting a calibration UI as needed – for example, automatically presenting the calibration UI when an uncalibrated Sensor is start()ed? Is the idea that this is "transparent" to the consumer of the Sensor interface, i.e. defer the onactivate callback until the calibration process has successfully completed?

I wonder if it would make sense to offer a bit of control to the application that uses Sensor. I imagine it may lead to a better UX if the application can read the calibration status and trigger the process to calibrate it. This way the application can explain to the user it wants to access the Sensor and why, before triggering the calibration UI. Automatically triggering the calibration UI may be a bad UX...

Thoughts?

alexshalamov commented 6 years ago

@martijnthe dynamic calibration might be a nice feature, especially for magnetometer and fusion sensors that use it. However, if I remember correctly, none of the platform APIs provide such functionality, thus, it would be challenging to implement such feature in the browser.

On the lowest level, in addition to e.g., temperature or ALS window factory calibration, sensors may expose dynamic calibration routines, yet, these are rarely exposed to application / middleware layer.

Do you have any suggestions or ideas how this can be implemented across all platforms?

alexshalamov commented 6 years ago

@pozdnyakov We might use 'accuracy' as a hint for required calibration, wdyt? We already have an issue for that https://github.com/w3c/sensors/issues/154

Accuracy level is exposed on many platforms.

martijnthe commented 6 years ago

@alexshalamov thanks for your comments.

Some ideas w.r.t. the API design, while keeping in mind:

  1. it may not make sense to calibrate a particular class of Sensor.
  2. it may not be possible to actual calibrate the sensor due to lack of platform support.
enum SensorCalibrationStatus {
  "unavailable",
  "uncalibrated",
  "calibrated",
}

interface Sensor :  EventTarget {
  readonly attribute SensorCalibrationStatus calibrationStatus;
  void calibrate();
  attribute EventHandler oncalibrationchange;
  ...
}

Re. 1 & 2: if a sensor doesn't need to be calibrated or cannot be calibrated for whatever reason, calibrationStatus would return "unavailable". calibrate() would be a no-op in that case and oncalibrationchange would never fire.