Android Sensor

class enamlnative.android.android_sensors.Sensor(*args, **kwargs)[source]

Bases: enamlnative.android.bridge.JavaBridgeObject

A wrapper for an Android sensor. This should be retrieved using the Sensor.get(sensor_type) method.

Examples

# In a function with an @inlineCallbacks or @coroutine decorator def on_data(data):

# Handle data here… # data is a dict with keys # {‘acc’: <accuracy>, ‘data’: [v1, v2, …], ‘sensor’: id, ‘time’: t}

def on_ready(sensor):
if sensor is not None:

sensor.start(callback=on_data) # … sensor.stop()

manager

Reference to the sensor manager

type

Sensor type

started

Sensor state

async classmethod get(sensor_type: int) Optional[enamlnative.android.android_sensors.Sensor][source]

Shortcut that acquires the default Sensor of a given type.

Parameters

sensor_type (int) – Type of sensor to get.

Returns

result – A future that resolves to an instance of the Sensor or None if the sensor is not present or access is not allowed.

Return type

Future

start(callback, rate=3)[source]

Start listening to sensor events. Sensor event data depends on the type of sensor that was given to

Parameters
  • callback (Callable) – A callback that takes one argument that will be passed the sensor data. Sensor data is a dict with data based on the type of sensor.

  • rate (Integer) – How fast to update. One of the Sensor.SENSOR_DELAY values

Returns

result – A future that resolves to whether the register call completed.

Return type

Future

stop()[source]

Stop listening to sensor events. This should be done in on resume.

__del__()[source]

Destroy this object and send a command to destroy the actual object reference the bridge implementation holds (allowing it to be released).