Stop accelerometer thread when double-tap/wake-on-motion disabled at runtime (#11025)

* Stop accelerometer thread when double-tap/wake-on-motion disabled at runtime

double_tap_as_button_press and wake_on_tap_or_motion are applied live: the
OFF->ON edge calls accelerometerThread->start(), but there was no ON->OFF
branch, so turning either flag off left the sensor thread running (polling
I2C, drawing power) until reboot. Worse, because enabled stayed true, a later
OFF->ON edge was a no-op (the enabled==false guard blocked re-start), leaving
the feature un-restartable without a reboot.

Add the symmetric ON->OFF branch in both handlers. When a flag goes true->off
and the other consumer of the shared thread is also off, call
accelerometerThread->disable() (stops runOnce polling and clears enabled so a
later re-enable can start() again). Each branch checks the other flag first so
disabling one feature never stops the sensor while the other still needs it.

* Keep accelerometer thread running when its sensor drives the compass

* Guard accelerometer thread config toggles against a null thread pointer

* AdminModule: factor shared accelerometer start/stop into a helper

The device and display config handlers had mirror-image blocks reconciling the
shared accelerometer thread. Extract reconcileAccelerometerThread(wasOn, nowOn,
otherFeatureOn) so the null guard, edge logic, compass (providesHeading) guard,
and rationale live in one place; each call site is now a single call. Behavior
is unchanged. Also drops the redundant per-field assignment that the
whole-struct `config.device = ...` / `config.display = ...` overwrites anyway.

---------

Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
This commit is contained in:
Ben Meadors
2026-07-18 06:26:20 -05:00
committed by GitHub
co-authored by GitHub Thomas Göttgens
parent 40d0d80f35
commit b20d89974a
6 changed files with 38 additions and 12 deletions
+4
View File
@@ -60,6 +60,10 @@ class AccelerometerThread : public concurrency::OSThread
}
}
// True if the active sensor drives the compass heading in runOnce(). Callers must not
// disable() the thread in this case, or the compass would freeze until the next reboot.
bool providesHeading() const { return isInitialised && sensor && sensor->providesHeading(); }
protected:
int32_t runOnce() override
{