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:
Map of all available properties
: this method also supports async callbacks - check the Callback tab for callback return parameters.
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:
Map of properties I want to know about
: this method also supports async callbacks - check the Callback tab for callback return parameters.
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:
The property to return info about.
: this method also supports async callbacks - check the Callback tab for callback return parameters.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:
Returns a sensor object for the sensor type passed as parameter. You can use the type field along with the Rho.Sensor Constants to see what type of sensor is returned.
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:
Current sensor data – format is the same with callback specified for start method.
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/s2)
Y co-ordinate value of the Accelerometer sensor in SI units (m/s2)
Z co-ordinate value of the Accelerometer sensor in SI units (m/s2)
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 Symbol 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.
X co-ordinate value of the gyroscope sensor in radians/second.
X co-ordinate value of the gyroscope sensor in radians/second.
Value of the ambient Light sensor in SI lux units.
Value of the proximity sensor in centimeters.
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 as a percentage.
X co-ordinate value of the gravity sensor in SI units (m/s2)
Y co-ordinate value of the gravity sensor in SI units (m/s2)
Z co-ordinate value of the gravity sensor in SI units (m/s2)
X co-ordinate value of the linear acceleration sensor in SI units (m/s2)
Y co-ordinate value of the linear acceleration sensor in SI units (m/s2)
Z co-ordinate value of the linear acceleration sensor in SI units (m/s2)
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()
The minimum amount of time gap between two sensor update events, specified in milliseconds. The interval cannot be set to less than 200 milliseconds, if a value of less than 200 milliseconds is specified, the interval will be defaulted to 200 milliseconds.
Default: 200
Property Access:
myObject.minimumGap
Current status: not_ready, ready, started, error etc.
Property Access:
myObject.status
Type of current sensor: Accelerometer, Magnetometer, etc.
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 initializing / calibrating of HW etc.
Sensor is ready to start listening.
Sensor already started to listening.
Sensor in error state.
The below example gets the Accelerometer values for every 500 milliseconds.
#/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.
In Android, as supported sensors could vary from product to product so please refer to Device’s PRD/TRD for the list of supported sensors in that particular device.