Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

UserSensorDriver

public interface UserSensorDriver

com.google.android.things.userdriver.sensor.UserSensorDriver


Driver to interface with a user-connected sensor. This class is responsible for the actual I/O operations to talk to the sensor. Usage is to pass this to a UserSensor.Builder to create a UserSensor.

Summary

Public methods

abstract UserSensorReading read()

Reads the sensor.

default void setEnabled(boolean enabled)

Enables or disables the sensor.

Public methods

read

UserSensorReading read ()

Reads the sensor.

This will be called on a registered sensor when a new reading is needed, and only while the sensor is enabled. The implementation may block for a short time while making the necessary calls to communicate with the sensor.

If an exception is thrown, nothing will be reported to the framework and the sensor will be re-read on the next iteration.

Returns
UserSensorReading new UserSensorReading

Throws
IOException if reading fails

setEnabled

void setEnabled (boolean enabled)

Enables or disables the sensor.

If the sensor has a low power/sleep mode, this should be overridden to start sleep on disable and wake up on enable.

If an exception is thrown while enabling, the sensor will remain in disabled mode and will not be polled for readings. Exceptions thrown while disabling are ignored. In both cases, this method may attempt to re-enable in the future.

Parameters
enabled boolean: true to enable the sensor, false to disable

Throws
IOException if sensor configuration fails