Moscrif API Docs for: 2012q3
Show:

Sensor Class

Library: sensor

Sensor class manages all operations with hardware sensors.

Item Index

Methods

Methods

this

(
  • type
  • interval
)
Sensor

Constructor creates new Sensor object, which provides access to various types of sensors.

Parameters:

  • type Symbol

    Type of sensor.

    • #acceleration
    • #magnetic
    • #proximity
    • #tilt
  • interval Interval

    Time 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

(
  • type
)
Boolean

Check if sensor is available on the device. Otherwise it returns false.

Parameters:

  • type Symbol

    Type 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 Integer

    Timestamp information.

  • params Array

    Data 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();