mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-15 16:01:19 +10:00
* 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>
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#pragma once
|
|
#ifndef _BMM_150_SENSOR_H_
|
|
#define _BMM_150_SENSOR_H_
|
|
|
|
#include "MotionSensor.h"
|
|
|
|
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include(<DFRobot_BMM150.h>)
|
|
|
|
#include "Fusion/Fusion.h"
|
|
#include <DFRobot_BMM150.h>
|
|
|
|
// The I2C address of the Accelerometer (if found) from main.cpp
|
|
extern ScanI2C::DeviceAddress accelerometer_found;
|
|
|
|
// Singleton wrapper
|
|
class BMM150Singleton : public DFRobot_BMM150_I2C
|
|
{
|
|
private:
|
|
static BMM150Singleton *pinstance;
|
|
|
|
protected:
|
|
BMM150Singleton(TwoWire *tw, uint8_t addr) : DFRobot_BMM150_I2C(tw, addr) {}
|
|
~BMM150Singleton();
|
|
|
|
public:
|
|
// Create a singleton instance (not thread safe)
|
|
static BMM150Singleton *GetInstance(ScanI2C::FoundDevice device);
|
|
|
|
// Singletons should not be cloneable.
|
|
BMM150Singleton(BMM150Singleton &other) = delete;
|
|
|
|
// Singletons should not be assignable.
|
|
void operator=(const BMM150Singleton &) = delete;
|
|
|
|
// Initialise the motion sensor singleton for normal operation
|
|
bool init(ScanI2C::FoundDevice device);
|
|
};
|
|
|
|
class BMM150Sensor : public MotionSensor
|
|
{
|
|
private:
|
|
BMM150Singleton *sensor = nullptr;
|
|
bool showingScreen = false;
|
|
|
|
public:
|
|
explicit BMM150Sensor(ScanI2C::FoundDevice foundDevice);
|
|
|
|
// Initialise the motion sensor
|
|
virtual bool init() override;
|
|
|
|
// Called each time our sensor gets a chance to run
|
|
virtual int32_t runOnce() override;
|
|
virtual bool providesHeading() const override { return true; }
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif |