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

Commit 9bae7429 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Better support for head and screen sensors being the same one

This is not a super interesting use-case, but for completeness we
should make sure it is handled correctly.

From the Sensor Framework standpoint, a sensor can only be enabled
once at a given time. We mirror this behavior in SensorPoseProvider
and document it well.

At the SpatializerPoseController layer we make sure that we don't
enable a sensor more than once and that if both sensors are the same
that we treat an event as applying to both.

Test: manual verification of this mode.
Bug: 188502620
Change-Id: I3aa1f225d7100c5d934af9255484caec75375380
parent 95b00c8c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -77,11 +77,13 @@ class SensorPoseProvider {

    /**
     * Start receiving pose updates from a given sensor.
     * Attempting to start a sensor that has already been started results in undefined behavior.
     * @param sensor The sensor to subscribe to.
     * @param samplingPeriod Sampling interval, in microseconds. Actual rate might be slightly
     * different.
     * @return A handle, which can be later used for stopSensor(). INVALID_HANDLE would be returned
     * in case of error.
     * @return The sensor handle, which can be later used for stopSensor(). INVALID_HANDLE would be
     * returned in case of error. This is guaranteed to be the same handle as the one returned by
     * ASensor_getHandle(sensor).
     */
    virtual int32_t startSensor(const ASensor* sensor,
                                std::chrono::microseconds samplingPeriod) = 0;
+32 −11
Original line number Diff line number Diff line
@@ -117,25 +117,45 @@ SpatializerPoseController::~SpatializerPoseController() {

void SpatializerPoseController::setHeadSensor(const ASensor* sensor) {
    std::lock_guard lock(mMutex);
    // Stop current sensor, if valid.
    if (mHeadSensor != SensorPoseProvider::INVALID_HANDLE) {
    // Stop current sensor, if valid and different from the other sensor.
    if (mHeadSensor != SensorPoseProvider::INVALID_HANDLE && mHeadSensor != mScreenSensor) {
        mPoseProvider->stopSensor(mHeadSensor);
    }
    // Start new sensor, if valid.
    mHeadSensor = sensor != nullptr ? mPoseProvider->startSensor(sensor, mSensorPeriod)
                                    : SensorPoseProvider::INVALID_HANDLE;

    if (sensor != nullptr) {
        if (ASensor_getHandle(sensor) != mScreenSensor) {
            // Start new sensor.
            mHeadSensor = mPoseProvider->startSensor(sensor, mSensorPeriod);
        } else {
            // Sensor is already enabled.
            mHeadSensor = mScreenSensor;
        }
    } else {
        mHeadSensor = SensorPoseProvider::INVALID_HANDLE;
    }

    mProcessor->recenter(true, false);
}

void SpatializerPoseController::setScreenSensor(const ASensor* sensor) {
    std::lock_guard lock(mMutex);
    // Stop current sensor, if valid.
    if (mScreenSensor != SensorPoseProvider::INVALID_HANDLE) {
    // Stop current sensor, if valid and different from the other sensor.
    if (mScreenSensor != SensorPoseProvider::INVALID_HANDLE && mScreenSensor != mHeadSensor) {
        mPoseProvider->stopSensor(mScreenSensor);
    }
    // Start new sensor, if valid.
    mScreenSensor = sensor != nullptr ? mPoseProvider->startSensor(sensor, mSensorPeriod)
                                      : SensorPoseProvider::INVALID_HANDLE;

    if (sensor != nullptr) {
        if (ASensor_getHandle(sensor) != mHeadSensor) {
            // Start new sensor.
            mScreenSensor = mPoseProvider->startSensor(sensor, mSensorPeriod);
        } else {
            // Sensor is already enabled.
            mScreenSensor = mHeadSensor;
        }
    } else {
        mScreenSensor = SensorPoseProvider::INVALID_HANDLE;
    }

    mProcessor->recenter(false, true);
}

@@ -188,7 +208,8 @@ void SpatializerPoseController::onPose(int64_t timestamp, int32_t sensor, const
    std::lock_guard lock(mMutex);
    if (sensor == mHeadSensor) {
        mProcessor->setWorldToHeadPose(timestamp, pose, twist.value_or(Twist3f()));
    } else if (sensor == mScreenSensor) {
    }
    if (sensor == mScreenSensor) {
        mProcessor->setWorldToScreenPose(timestamp, pose);
    }
}