SensorDirectChannel
class SensorDirectChannel : Channel
| kotlin.Any | |
| ↳ | android.hardware.SensorDirectChannel |
Class representing a sensor direct channel. Use SensorManager.createDirectChannel(android.os.MemoryFile) or SensorManager.createDirectChannel(android.hardware.HardwareBuffer) to obtain an object. The channel object can be then configured (see configure(android.hardware.Sensor,int)) to start delivery of sensor events into shared memory buffer.
Summary
| Constants | |
|---|---|
| static Int |
Sensor operates at nominal rate of 200Hz. |
| static Int |
Sensor operates at nominal rate of 50Hz. |
| static Int |
Sensor stopped (no event output). |
| static Int |
Sensor operates at nominal rate of 800Hz. |
| static Int |
Shared memory type wrapped by HardwareBuffer object. |
| static Int |
Shared memory type ashmem, wrapped in MemoryFile object. |
| Public methods | |
|---|---|
| Unit |
close()Close sensor direct channel. |
| Int |
Configure sensor rate or stop sensor report. |
| Boolean |
isOpen()Determine if a channel is still valid. |
| Protected methods | |
|---|---|
| Unit |
finalize()Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
Constants
RATE_FAST
static val RATE_FAST: Int
Sensor operates at nominal rate of 200Hz. The actual rate is expected to be between 55% to 220% of nominal rate, thus between 110Hz to 440Hz.
Value: 2See Also
RATE_NORMAL
static val RATE_NORMAL: Int
Sensor operates at nominal rate of 50Hz. The actual rate is expected to be between 55% to 220% of nominal rate, thus between 27.5Hz to 110Hz.
Value: 1See Also
RATE_STOP
static val RATE_STOP: Int
Sensor stopped (no event output).
Value: 0See Also
RATE_VERY_FAST
static val RATE_VERY_FAST: Int
Sensor operates at nominal rate of 800Hz. The actual rate is expected to be between 55% to 220% of nominal rate, thus between 440Hz to 1760Hz.
Value: 3See Also
TYPE_HARDWARE_BUFFER
static val TYPE_HARDWARE_BUFFER: Int
Shared memory type wrapped by HardwareBuffer object.
Value: 2TYPE_MEMORY_FILE
static val TYPE_MEMORY_FILE: Int
Shared memory type ashmem, wrapped in MemoryFile object.
Value: 1Public methods
close
fun close(): Unit
Close sensor direct channel. Stop all active sensor in the channel and free sensor system resource related to channel. Shared memory used for creating the direct channel need to be closed or freed separately.
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
If an I/O error occurs |
configure
fun configure(
sensor: Sensor!,
rateLevel: Int
): Int
Configure sensor rate or stop sensor report. To start event report of a sensor, or change rate of existing report, call this function with rateLevel other than RATE_STOP. Sensor events will be added into a queue formed by the shared memory used in creation of direction channel. Each element of the queue has size of 104 bytes and represents a sensor event. Data structure of an element (all fields in little-endian):
offset type name ------------------------------------------------------------------------ 0x0000 int32_t size (always 104) 0x0004 int32_t sensor report token 0x0008 int32_t type (see SensorType) 0x000C uint32_t atomic counter 0x0010 int64_t timestamp (see Event) 0x0018 float[16]/int64_t[8] data (data type depends on sensor type) 0x0058 int32_t[4] reserved (set to zero)
RATE_STOP. If the sensor parameter is left to be null, this will stop all active sensor report associated with the direct channel specified. Function return 1 on success or 0 on failure.
| Parameters | |
|---|---|
sensor |
Sensor!: A android.hardware.Sensor object to denote sensor to be operated. |
rateLevel |
Int: rate level defined in android.hardware.SensorDirectChannel. Value is one of the following: |
| Return | |
|---|---|
Int |
* starting report or changing rate: positive sensor report token on success, 0 on failure; * stopping report: 1 on success, 0 on failure. |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
when channel is null. |
isOpen
fun isOpen(): Boolean
Determine if a channel is still valid. A channel is invalidated after #close() is called.
| Return | |
|---|---|
Boolean |
true if channel is valid. |
Protected methods
finalize
protected fun finalize(): Unit
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.
The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.
The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.
| Exceptions | |
|---|---|
java.lang.Throwable |
the Exception raised by this method |