Class FtcAndroidSensor

java.lang.Object
trclib.sensor.TrcSensor
ftclib.archive.FtcAndroidSensor
All Implemented Interfaces:
android.hardware.SensorEventListener

public class FtcAndroidSensor extends TrcSensor implements android.hardware.SensorEventListener
This class implements an Android sensor that may have multiple axes.
  • Field Details

    • sensorManager

      private final android.hardware.SensorManager sensorManager
    • sensor

      private final android.hardware.Sensor sensor
    • numAxes

      private final int numAxes
    • sensorData

      private final TrcSensor.SensorData<Double>[] 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

      public FtcAndroidSensor(String instanceName, int sensorType, int numAxes, TrcFilter[] filters)
      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

      public FtcAndroidSensor(String instanceName, int sensorType, int numAxes)
      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

      public static FtcAndroidSensor createInstance(String instanceName, int sensorType, int numAxes)
      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

      public TrcSensor.SensorData<Double> getRawData(int index, Object dataType)
      This method returns the raw sensor data of the specified axis and type.
      Specified by:
      getRawData in class TrcSensor
      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:
      onAccuracyChanged in interface android.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:
      onSensorChanged in interface android.hardware.SensorEventListener
      Parameters:
      event - specifies the sensor data.