UserSensor
public
static
class
UserSensor.Builder
extends Object
java.lang.Object | |
↳ | com.google.android.things.userdriver.UserSensor.Builder |
Builder to allow for flexible UserSensor
construction.
Most parameters are given default values and can be skipped if not needed. The only required
calls are setDriver(UserSensorDriver)
and either setType(int)
or setCustomType(int, String, int)
.
See the
Sensor HAL documentation for details on how each parameter is used.
Usage will look something like this:
UserSensor sensor = UserSensor.builder()
.setName("ABC123 Accelerometer")
.setType(Sensor.TYPE_ACCELEROMETER)
.setDriver(myDriverObject)
.build();
Summary
Public methods | |
---|---|
UserSensor
|
build()
Returns a new UserSensor with the configured parameters. |
UserSensor.Builder
|
setCustomType(int type, String stringType, int reportingMode)
Sets a custom driver type and reporting mode. |
UserSensor.Builder
|
setDriver(UserSensorDriver driver)
Sets the UserSensorDriver that controls the sensor. |
UserSensor.Builder
|
setMaxDelay(int maxDelay)
Sets the maximum allowed delay between sensor reads in microseconds. |
UserSensor.Builder
|
setMaxRange(float maxRange)
Sets the max sensor range. |
UserSensor.Builder
|
setMinDelay(int minDelay)
Sets the minimum allowed delay between sensor reads in microseconds. |
UserSensor.Builder
|
setName(String name)
Sets the sensor name. |
UserSensor.Builder
|
setPower(float power)
Sets the power cost of enabling the sensor in milliAmps. |
UserSensor.Builder
|
setRequiredPermission(String requiredPermission)
Sets a permission that will be required to read this sensor. |
UserSensor.Builder
|
setResolution(float resolution)
Sets the sensor resolution. |
UserSensor.Builder
|
setType(int type)
Sets the driver type. |
UserSensor.Builder
|
setUuid(UUID uuid)
Sets a UUID to identify this sensor. |
UserSensor.Builder
|
setVendor(String vendor)
Sets the driver vendor name. |
UserSensor.Builder
|
setVersion(int version)
Sets the driver version. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
Public methods
build
</div>
UserSensor build ()
Returns a new UserSensor with the configured parameters.
Returns | |
---|---|
UserSensor |
A new UserSensor object.
|
</div>
setCustomType
</div>
UserSensor.Builder setCustomType (int type, String stringType, int reportingMode)
Sets a custom driver type and reporting mode.
This can be used to install a custom driver type that is not currently defined as an Android sensor, e.g. a radiation detector. It's up to the sensor to define what the returned float array represents and the user to interpret these values correctly.</p>
Parameters | |
---|---|
type |
int :
An int value to represent this sensor type. Must be greater than or equal to
Sensor.TYPE_DEVICE_PRIVATE_BASE. Used by SensorManager.getDynamicSensorList()
to return only the sensors that match the given type. |
stringType |
String :
A string identifying the sensor type in reverse-domain format, e.g.
com.companyname.radiationdetector. |
reportingMode |
int :
One of the Sensor.REPORTING_MODE_* constants. |
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
Throws | |
---|---|
IllegalArgumentException |
if type is invalid or stringType is null. |
</div>
setDriver
</div>
UserSensor.Builder setDriver (UserSensorDriver driver)
Sets the UserSensorDriver that controls the sensor.
Parameters | |
---|---|
driver |
UserSensorDriver
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setMaxDelay
</div>
UserSensor.Builder setMaxDelay (int maxDelay)
Sets the maximum allowed delay between sensor reads in microseconds.
Parameters | |
---|---|
maxDelay |
int
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setMaxRange
</div>
UserSensor.Builder setMaxRange (float maxRange)
Sets the max sensor range.
The sensor should be able to report values without saturating within [-maxRange, maxRange].</p>
Parameters | |
---|---|
maxRange |
float :
The maximum sensor range in the sensor's reporting units. |
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
See also:
setResolution(float)
</div>
setMinDelay
</div>
UserSensor.Builder setMinDelay (int minDelay)
Sets the minimum allowed delay between sensor reads in microseconds.
Parameters | |
---|---|
minDelay |
int
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setName
</div>
UserSensor.Builder setName (String name)
Sets the sensor name.
Usually contains the part name and sensor type, e.g. "ABC001 Accelerometer".</p>
Parameters | |
---|---|
name |
String
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setPower
</div>
UserSensor.Builder setPower (float power)
Sets the power cost of enabling the sensor in milliAmps.
Parameters | |
---|---|
power |
float
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setRequiredPermission
</div>
UserSensor.Builder setRequiredPermission (String requiredPermission)
Sets a permission that will be required to read this sensor.
The framework may force a set permission for certain sensors, e.g. heart rate monitors, and disregard any manually set permissions.</p>
Parameters | |
---|---|
requiredPermission |
String :
A string permission name, or empty for no permission needed. |
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setResolution
</div>
UserSensor.Builder setResolution (float resolution)
Sets the sensor resolution.
Sensor resolution is the smallest discernable difference the sensor can measure. Usually calculated based on max range and the number of bits available.</p>
Parameters | |
---|---|
resolution |
float :
The sensor resolution in the sensor's reporting units. |
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
See also:
setMaxRange(float)
</div>
setType
</div>
UserSensor.Builder setType (int type)
Sets the driver type.
Use this to set the driver to be a known Android sensor type. For custom sensor types,
use setCustomType(int, String, int)
instead.</p>
Parameters | |
---|---|
type |
int :
Android sensor type. |
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
Throws | |
---|---|
IllegalArgumentException |
if the given type is deprecated or unknown. |
</div>
setUuid
</div>
UserSensor.Builder setUuid (UUID uuid)
Sets a UUID to identify this sensor.
This is only useful when multiple sensors of the exact same type are connected, to be able to distinguish between them. Normally this can be left at the default 0.
Apps will not see this value directly, but can use Sensor.getId() to distinguish between sensors that have non-zero UUIDs.</p>
Parameters | |
---|---|
uuid |
UUID :
A UUID to assign this sensor, or null for 0. |
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setVendor
</div>
UserSensor.Builder setVendor (String vendor)
Sets the driver vendor name.
Parameters | |
---|---|
vendor |
String
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>
setVersion
</div>
UserSensor.Builder setVersion (int version)
Sets the driver version.
Parameters | |
---|---|
version |
int
|
Returns | |
---|---|
UserSensor.Builder |
The same builder instance. |
</div>