KallistoSensorManager¶
-
public class
KallistoSensorManager
extends KallistoManager¶ KALLISTOSensorManager lets you access the device’s
KallistoSensor Sensors
. Get an instance of this class by instantiatingKALLISTOSensorManager
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_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_STATUS_ACCURACY_HIGH¶
-
public static final int
SENSOR_STATUS_ACCURACY_HIGH
¶ This sensor is reporting data with maximum accuracy
Methods¶
deleteCalibration¶
-
public boolean
deleteCalibration
(CalibrationEventListener listener, KallistoSensor sensor)¶ Deletes the calibration of the passed
sensor
.Blocking function.
- Parameters
listener – A
CalibrationEventListener
to receivecalibration events
.sensor – The
sensor
to delete calibration
- 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.
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 passedlistener
is registered to.- Parameters
listener – The
listener
used inKallistoSensorManager.registerListener(SensorEventListener,KallistoSensor,int)
call.
- Returns
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.
registerListener¶
-
public boolean
registerListener
(SensorEventListener listener, KallistoSensor sensor, int rateUs)¶ Registers a
listener
for the givensensor
.Blocking function.
- Parameters
listener – A
listener
to receive sensor events.sensor – The
sensor
to register to.rateUs – The rate
sensor events
are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. The value must be one ofSENSOR_DELAY_NORMAL
,SENSOR_DELAY_UI
,SENSOR_DELAY_GAME
,SENSOR_DELAY_FASTEST
,SENSOR_DELAY_MAX_SAFE
, or, the desired delay between events in microseconds.
- Returns
true
if the sensor is supported and successfully enabled.
registerListener¶
-
public boolean
registerListener
(SensorEventListener listener, KallistoSensor sensor)¶ Registers a
listener
for the givensensor
.Blocking function.
registerListener¶
-
public boolean
registerListener
(SensorEventListener listener, KallistoSensor sensor, Map<String, Object> parameters)¶ Registers a
listener
for the givensensor
.Should only be used for custom sensors not supported by the API that need special parameters.
Blocking function.
startCalibration¶
-
public boolean
startCalibration
(CalibrationEventListener listener, KallistoSensor sensor)¶ Registers a new
calibration listener
for the passedsensor
. 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
listener – A
CalibrationEventListener
to receivecalibration events
.sensor – The
sensor
to be calibrated.
- Returns
true
if the calibration was started successfully.
stopCalibration¶
-
public boolean
stopCalibration
(KallistoSensor sensor)¶ Unregisters the
calibration listener
of the passedsensor
. 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 passedsensor
.Blocking function if the device is no longer in use.
- Parameters
listener – The
listener
used inKallistoSensorManager.registerListener(SensorEventListener,KallistoSensor,int)
call.sensor – The
sensor
used inKallistoSensorManager.registerListener(SensorEventListener,KallistoSensor,int)
call.
unregisterListener¶
-
public void
unregisterListener
(SensorEventListener listener)¶ Unregisters a
listener
for allsensors
.Blocking function if the device is no longer in use.
- Parameters
listener – The
listener
used inKallistoSensorManager.registerListener(SensorEventListener,KallistoSensor,int)
calls.