org.openintents.hardware
Class Sensors

java.lang.Object
  extended by org.openintents.hardware.Sensors
Direct Known Subclasses:
SensorsPlus

public class Sensors
extends java.lang.Object


Field Summary
static SensorSimulatorClient mClient
          Client that communicates with the SensorSimulator application.
static java.lang.String SENSOR_ACCELEROMETER
          A constant describing an accelerometer.
static java.lang.String SENSOR_COMPASS
          A constant describing a compass.
static java.lang.String SENSOR_ORIENTATION
          A constant describing an orientation sensor.
 
Constructor Summary
Sensors()
           
 
Method Summary
static void connectSimulator()
          Connect to the Sensor Simulator.
static void disableSensor(java.lang.String sensor)
          Disables the given sensor for this VM.
static void disconnectSimulator()
          Disconnect from the Sensor Simulator.
static void enableSensor(java.lang.String sensor)
          Enables the given sensor for this VM.
static int getNumSensorValues(java.lang.String sensor)
          Returns the number of sensor values returned by the given sensor.
static float getSensorUpdateRate(java.lang.String sensor)
          Returns the current update rate for the given sensor, in updates per second.
static float[] getSensorUpdateRates(java.lang.String sensor)
          Returns a list of supported update rates for the given sensor, in updates per second.
static java.lang.String[] getSupportedSensors()
          Returns an array of Strings containing the supported sensor types.
static void readSensor(java.lang.String sensor, float[] sensorValues)
          Reads the sensor indicated by sensorType, storing the vector of returned values into the entries of sensorValues.
static void setSensorUpdateRate(java.lang.String sensor, float updatesPerSecond)
          Sets the desired update rate for the given sensor, in updates per second.
static void unsetSensorUpdateRate(java.lang.String sensor)
          Unsets the desired update rate for the given sensor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SENSOR_ACCELEROMETER

public static final java.lang.String SENSOR_ACCELEROMETER
A constant describing an accelerometer. Constant Value: "accelerometer"

See Also:
Constant Field Values

SENSOR_COMPASS

public static final java.lang.String SENSOR_COMPASS
A constant describing a compass. Constant Value: "compass"

See Also:
Constant Field Values

SENSOR_ORIENTATION

public static final java.lang.String SENSOR_ORIENTATION
A constant describing an orientation sensor. Constant Value: "orientation"

See Also:
Constant Field Values

mClient

public static SensorSimulatorClient mClient
Client that communicates with the SensorSimulator application.

Constructor Detail

Sensors

public Sensors()
Method Detail

disableSensor

public static void disableSensor(java.lang.String sensor)
Disables the given sensor for this VM. Following this call, calls to readSensor or getSensorUpdateRate for the given sensor type are disallowed.

Parameters:
sensor - the name of the sensor to be enabled
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported

enableSensor

public static void enableSensor(java.lang.String sensor)
Enables the given sensor for this VM. Following this call, calls to readSensor for the given sensor type are allowed.

Parameters:
sensor - the name of the sensor to be enabled
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported

getNumSensorValues

public static int getNumSensorValues(java.lang.String sensor)
Returns the number of sensor values returned by the given sensor. The returned value is 1 for temperature and pedometer values, and 3 for accelerator or compass values.

Parameters:
sensor - a string indicating the sensor type
Returns:
number of sensor values
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported

getSensorUpdateRate

public static float getSensorUpdateRate(java.lang.String sensor)
Returns the current update rate for the given sensor, in updates per second. If the sensor does not allow external control over its update rate, or does not have a fixed update rate, 0 is returned.

Parameters:
sensor - the name of the sensor to be queried
Returns:
the current update rate for the sensor, or 0
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported
java.lang.IllegalStateException - if the sensor is not enabled

getSensorUpdateRates

public static float[] getSensorUpdateRates(java.lang.String sensor)
Returns a list of supported update rates for the given sensor, in updates per second. If no information is available, null is returned.

Parameters:
sensor - the name of the sensor to be queried
Returns:
an array of floats, or null is nor information is available.
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported

getSupportedSensors

public static java.lang.String[] getSupportedSensors()
Returns an array of Strings containing the supported sensor types.

Returns:
array of Strings containing the supported sensor types

readSensor

public static void readSensor(java.lang.String sensor,
                              float[] sensorValues)
Reads the sensor indicated by sensorType, storing the vector of returned values into the entries of sensorValues. Values whose values are not given in defined units are normalized to the range [-1, 1]. For sensors that return a spatial vector, the axes are oriented as follows: with the device lying flat on a horizontal surface in front of the user, oriented so the screen is readable by the user in the normal fashion, the X axis goes from left to right, the Y axis goes from the user toward the device, and the Z axis goes upwards perpendicular to the surface.

Parameters:
sensor - the name of the sensor to read from
sensorValues - an array of floats to hold the returned value(s)
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported
java.lang.IllegalStateException - if the sensor is not enabled
java.lang.NullPointerException - if sensorValues is null
java.lang.ArrayIndexOutOfBoundsException - if sensorValues has too few elements to hold the sensor values

setSensorUpdateRate

public static void setSensorUpdateRate(java.lang.String sensor,
                                       float updatesPerSecond)
Sets the desired update rate for the given sensor, in updates per second. The supported update rate closest to the given rate is used. If the sensor is not enabled at the time of the call, the change will take effect when it becomes enabled. If the sensor does not allow external control over its update rate, nothing happens.

Parameters:
sensor - the name of the sensor to be queried
updatesPerSecond - the desired update rate for the sensor
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported

unsetSensorUpdateRate

public static void unsetSensorUpdateRate(java.lang.String sensor)
Unsets the desired update rate for the given sensor. The sensor will use its default rate. If the sensor is not enabled at the time of the call, the change will take effect when it becomes enabled.

Parameters:
sensor - the name of the sensor to be updated
Throws:
java.lang.IllegalArgumentException - if the sensor is not supported

connectSimulator

public static void connectSimulator()
Connect to the Sensor Simulator. (All the settings should have been set already.)


disconnectSimulator

public static void disconnectSimulator()
Disconnect from the Sensor Simulator.