KallistoSensorManager

public class KallistoSensorManager extends KallistoManager

KALLISTOSensorManager lets you access the device’s KallistoSensor Sensors. Get an instance of this class by instantiating KALLISTOSensorManager with a valid context. This class is implemented as a singleton.

The implementation follows the Sensor Manager implementation so the API should be straightforward to a developer with experience with the Android platform sensors.

Like the Android implementation, always make sure to disable sensors you don’t need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will not disable sensors automatically when the screen turns off.

The snippet presented below is the simplest example to get started with the API. Even though the example shows how to register to receive sensor data, other interactions are needed to ensure correct behaviour. See the documentation for details.

public class KallistoSensorActivity extends Activity, implements SensorEventListener {
  private final KALLISTOSensorManager mSensorManager;
  private final KallistoSensorSensor mAccelerometer;

  public SensorActivity() {
    mSensorManager = KALLISTOSensorManager.getInstance(getApplicationContext());
  }

  protected void onResume() {
    super.onResume();
  }

  protected void onPause() {
    super.onPause();
    mSensorManager.unregisterListener(this);
  }

  protected void onDestroy() {
    super.onDestroy();
    mSensorManager.disconnect();
  }

  public void onAccuracyChanged(Sensor sensor, int accuracy) {
  }

  public void onSensorChanged(SensorEvent event) {
    //Do something with the data
  }

  public void onButtonClick(View v){
      //Asking for a device right after the instantiation can lead to a failed call because the
      //API uses a service so it could not be bond yet. One can wait for a broadcast of SERVICE_CONNECTED.
      //Register the listener with a button click.
      mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
      mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
  }

}

Add the service to your manifest:
  "android:name="pt.fraunhofer.kallisto.service.KallistoService"

See also: SensorEventListener, SensorEvent, KallistoSensor

Fields

SENSOR_DELAY_FASTEST

public static final int SENSOR_DELAY_FASTEST

Rate as fast as possible

SENSOR_DELAY_GAME

public static final int SENSOR_DELAY_GAME

Rate suitable for games

SENSOR_DELAY_MAX_SAFE

public static final int SENSOR_DELAY_MAX_SAFE

Rate suitable to get maximum data from the with the guarantee that all samples are delivered

SENSOR_DELAY_NORMAL

public static final int SENSOR_DELAY_NORMAL

Rate (default) suitable for screen orientation changes

SENSOR_DELAY_UI

public static final int SENSOR_DELAY_UI

Rate suitable for the user interface

SENSOR_STATUS_ACCURACY_HIGH

public static final int SENSOR_STATUS_ACCURACY_HIGH

This sensor is reporting data with maximum accuracy

SENSOR_STATUS_ACCURACY_LOW

public static final int SENSOR_STATUS_ACCURACY_LOW

This sensor is reporting data with low accuracy, calibration with the environment is needed

SENSOR_STATUS_ACCURACY_MEDIUM

public static final int SENSOR_STATUS_ACCURACY_MEDIUM

This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings

Methods

deleteCalibration

public boolean deleteCalibration(CalibrationEventListener listener, KallistoSensor sensor)

Deletes the calibration of the passed sensor.

Blocking function.

Parameters
Returns

true if the calibration was deleted successfully.

disconnect

public void disconnect()

Disconnects from the KallistoSensor Service. Will trigger all cleanup routines in the service.

Always call it when done with the service.

getDefaultSensor

public KallistoSensor getDefaultSensor(int type)

Use this method to get the default sensor for a given type.

Beware that the sensor will be null if not found.

Parameters
  • type – The type of the desired sensor. See sensor class for the available types.

Returns

A sensor of the passed type or null if not found.

getInstance

public static KallistoSensorManager getInstance(Context context)

Get a instance of this manager. Will create it if it is null.

Parameters
  • context – A valid context.

getInstance

public static KallistoSensorManager getInstance(Context context, BleDeviceManagerConfiguration bleConfiguration, LoggerConfiguration loggerConfiguration, ScannerConfiguration scannerConfiguration, ScannerFilter scannerFilter, List<SensorProvider> customSensorProviders)

Get a instance of this manager. Will create it if it is null.

Parameters
  • context – A valid context.

  • bleConfiguration – The BLE configuration. Can be null, the default will be used.

  • loggerConfiguration – The logger configuration. Can be null, the default will be used.

  • scannerConfiguration – The scanner starting configuration. Can be null, the default will be used.

  • scannerFilter – The scanner filter configuration. Can be null, the default will be used.

  • customSensorProviders – A list of custom sensor providers. Can be null for no custom providers.

getRegisteredSensors

public List<KallistoSensor> getRegisteredSensors(SensorEventListener listener)

Returns a list of sensors whose the passed listener is registered to.

Parameters
Returns

A list of sensors the passed listener is registered to.

getSensorList

public List<KallistoSensor> getSensorList(int type)

Use this method to get the list of available sensors of a certain type.

Make multiple calls to get sensors of different types or use KallistoSensorSensor.TYPE_ALL to get all the sensors.

Parameters
  • type – The type of the desired sensors. See sensor class for the available types.

Returns

A list with all the sensors available of the requested type.

registerListener

public boolean registerListener(SensorEventListener listener, KallistoSensor sensor, int rateUs)

Registers a listener for the given sensor.

Blocking function.

Parameters
Returns

true if the sensor is supported and successfully enabled.

registerListener

public boolean registerListener(SensorEventListener listener, KallistoSensor sensor)

Registers a listener for the given sensor.

Blocking function.

Parameters
  • listener – A listener to receive sensor events.

  • sensor – The sensor to register to.

Returns

true if the sensor is supported and successfully enabled.

registerListener

public boolean registerListener(SensorEventListener listener, KallistoSensor sensor, Map<String, Object> parameters)

Registers a listener for the given sensor.

Should only be used for custom sensors not supported by the API that need special parameters.

Blocking function.

Parameters
  • listener – A listener to receive sensor events.

  • sensor – The sensor to register to.

  • parameters – The sensor parameters.

Returns

true if the sensor is supported and successfully enabled.

startCalibration

public boolean startCalibration(CalibrationEventListener listener, KallistoSensor sensor)

Registers a new calibration listener for the passed sensor. This will start the calibration and the listener will receive the necessary events.

Only some sensors support calibration. Use KallistoSensor.supportsCalibration() function to check it.

Some sensors need special procedures for correct calibration. See CalibrationEventListener.

This call will fail if the sensor is being used.

Blocking function.

Parameters
Returns

true if the calibration was started successfully.

stopCalibration

public boolean stopCalibration(KallistoSensor sensor)

Unregisters the calibration listener of the passed sensor. This will stop the calibration.

This isn’t needed in normal operation since the calibration listener is automatically removed, is only needed when when the calibration should be stopped mid-way.

Blocking function.

Parameters
  • sensor – The sensor to stop calibration

Returns

true if the calibration was stopped successfully.

unregisterListener

public void unregisterListener(SensorEventListener listener, KallistoSensor sensor)

Unregisters the listener for the passed sensor.

Blocking function if the device is no longer in use.

Parameters

unregisterListener

public void unregisterListener(SensorEventListener listener)

Unregisters a listener for all sensors.

Blocking function if the device is no longer in use.

Parameters