Files
firmware/src/motion/AccelerometerThread.h
T
c308d0aca4 feat: Support Elecrow ThinkNode M9 (#10908)
* thinknode-m9 variant

* move lora to SPI1 device

* enable SDcard

* use HSPI

* BaseUI tft -> HSPI

* buzzer, webdav lib

* fix build issues

* M9 default to MUI, no BT, short ringtone

* add keyboard long-press config

* update variant

* add ThingNode-M9 GPS string

* GPS 115200 baud

* Basic BaseUI support

* Fixup power detection

* Compass and KB fixes for M9

* add timed Lock::lock()

* add SD card

* point device-ui to thinknode m9 draft branch

* trunk fmt

* fix FusionCompass

* Fix t-deck-tft linker arg list overflow in CI

* SDcard/lora fix: SPI1 must not be declared twice in arduino 3.x -> reuse SPI1 defined in FSCommon.cpp

* update battery parameters

* reinit SD card when updating; fix PSRAM size

* update lib versions

* fix wakeup on key press (KB_INT)

* fix default nag_timeout for TFT/MUI devices with buzzer

* increase PSRAM and SD freq

* trunk fmt

* update lovyanGFX 1.2.26

* update device-ui commit reference

* fix screen definition

* remove DONE; maybe a keyword or other used identifier

* fixed CI error nag_timeout

* fix prepareSleep initialization

* trunk fmt

* reduce SD SPI frequency

* update device-ui

* fix SDcard issue

* stage

* fix device-ui commit reference

* fix device-ui commit

* update device-ui commit (fixed keyboard lag)

* fix QMI8658

* trunk fmt

* update .ini meta information, align SD freq

* fix device-ui reference to target (ready to merge)

* device-ui for all other targets

* make the rabbit happy

* trunk fmt

* fixed lock screen

* fix compile error

* SPI lock timeout

* apply device-ui fix

* revert bad RadioLib commit hash in platformio.ini

Co-authored-by: mverch67 <71137295+mverch67@users.noreply.github.com>

* fix wrong commit hash change

* fix fix commit fix

* I love changing random numbers in random files

---------

Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-08-17 17:28:33 +00:00

203 lines
5.4 KiB
C++
Executable File

#pragma once
#ifndef _ACCELEROMETER_H_
#define _ACCELEROMETER_H_
#include "configuration.h"
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && !MESHTASTIC_EXCLUDE_ACCELEROMETER
#include "../concurrency/OSThread.h"
#ifdef HAS_BMA423
#include "BMA423Sensor.h"
#endif
#ifdef HAS_BMI270
#include "BMI270Sensor.h"
#endif
#include "BMM150Sensor.h"
#include "BMX160Sensor.h"
#include "ICM20948Sensor.h"
#include "ICM42607PSensor.h"
#include "LIS3DHSensor.h"
#include "LSM6DS3Sensor.h"
#include "MPU6050Sensor.h"
#include "MotionSensor.h"
#include "QMI8658Sensor.h"
#include <memory>
#ifdef HAS_QMA6100P
#include "QMA6100PSensor.h"
#endif
#ifdef HAS_STK8XXX
#include "STK8XXXSensor.h"
#endif
extern ScanI2C::DeviceAddress accelerometer_found;
class AccelerometerThread : public concurrency::OSThread
{
private:
std::unique_ptr<MotionSensor> sensor;
bool isInitialised = false;
public:
explicit AccelerometerThread(ScanI2C::FoundDevice foundDevice) : OSThread("Accelerometer")
{
device = foundDevice;
init();
}
explicit AccelerometerThread(ScanI2C::DeviceType type) : AccelerometerThread(ScanI2C::FoundDevice{type, accelerometer_found})
{
}
void start()
{
init();
setIntervalFromNow(0);
};
void calibrate(uint16_t forSeconds)
{
if (sensor) {
sensor->calibrate(forSeconds);
}
}
// 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
{
// Assume we should not keep the board awake
canSleep = true;
if (isInitialised)
return sensor->runOnce();
return MOTION_SENSOR_CHECK_INTERVAL_MS;
}
private:
ScanI2C::FoundDevice device;
void init()
{
if (isInitialised)
return;
if (device.address.port == ScanI2C::I2CPort::NO_I2C || device.address.address == 0 || device.type == ScanI2C::NONE) {
LOG_DEBUG("AccelerometerThread Disable due to no sensors found");
disable();
return;
}
switch (device.type) {
#ifdef HAS_BMA423
case ScanI2C::DeviceType::BMA423:
sensor.reset(new BMA423Sensor(device));
break;
#endif
#if __has_include(<Adafruit_MPU6050.h>)
case ScanI2C::DeviceType::MPU6050:
sensor.reset(new MPU6050Sensor(device));
break;
#endif
case ScanI2C::DeviceType::BMX160:
sensor.reset(new BMX160Sensor(device));
break;
#if __has_include(<Adafruit_LIS3DH.h>)
case ScanI2C::DeviceType::LIS3DH:
case ScanI2C::DeviceType::SC7A20:
sensor.reset(new LIS3DHSensor(device));
break;
#endif
#if __has_include(<Adafruit_LSM6DS3TRC.h>)
case ScanI2C::DeviceType::LSM6DS3:
sensor.reset(new LSM6DS3Sensor(device));
break;
#endif
#ifdef HAS_STK8XXX
case ScanI2C::DeviceType::STK8BAXX:
sensor.reset(new STK8XXXSensor(device));
break;
#endif
#if __has_include(<ICM_20948.h>)
case ScanI2C::DeviceType::ICM20948:
sensor.reset(new ICM20948Sensor(device));
break;
#endif
#if __has_include(<ICM42670P.h>)
case ScanI2C::DeviceType::ICM42607P:
sensor.reset(new ICM42607PSensor(device));
break;
#endif
#if __has_include(<DFRobot_BMM150.h>)
case ScanI2C::DeviceType::BMM150:
sensor.reset(new BMM150Sensor(device));
break;
#endif
#ifdef HAS_BMI270
case ScanI2C::DeviceType::BMI270:
sensor.reset(new BMI270Sensor(device));
break;
#endif
#ifdef HAS_QMA6100P
case ScanI2C::DeviceType::QMA6100P:
sensor.reset(new QMA6100PSensor(device));
break;
#endif
#if __has_include(<SensorQMI8658.hpp>)
case ScanI2C::DeviceType::QMI8658:
sensor.reset(new QMI8658Sensor(device));
break;
#endif
default:
disable();
return;
}
isInitialised = sensor->init();
if (!isInitialised) {
clean();
}
LOG_DEBUG("AccelerometerThread::init %s", isInitialised ? "ok" : "failed");
}
// Copy constructor (not implemented / included to avoid cppcheck warnings)
AccelerometerThread(const AccelerometerThread &other) : OSThread::OSThread("Accelerometer") { this->copy(other); }
// Destructor (included to avoid cppcheck warnings)
virtual ~AccelerometerThread() { clean(); }
// Copy assignment (not implemented / included to avoid cppcheck warnings)
AccelerometerThread &operator=(const AccelerometerThread &other)
{
this->copy(other);
return *this;
}
// Take a very shallow copy (does not copy OSThread state nor the sensor object)
// If for some reason this is ever used, make sure to call init() after any copy
void copy(const AccelerometerThread &other)
{
if (this != &other) {
clean();
this->device = ScanI2C::FoundDevice(other.device.type,
ScanI2C::DeviceAddress(other.device.address.port, other.device.address.address));
}
}
// Cleanup resources
void clean()
{
isInitialised = false;
sensor.reset();
}
};
#endif
#endif