Bagikan melalui


SensorDirectChannel.Configure(Sensor, SensorDirectRateLevel) Method

Definition

Configure sensor rate or stop sensor report.

[Android.Runtime.Register("configure", "(Landroid/hardware/Sensor;I)I", "", ApiSince=26)]
public int Configure (Android.Hardware.Sensor? sensor, Android.Hardware.SensorDirectRateLevel rateLevel);
[<Android.Runtime.Register("configure", "(Landroid/hardware/Sensor;I)I", "", ApiSince=26)>]
member this.Configure : Android.Hardware.Sensor * Android.Hardware.SensorDirectRateLevel -> int

Parameters

sensor
Sensor

A android.hardware.Sensor object to denote sensor to be operated.

rateLevel
SensorDirectRateLevel

rate level defined in android.hardware.SensorDirectChannel.

Returns

  • starting report or changing rate: positive sensor report token on success, 0 on failure; * stopping report: 1 on success, 0 on failure.
Attributes

Remarks

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 android.hardware.SensorDirectChannel#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)

There are no head or tail pointers. The sequence and frontier of new sensor events is determined by the atomic counter, which counts from 1 after creation of direct channel and increments 1 for each new event. Atomic counter will wrap back to 1 after it reaches UINT32_MAX, skipping value 0 to avoid confusion with uninitialized memory. The writer in sensor system will wrap around from the start of shared memory region when it reaches the end. If size of memory region is not a multiple of size of element (104 bytes), the residual is not used at the end. Function returns a positive sensor report token on success. This token can be used to differentiate sensor events from multiple sensor of the same type. For example, if there are two accelerometers in the system A and B, it is guaranteed different report tokens will be returned when starting sensor A and B.

To stop a sensor, call this function with rateLevel equal android.hardware.SensorDirectChannel#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.

Java documentation for android.hardware.SensorDirectChannel.configure(android.hardware.Sensor, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to