172
edits
| (9 intermediate revisions by the same user not shown) | |||
| Line 15: | Line 15: | ||
== Proposed API == | == Proposed API == | ||
<pre> | |||
interface SensorManager : EventTarget { | interface SensorManager : EventTarget { | ||
// Creates a new session to interact with a sensor | |||
SensorSession newSession(in DOMString sensorName,in optional SensorSessionOptions options) raises SensorNotFound; | SensorSession newSession(in DOMString sensorName,in optional SensorSessionOptions options) | ||
raises SensorNotFound; | |||
// The list of open sessions | |||
attribute sequence<SensorSession> openSessions; | attribute sequence<SensorSession> openSessions; | ||
sequence<Sensor> listSensors(); // List the available sensors on the device | sequence<Sensor> listSensors(); // List the available sensors on the device | ||
attribute Function onSensorAvailable; | attribute Function onSensorAvailable; | ||
}; | }; | ||
interface Sensor : EventTarget { | interface Sensor : EventTarget { | ||
readonly attribute DOMString type; // Vocabulary to be defined ("Acceleration", "AmbientLight") | |||
readonly attribute DOMString | readonly attribute DOMString name; // ("Accelerometer", "Compass", "Thermometer") | ||
// ("Accelerometer", "Compass", "Thermometer") | |||
// Another method to retrieve capabilities?? | // Another method to retrieve capabilities?? | ||
}; | }; | ||
interface SensorSession : EventTarget { | interface SensorSession : EventTarget { | ||
readonly attribute Sensor sensor; | readonly attribute Sensor sensor; | ||
| Line 45: | Line 46: | ||
attribute Function onError; | attribute Function onError; | ||
}; | }; | ||
interface SensorData { | interface SensorData { | ||
readonly attribute any value; | readonly attribute any value; | ||
}; | }; | ||
// New DOM Event 'sensordata' | // New DOM Event 'sensordata' | ||
interface SensorDataEvent : Event { | interface SensorDataEvent : Event { | ||
| Line 56: | Line 59: | ||
in SensorData data); | in SensorData data); | ||
}; | }; | ||
interface SensorWatchOptions { | interface SensorWatchOptions { | ||
// High threshold. If the sensor value is higher a data event will be raised | |||
attribute any | attribute any highThreshold; | ||
attribute | // Low threshold. If the sensor value is lower a data event will be raised | ||
attribute double | attribute any lowThreshold; | ||
// Notify only when a relative change in the magnitude meausured by the sensor occurs | |||
attribute double relativeThreshold; | |||
// Interval at which values will be provided by the sensor (milliseconds) | |||
attribute double interval; | |||
}; | }; | ||
</pre> | |||
Example of use | Example of use | ||
var accelerometer = navigator.sensor.newSession('Accelerometer') | <pre> | ||
var accelerometer = navigator.sensor.newSession('Accelerometer'); | |||
session.onSensorData = function(e) { | session.onSensorData = function(e) { | ||
window.console.log('New accelerometer data'); | window.console.log('New accelerometer data'); | ||
window.console.log('Acceleration along the x axis: ' + e.value.x); | window.console.log('Acceleration along the x axis: ' + e.value.x); | ||
} | }; | ||
var watchOptions = { interval | var watchOptions = { interval: 1.0 }; // Every one millisecond | ||
accelerometer.watch(watchOptions); | |||
</pre> | |||
edits