Package ftclib.archive
Class FtcAndroidSensor
java.lang.Object
trclib.sensor.TrcSensor
ftclib.archive.FtcAndroidSensor
- All Implemented Interfaces:
android.hardware.SensorEventListener
This class implements an Android sensor that may have multiple axes.
-
Nested Class Summary
Nested classes/interfaces inherited from class trclib.sensor.TrcSensor
TrcSensor.DataSource<D>, TrcSensor.SensorData<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final intprivate final android.hardware.Sensorprivate final TrcSensor.SensorData<Double>[]private final android.hardware.SensorManagerFields inherited from class trclib.sensor.TrcSensor
instanceName, tracer -
Constructor Summary
ConstructorsConstructorDescriptionFtcAndroidSensor(android.content.Context context, String instanceName, int sensorType, int numAxes, TrcFilter[] filters) Constructor: Creates an instance of the object.FtcAndroidSensor(String instanceName, int sensorType, int numAxes) Constructor: Creates an instance of the object.FtcAndroidSensor(String instanceName, int sensorType, int numAxes, TrcFilter[] filters) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionstatic FtcAndroidSensorcreateInstance(android.content.Context context, String instanceName, int sensorType, int numAxes, TrcFilter[] filters) This method creates an instance of the FtcAndroidSensor with the given sensor type.static FtcAndroidSensorcreateInstance(String instanceName, int sensorType, int numAxes) This method creates an instance of the FtcAndroidSensor with the given sensor type.static FtcAndroidSensorcreateInstance(String instanceName, int sensorType, int numAxes, TrcFilter[] filters) This method creates an instance of the FtcAndroidSensor with the given sensor type.getRawData(int index, Object dataType) This method returns the raw sensor data of the specified axis and type.booleanThis method returns true if the Android sensor is enabled.final voidonAccuracyChanged(android.hardware.Sensor sensor, int accuracy) This method is called when the sensor data accuracy has changed.final voidonSensorChanged(android.hardware.SensorEvent event) This method is called when new data is available from the sensor.voidsetEnabled(boolean enabled) This method enables/disables the sensor data listener.voidsetEnabled(boolean enabled, int samplingInterval) This method enables/disables the sensor data listener.Methods inherited from class trclib.sensor.TrcSensor
calibrate, calibrate, getNumAxes, getProcessedData, isCalibrating, setInverted, setScale, setScaleAndOffset, toString
-
Field Details
-
sensorManager
private final android.hardware.SensorManager sensorManager -
sensor
private final android.hardware.Sensor sensor -
numAxes
private final int numAxes -
sensorData
-
enabled
private boolean enabled
-
-
Constructor Details
-
FtcAndroidSensor
public FtcAndroidSensor(android.content.Context context, String instanceName, int sensorType, int numAxes, TrcFilter[] filters) Constructor: Creates an instance of the object.- Parameters:
context- specifies the activity context.instanceName- specifies the instance name.sensorType- specifies the sensor type.numAxes- specifies the number of axes of the sensor.filters- specifies an array of filter object used for filtering data of each axis. If none needed, it can be set to null.
-
FtcAndroidSensor
Constructor: Creates an instance of the object.- Parameters:
instanceName- specifies the instance name.sensorType- specifies the sensor type.numAxes- specifies the number of axes of the sensor.filters- specifies an array of filter object used for filtering data of each axis. If none needed, it can be set to null.
-
FtcAndroidSensor
Constructor: Creates an instance of the object.- Parameters:
instanceName- specifies the instance name.sensorType- specifies the sensor type.numAxes- specifies the number of axes of the sensor.
-
-
Method Details
-
createInstance
public static FtcAndroidSensor createInstance(android.content.Context context, String instanceName, int sensorType, int numAxes, TrcFilter[] filters) This method creates an instance of the FtcAndroidSensor with the given sensor type. If none found, it will return null.- Parameters:
context- specifies the activity context.instanceName- specifies the instance name.sensorType- specifies the sensor type.numAxes- specifies the number of axes of the sensor.filters- specifies an array of filter object used for filtering data of each axis. If none needed, it can be set to null.
-
createInstance
public static FtcAndroidSensor createInstance(String instanceName, int sensorType, int numAxes, TrcFilter[] filters) This method creates an instance of the FtcAndroidSensor with the given sensor type. If none found, it will return null.- Parameters:
instanceName- specifies the instance name.sensorType- specifies the sensor type.numAxes- specifies the number of axes of the sensor.filters- specifies an array of filter object used for filtering data of each axis. If none needed, it can be set to null.
-
createInstance
This method creates an instance of the FtcAndroidSensor with the given sensor type. If none found, it will return null.- Parameters:
instanceName- specifies the instance name.sensorType- specifies the sensor type.numAxes- specifies the number of axes of the sensor.
-
setEnabled
public void setEnabled(boolean enabled, int samplingInterval) This method enables/disables the sensor data listener.- Parameters:
enabled- specifies true to enable data listener, false otherwise.samplingInterval- specifies the maximum sampling interval in microseconds.
-
setEnabled
public void setEnabled(boolean enabled) This method enables/disables the sensor data listener.- Parameters:
enabled- specifies true to enable data listener, false otherwise.
-
isEnabled
public boolean isEnabled()This method returns true if the Android sensor is enabled.- Returns:
- true if sensor is enabled, false otherwise.
-
getRawData
This method returns the raw sensor data of the specified axis and type.- Specified by:
getRawDatain classTrcSensor- Parameters:
index- specifies the axis index.dataType- specifies the data type (not used, can be null).- Returns:
- raw sensor data of the specified axis.
-
onAccuracyChanged
public final void onAccuracyChanged(android.hardware.Sensor sensor, int accuracy) This method is called when the sensor data accuracy has changed. We don't do anything here.- Specified by:
onAccuracyChangedin interfaceandroid.hardware.SensorEventListener- Parameters:
sensor- specifies the sensor object that generates this event.accuracy- specifies the new accuracy.
-
onSensorChanged
public final void onSensorChanged(android.hardware.SensorEvent event) This method is called when new data is available from the sensor. It reads the data for each axis and stores them.- Specified by:
onSensorChangedin interfaceandroid.hardware.SensorEventListener- Parameters:
event- specifies the sensor data.
-