Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0420b79 authored by Eva Chen's avatar Eva Chen
Browse files

Add limited axes imu sensor types to sensor NDK.

Included sensors:
- SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES
- SENSOR_TYPE_GYROSCOPE_LIMITED_AXES
- SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED
- SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED

These changes will enable support for automotive style IMUs that have
more limited axes for accelerometers (x-axis and y-axis) and gyroscopes
(z-axis).

Bug: 187342209
Test: Presubmits
Change-Id: I7f8ecd4f3323c71c723a6415e573413cb464a0f1
parent c945c1b8
Loading
Loading
Loading
Loading
+86 −0
Original line number Diff line number Diff line
@@ -263,6 +263,44 @@ enum {
     * Measures the orientation and rotational velocity of a user's head.
     */
    ASENSOR_TYPE_HEAD_TRACKER = 37,
    /**
     * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES}
     * reporting-mode: continuous
     *
     * The first three values are in SI units (m/s^2) and measure the acceleration of the device
     * minus the force of gravity. The last three values indicate which acceleration axes are
     * supported. A value of 1.0 means supported and a value of 0 means not supported.
     */
    ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
    /**
     * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES}
     * reporting-mode: continuous
     *
     * The first three values are in radians/second and measure the rate of rotation around the X,
     * Y and Z axis. The last three values indicate which rotation axes are supported. A value of
     * 1.0 means supported and a value of 0 means not supported.
     */
    ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
    /**
     * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED}
     * reporting-mode: continuous
     *
     * The first three values are in SI units (m/s^2) and measure the acceleration of the device
     * minus the force of gravity. The middle three values represent the estimated bias for each
     * axis. The last three values indicate which acceleration axes are supported. A value of 1.0
     * means supported and a value of 0 means not supported.
     */
    ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
    /**
     * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED}
     * reporting-mode: continuous
     *
     * The first three values are in radians/second and measure the rate of rotation around the X,
     * Y and Z axis. The middle three values represent the estimated drift around each axis in
     * rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means
     * supported and a value of 0 means not supported.
     */
    ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
};

/**
@@ -479,6 +517,52 @@ typedef struct AHeadTrackerEvent {
    int32_t discontinuity_count;
} AHeadTrackerEvent;

typedef struct ALimitedAxesImuEvent {
    union {
        float calib[3];
        struct {
            float x;
            float y;
            float z;
        };
    };
    union {
        float supported[3];
        struct {
            float x_supported;
            float y_supported;
            float z_supported;
        };
    };
} ALimitedAxesImuEvent;

typedef struct ALimitedAxesImuUncalibratedEvent {
    union {
        float uncalib[3];
        struct {
            float x_uncalib;
            float y_uncalib;
            float z_uncalib;
        };
    };
    union {
        float bias[3];
        struct {
            float x_bias;
            float y_bias;
            float z_bias;
        };
    };
    union {
        float supported[3];
        struct {
            float x_supported;
            float y_supported;
            float z_supported;
        };
    };
} ALimitedAxesImuUncalibratedEvent;

/**
 * Information that describes a sensor event, refer to
 * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional
@@ -516,6 +600,8 @@ typedef struct ASensorEvent {
            ADynamicSensorEvent dynamic_sensor_meta;
            AAdditionalInfoEvent additional_info;
            AHeadTrackerEvent head_tracker;
            ALimitedAxesImuEvent limited_axes_imu;
            ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
        };
        union {
            uint64_t        data[8];
+16 −0
Original line number Diff line number Diff line
@@ -280,6 +280,22 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
        mStringType = SENSOR_STRING_TYPE_HEAD_TRACKER;
        mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
        break;
    case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES:
        mStringType = SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES;
        mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
        break;
    case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES:
        mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES;
        mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
        break;
    case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED:
        mStringType = SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED;
        mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
        break;
    case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED:
        mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED;
        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) {
+6 −0
Original line number Diff line number Diff line
@@ -30,12 +30,18 @@ size_t eventSizeBySensorType(int type) {
        case SENSOR_TYPE_POSE_6DOF:
            return 16;

        case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED:
        case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED:
            return 9;

        case SENSOR_TYPE_ROTATION_VECTOR:
        case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            return 5;

        case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
        case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
        case SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES:
        case SENSOR_TYPE_GYROSCOPE_LIMITED_AXES:
            return 6;

        case SENSOR_TYPE_GAME_ROTATION_VECTOR: