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. ## Enabling the API In order to use this API you must include the following extension in your `build.yml`. :::ruby extensions: ["sensor"] ## JavaScript Usage Be sure to review the [JavaScript API Usage](/guide/api_js) guide for important information about using this API in JavaScript. ## Ruby Usage Be sure to review the [Ruby API Usage](/guide/api_ruby) guide for important information about using this API in Ruby. ## Enabling the API There are two methods of enabling the Sensor API: * Include all ebapi modules or * Include only the API modules you need For either of these methods, you'll need to include files from the `/Enterprise Browser/JavaScript Files/Enterprise Browser` directory on the computer that you installed the Enterprise Browser. ### Include all JS API modules To include all JS APIs, you must copy the ebapi-modules.js file to a location accessible by your app's files and include the JavaScript file in your app. For instance, to include the modules file in your index.html, with the file in the same directory as your index.html, you would add the following line to the <head> section of your index.html: :::html <script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script> > Note: that the pathing for this file is relative to the current page. This will define the EB class within the page. Any page you need to use the modules will need to have the .js file included in this fashion. ### Include only the modules you need To include single APIs, you must first include the `ebapi.js` in your HTML as well as the API file you want to use. For instance, to use the Sensor API, I would add the following code to my HTML file(s), assuming the API files have been copied to the same directory as the HTML. :::html <script type="text/javascript" charset="utf-8" src="ebapi.js"></script> <script type="text/javascript" charset="utf-8" src="eb.sensor.js"></script> The ebapi.js file is necessary for all single API inclusions. WM, CE, Android, iOS Android, WM, CE 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. These properties are used to configure the Camera. 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. Type of current sensor: Accelerometer, Magnetometer, etc. Current status: not_ready, ready, started, error etc. Return the new sensor object by type. Sensor type. Use the appropriate constants to get the sensor type. In the case of accelerometer use SENSOR_TYPE_ACCELEROMETER. 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. WM, CE, Android, iOS Android, WM, CE This enables the sensor data retrieval. Call start on the instance returned from the makeSensorByType. WM, CE, Android, iOS Android, WM, CE The callback is triggered with the sensors values according to sensor type when a parameter of the sensor is changed. Each sensor sends to the callback different object types - see sensor prefix of value name. All sensors will contain a status and message parameter in the callback. 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 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/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. Read current sensor data from the sensor object retrieved by using makeSensorByType. Current sensor data - format is the same with callback specified for start method. > WM, CE, Android, iOS Android, WM, CE 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. WM, CE, Android, iOS Android, WM, CE 2.0.0 Android, WM, iOS Android, WM 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.
The below example gets the Accelerometer values for every 500 milliseconds. :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 ]]>