The Sensors extension is used to retrieve the raw data values of the specified sensors (accelerometer, tilt angle, device orientation, motion, eCompass, magnetometer, gyroscope, ambient light, proximity, proximity long range, pressure, temperature, humidity, gravity, linear acceleration, rotation, orientation etc.) from the device. To use this, you have to first call makeSensorByType to get an instance of that sensor. Then you can use the start and stop methods on that instance.
In order to use this API you must include the following extension in your build.yml
extensions: ["sensor"]
Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript
Be sure to review the Ruby API Usage guide for important information about using this API in Ruby
This method will return all of object/value pairs for the propertyNames of the API class.
Parameters
Async Callback Returning Parameters: HASH
Synchronous Return:
Method Access:
myObject.getAllProperties(CallBackHandler callback)
This method will return a set of object/value pairs for the list of the propertyName that is passed in. The propertyNames must be a valid property of the API class.
Parameters
List of properties I want to know about
Async Callback Returning Parameters: HASH
Synchronous Return:
Method Access:
myObject.getProperties(ARRAY arrayofNames, CallBackHandler callback)
This method will return the value of the propertyName that is passed in. The propertyName must be a valid property of the API class.
Parameters
The property to return info about.
Async Callback Returning Parameters: STRING
Synchronous Return:
Method Access:
myObject.getProperty(STRING propertyName, CallBackHandler callback)
Return the new sensor object by type
Parameters
sensor type. Use the appropriate constants to get the sensor type. In the case of accelerometer use SENSOR_TYPE_ACCELEROMETER
Synchronous Return:
Method Access:
Rho.Sensor.makeSensorByType(STRING type)
Rho::Sensor.makeSensorByType(STRING type)
Read current sensor data from the sensor object retrieved by using makeSensorByType
Synchronous Return:
Method Access:
myObject.readData()
This method will set the values of a list of properties for the API class. The propertyName must be a valid property for the class and must also not be read only.
Parameters
Map of properties I want to set
Synchronous Return:
Method Access:
myObject.setProperties(HASH propertyMap)
This method will set the value of a property for the API class. The propertyName must be a valid property for the class and must also not be read only.
Parameters
The one property name that I want to set
The one property value that I want to set
Synchronous Return:
Method Access:
myObject.setProperty(STRING propertyName, STRING propertyValue)
This enables the sensor data retrieval. Call start on the instance returned from the makeSensorByType.
Parameters
Async Callback Returning Parameters: HASH
status: ok, error
only if status=error, contain error message
X co-ordinate value of the Accelerometer sensor in SI units (m/s^2)
Y co-ordinate value of the Accelerometer sensor in SI units (m/s^2)
Z co-ordinate value of the Accelerometer sensor in SI units (m/s^2)
X co-ordinate value of the tiltangle sensor in degrees units
Y co-ordinate value of the tiltangle sensor in degrees units
Z co-ordinate value of the tiltangle sensor in degrees units
The values of the Orientation sensor. Possible values include Portrait Down, Portrait Up, Landscape Left, Landscape Right, Face Up, Face Down. Applicable only for Zebra Windows Mobile/CE devices with Sensor support.
Value from the Motion sensor
Value from the E-Compass sensor
X value of the magnetometer sensor in micro-Tesla (uT) units
Y value of the magnetometer sensor in micro-Tesla (uT) units
Z value of the magnetometer sensor in micro-Tesla (uT) units
X co-ordinate value of the gyroscope sensor in radians/second units
X co-ordinate value of the gyroscope sensor in radians/second units
X co-ordinate value of the gyroscope sensor in radians/second units
Value of the ambient Light sensor in SI lux units
Value of the proximity sensor in centimeters units
Value of the proximitylongrange sensor
Value of the pressure sensor in hPa (millibar) units
Value of the temperature sensor in degree Celsius units
Value of the humidity sensor in percent units
X co-ordinate value of the gravity sensor in SI units (m/s^2)
Y co-ordinate value of the gravity sensor in SI units (m/s^2)
Z co-ordinate value of the gravity sensor in SI units (m/s^2)
X co-ordinate value of the linear acceleration sensor in SI units (m/s^2)
Y co-ordinate value of the linear acceleration sensor in SI units (m/s^2)
Z co-ordinate value of the linear acceleration sensor in SI units (m/s^2)
X co-ordinate value of the rotation sensor as a combination of an angle and an axis
Y co-ordinate value of the rotation sensor as a combination of an angle and an axis
Z co-ordinate value of the rotation sensor as a combination of an angle and an axis
X co-ordinate value of the orientation sensor in degrees units
Y co-ordinate value of the orientation sensor in degrees units
Z co-ordinate value of the orientation sensor in degrees units
Synchronous Return:
Method Access:
myObject.start(CallBackHandler callback)
Stops listening to the sensor retrieved by using makeSensorType. On Windows Mobile/CE its recommended to call stop on all retrieved sensor objects before exiting a page.
Synchronous Return:
Method Access:
myObject.stop()
Default: 200
Property Access:
myObject.minimumGap
Property Access:
myObject.status
Property Access:
myObject.type
Accelerometer sensor type
TiltAngle sensor type
DeviceOrientation sensor type
Motion sensor type
ECompass sensor type
Magnetometer sensor type
Gyroscope sensor type
AmbientLight sensor type
Proximity sensor type
ProximityLongRange sensor type
Pressure sensor type
Temperature sensor type
Humidity sensor type
Gravity sensor type
LinearAcceleration sensor type
Rotation sensor type
Orientation sensor type
sensor is not ready for start – may be some type of sensor require time for initialising/calibrating of HW etc.
sensor is ready to start listening
sensor already started to listening
sensor in error state
#/app/Model def index @accelerometer_sensor = Rho::Sensor.makeSensorByType(Rho::Sensor::SENSOR_TYPE_ACCELEROMETER) if @accelerometer_sensor != nil @accelerometer_sensor.minimumGap = 500 @accelerometer_sensor.start(url_for(:action => :myevent)) else puts "Warning: This device has not Accelerometer sensor !" end end def stop_listening_accelerator if @accelerometer_sensor != nil @accelerometer_sensor.stop end end def myevent puts "Accelerometer params: #{@params}" puts "X is #{@params['accelerometer_x']}" puts "Y is #{@params['accelerometer_y']}" puts "Z is #{@params['accelerometer_z']}" end
As this extension returns the raw sensor values reported by the operating system the values might differ between platforms. Also as some of the sensor values change rapidly the minimum gap between two updates should be specified as a reasonable value, otherwise there can be a performance impact.