com.googlecode.android_scripting.facade
Class SensorManagerFacade
java.lang.Object
com.googlecode.android_scripting.jsonrpc.RpcReceiver
com.googlecode.android_scripting.facade.SensorManagerFacade
public class SensorManagerFacade
- extends RpcReceiver
Exposes the SensorManager related functionality.
Guidance notes
For reasons of economy the sensors on smart phones are usually low cost and, therefore, low
accuracy (usually represented by 10 bit data). The floating point data values obtained from
sensor readings have up to 16 decimal places, the majority of which are noise. On many phones the
accelerometer is limited (by the phone manufacturer) to a maximum reading of 2g. The magnetometer
(which also provides orientation readings) is strongly affected by the presence of ferrous metals
and can give large errors in vehicles, on board ship etc.
Following a startSensingTimed(A,B) api call sensor events are entered into the Event Queue (see
EventFacade). For the A parameter: 1 = All Sensors, 2 = Accelerometer, 3 = Magnetometer and 4 =
Light. The B parameter is the minimum delay between recordings in milliseconds. To avoid
duplicate readings the minimum delay should be 20 milliseconds. The light sensor will probably be
much slower (taking about 1 second to register a change in light level). Note that if the light
level is constant no sensor events will be registered by the light sensor.
Following a startSensingThreshold(A,B,C) api call sensor events greater than a given threshold
are entered into the Event Queue. For the A parameter: 1 = Orientation, 2 = Accelerometer, 3 =
Magnetometer and 4 = Light. The B parameter is the integer value of the required threshold level.
For orientation sensing the integer threshold value is in milliradians. Since orientation events
can exceed the threshold value for long periods only crossing and return events are recorded. The
C parameter is the required axis (XYZ) of the sensor: 0 = No axis, 1 = X, 2 = Y, 3 = X+Y, 4 = Z,
5= X+Z, 6 = Y+Z, 7 = X+Y+Z. For orientation X = azimuth, Y = pitch and Z = roll.
Example (python)
import android, time
droid = android.Android()
droid.startSensingTimed(1, 250)
time.sleep(1)
s1 = droid.readSensors().result
s2 = droid.sensorsGetAccuracy().result
s3 = droid.sensorsGetLight().result
s4 = droid.sensorsReadAccelerometer().result
s5 = droid.sensorsReadMagnetometer().result
s6 = droid.sensorsReadOrientation().result
droid.stopSensing()
Returns:
s1 = {u'accuracy': 3, u'pitch': -0.47323511242866517, u'xmag': 1.75, u'azimuth':
-0.26701245009899138, u'zforce': 8.4718560000000007, u'yforce': 4.2495484000000001, u'time':
1297160391.2820001, u'ymag': -8.9375, u'zmag': -41.0625, u'roll': -0.031366908922791481,
u'xforce': 0.23154590999999999}
s2 = 3 (Highest accuracy)
s3 = None ---(not available on many phones)
s4 = [0.23154590999999999, 4.2495484000000001, 8.4718560000000007] ----(x, y, z accelerations)
s5 = [1.75, -8.9375, -41.0625] -----(x, y, z magnetic readings)
s6 = [-0.26701245009899138, -0.47323511242866517, -0.031366908922791481] ---(azimuth, pitch, roll
in radians)
- Author:
- Damon Kohler (damonkohler@gmail.com), Felix Arends (felix.arends@gmail.com), Alexey Reznichenko (alexey.reznichenko@gmail.com), Robbie Mathews (rjmatthews62@gmail.com), John Karwatzki (jokar49@gmail.com)
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SensorManagerFacade
public SensorManagerFacade(FacadeManager manager)
startSensingTimed
@Rpc(description="Starts recording sensor data to be available for polling.")
@RpcStartEvent(value="sensors")
public void startSensingTimed(@RpcParameter(name="sensorNumber",description="1 = All, 2 = Accelerometer, 3 = Magnetometer and 4 = Light")
java.lang.Integer sensorNumber,
@RpcParameter(name="delayTime",description="Minimum time between readings in milliseconds")
java.lang.Integer delayTime)
startSensingThreshold
@Rpc(description="Records to the Event Queue sensor data exceeding a chosen threshold.")
@RpcStartEvent(value="threshold")
public void startSensingThreshold(@RpcParameter(name="sensorNumber",description="1 = Orientation, 2 = Accelerometer, 3 = Magnetometer and 4 = Light")
java.lang.Integer sensorNumber,
@RpcParameter(name="threshold",description="Threshold level for chosen sensor (integer)")
java.lang.Integer threshold,
@RpcParameter(name="axis",description="0 = No axis, 1 = X, 2 = Y, 3 = X+Y, 4 = Z, 5= X+Z, 6 = Y+Z, 7 = X+Y+Z")
java.lang.Integer axis)
readSensors
@Rpc(description="Returns the most recently recorded sensor data.")
public Bundle readSensors()
stopSensing
@Rpc(description="Stops collecting sensor data.")
@RpcStopEvent(value="sensors")
public void stopSensing()
sensorsGetAccuracy
@Rpc(description="Returns the most recently received accuracy value.")
public java.lang.Integer sensorsGetAccuracy()
sensorsGetLight
@Rpc(description="Returns the most recently received light value.")
public java.lang.Float sensorsGetLight()
sensorsReadAccelerometer
@Rpc(description="Returns the most recently received accelerometer values.",
returns="a List of Floats [(acceleration on the) X axis, Y axis, Z axis].")
public java.util.List<java.lang.Float> sensorsReadAccelerometer()
sensorsReadMagnetometer
@Rpc(description="Returns the most recently received magnetic field values.",
returns="a List of Floats [(magnetic field value for) X axis, Y axis, Z axis].")
public java.util.List<java.lang.Float> sensorsReadMagnetometer()
sensorsReadOrientation
@Rpc(description="Returns the most recently received orientation values.",
returns="a List of Doubles [azimuth, pitch, roll].")
public java.util.List<java.lang.Double> sensorsReadOrientation()
startSensing
@Rpc(description="Starts recording sensor data to be available for polling.")
@RpcDeprecated(value="startSensingTimed or startSensingThreshhold",
release="4")
public void startSensing(@RpcParameter(name="sampleSize",description="number of samples for calculating average readings")@RpcDefault(value="5")
java.lang.Integer sampleSize)
shutdown
public void shutdown()
- Description copied from class:
RpcReceiver
- Invoked when the receiver is shut down.
- Specified by:
shutdown in class RpcReceiver