Stay organized with collections
Save and categorize content based on your preferences.
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
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.
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 |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# UserSensorDriver\n================\n\n\n`\npublic\n\n\ninterface\nUserSensorDriver\n`\n\n\n`\n\n\n`\n\n|--------------------------------------------------------------|\n| com.google.android.things.userdriver.sensor.UserSensorDriver |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nDriver to interface with a user-connected sensor.\n\nThis class is responsible for the actual I/O operations to talk to the sensor. Usage is to\npass this to a [UserSensor.Builder](/reference/com/google/android/things/userdriver/sensor/UserSensor.Builder) to create a [UserSensor](/reference/com/google/android/things/userdriver/sensor/UserSensor).\n\nSummary\n-------\n\n| ### Public methods ||\n|-----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract `[UserSensorReading](/reference/com/google/android/things/userdriver/sensor/UserSensorReading) | ` `[read](/reference/com/google/android/things/userdriver/sensor/UserSensorDriver#read())`() ` Reads the sensor. |\n| ` default void` | ` `[setEnabled](/reference/com/google/android/things/userdriver/sensor/UserSensorDriver#setEnabled(boolean))`(boolean enabled) ` Enables or disables the sensor. |\n\nPublic methods\n--------------\n\n### read\n\n```\nUserSensorReading read ()\n```\n\nReads the sensor.\n\nThis will be called on a registered sensor when a new reading is needed, and only while\nthe sensor is [enabled](/reference/com/google/android/things/userdriver/sensor/UserSensorDriver#setEnabled(boolean)). The implementation may block for a short time\nwhile making the necessary calls to communicate with the sensor.\n\nIf an exception is thrown, nothing will be reported to the framework and the sensor will\nbe re-read on the next iteration.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------------------------------------------------------------------------------------------|------------------------------|\n| [UserSensorReading](/reference/com/google/android/things/userdriver/sensor/UserSensorReading) | new UserSensorReading \u003cbr /\u003e |\n\n| Throws ||\n|-----------------------------------------------|------------------|\n| [IOException](/reference/java/io/IOException) | if reading fails |\n\n### setEnabled\n\n```\nvoid setEnabled (boolean enabled)\n```\n\nEnables or disables the sensor.\n\nIf the sensor has a low power/sleep mode, this should be overridden to start sleep\non disable and wake up on enable.\n\nIf an exception is thrown while enabling, the sensor will remain in disabled mode and\nwill not be polled for readings. Exceptions thrown while disabling are ignored. In both\ncases, this method may attempt to re-enable in the future.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|-------------------------------------------------------------------|\n| `enabled` | `boolean`: `true` to enable the sensor, `false` to disable \u003cbr /\u003e |\n\n| Throws ||\n|-----------------------------------------------|-------------------------------|\n| [IOException](/reference/java/io/IOException) | if sensor configuration fails |\n\n-\n\n Interfaces\n ----------\n\n - [UserSensorDriver](/reference/com/google/android/things/userdriver/sensor/UserSensorDriver)\n-\n\n Classes\n -------\n\n - [UserSensor](/reference/com/google/android/things/userdriver/sensor/UserSensor)\n - [UserSensor.Builder](/reference/com/google/android/things/userdriver/sensor/UserSensor.Builder)\n - [UserSensorReading](/reference/com/google/android/things/userdriver/sensor/UserSensorReading)"]]