Sensor Class
Sensor class manages all operations with hardware sensors.
Methods
this
(
Sensor
type
interval
Constructor creates new Sensor object, which provides access to various types of sensors.
Parameters:
-
type
SymbolType of sensor.
- #acceleration
- #magnetic
- #proximity
- #tilt
-
interval
IntervalTime interval in milliseconds.
Returns:
Sensor: Created new instance of sensor class
Example:
var sensor = new Sensor(#acceleration, 40);
// setup handler for receiving data
sensor.onDataReceived = function(sender, timestamp, params) {
var (x, y, z) = (params[0], params[1], params[2]);
};
// start receiving data
sensor.start();
dispose
()
Clears all resources from memory.
isAvailable
(
Boolean
type
Check if sensor is available on the device. Otherwise it returns false.
Parameters:
-
type
SymbolType of sensor.
- #acceleration [/li]
- #magnetic [/li]
- #proximity [/li]
- #tilt
Returns:
Boolean: True if sensor is available on the device. Otherwise it returns false.
Example:
if (!Sensor.isAvailable(#acceleration))
System.messageBox("No accelometer detected!");
pause
()
Pause sending callback data.
resume
()
Resume sending callback data.
start
()
This function starts sending data from sensor. When new data are available, object calls callback functions.
Example:
var sensor = new Sensor(#acceleration, 40);
// setup handler for receiving data
sensor.onDataReceived = function(sender, timestamp, params) {
var (x, y, z) = (params[0], params[1], params[2]);
};
// start receiving data
sensor.start();
Events
onDataReceived
Sensor calls this callback function, when new data is available.
Event Payload:
-
timestamp
IntegerTimestamp information.
-
params
ArrayData from sensor. Usually three values, except proximity sensor. Proximity sensor returns only one value in the array.
Example:
var sensor = new Sensor(#acceleration, 40);
// setup handler for receiving data
sensor.onDataReceived = function(sender, timestamp, params) {
var (x, y, z) = (params[0], params[1], params[2]);
};
// start receiving data
sensor.start();