diff options
author | 2022-01-10 21:07:51 -0800 | |
---|---|---|
committer | 2022-02-03 23:34:06 -0800 | |
commit | 72c7104cab3a0e5bc886fab3acde0ba77fbabd49 (patch) | |
tree | c0bfd5cc892b7b2ddf87800fdbb9a4007a3e72a0 | |
parent | 9f3153648834dfa2222d3b001d0ecd3c4933127d (diff) |
Add TYPE_HEADING sensor type to sensor NDK.
Bug: 189983308
Test: Presubmits
Change-Id: I53bc59d6a1d03ab5e980920f0420ce0263cbc52c
-rw-r--r-- | include/android/sensor.h | 26 | ||||
-rw-r--r-- | libs/sensor/Sensor.cpp | 4 | ||||
-rw-r--r-- | services/sensorservice/SensorServiceUtils.cpp | 3 |
3 files changed, 33 insertions, 0 deletions
diff --git a/include/android/sensor.h b/include/android/sensor.h index 7e86d3fbb8..cf1ca02cb3 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -301,6 +301,14 @@ enum { * supported and a value of 0 means not supported. */ ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41, + /** + * {@link ASENSOR_TYPE_HEADING} + * reporting-mode: continuous + * + * A heading sensor measures the direction in which the device is pointing + * relative to true north in degrees. + */ + ASENSOR_TYPE_HEADING = 42, }; /** @@ -563,6 +571,23 @@ typedef struct ALimitedAxesImuUncalibratedEvent { }; } ALimitedAxesImuUncalibratedEvent; +typedef struct AHeadingEvent { + /** + * The direction in which the device is pointing relative to true north in + * degrees. The value must be between 0.0 (inclusive) and 360.0 (exclusive), + * with 0 indicating north, 90 east, 180 south, and 270 west. + */ + float heading; + /** + * Accuracy is defined at 68% confidence. In the case where the underlying + * distribution is assumed Gaussian normal, this would be considered one + * standard deviation. For example, if the heading returns 60 degrees, and + * accuracy returns 10 degrees, then there is a 68 percent probability of + * the true heading being between 50 degrees and 70 degrees. + */ + float accuracy; +} AHeadingEvent; + /** * Information that describes a sensor event, refer to * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional @@ -602,6 +627,7 @@ typedef struct ASensorEvent { AHeadTrackerEvent head_tracker; ALimitedAxesImuEvent limited_axes_imu; ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated; + AHeadingEvent heading; }; union { uint64_t data[8]; diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp index 5b4631a251..ec0ced8663 100644 --- a/libs/sensor/Sensor.cpp +++ b/libs/sensor/Sensor.cpp @@ -296,6 +296,10 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED; mFlags |= SENSOR_FLAG_CONTINUOUS_MODE; break; + case SENSOR_TYPE_HEADING: + mStringType = SENSOR_STRING_TYPE_HEADING; + mFlags |= SENSOR_FLAG_CONTINUOUS_MODE; + break; default: // Only pipe the stringType, requiredPermission and flags for custom sensors. if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) { diff --git a/services/sensorservice/SensorServiceUtils.cpp b/services/sensorservice/SensorServiceUtils.cpp index c3043811f1..7dd23316b1 100644 --- a/services/sensorservice/SensorServiceUtils.cpp +++ b/services/sensorservice/SensorServiceUtils.cpp @@ -67,6 +67,9 @@ size_t eventSizeBySensorType(int type) { case SENSOR_TYPE_HEAD_TRACKER: return 7; + case SENSOR_TYPE_HEADING: + return 2; + default: return 3; } |