From ace5e193f4d5cff22a09bc937122f61d55530b91 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 8 May 2024 14:01:54 -0500 Subject: [PATCH] Move threads --- src/AccelerometerThread.h | 4 +++- src/AmbientLightingThread.h | 4 ++++ src/main.cpp | 9 --------- src/main.h | 5 +++++ src/modules/AdminModule.cpp | 9 ++++++++- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/AccelerometerThread.h b/src/AccelerometerThread.h index 66e5624f1..eb503d26f 100644 --- a/src/AccelerometerThread.h +++ b/src/AccelerometerThread.h @@ -1,3 +1,4 @@ +#pragma once #include "configuration.h" #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR @@ -123,6 +124,7 @@ class AccelerometerThread : public concurrency::OSThread // Duration is number of occurances needed to trigger, higher threshold is less sensitive } } + void start() { setIntervalFromNow(0); }; protected: int32_t runOnce() override @@ -174,7 +176,7 @@ class AccelerometerThread : public concurrency::OSThread Adafruit_LIS3DH lis; Adafruit_LSM6DS3TRC lsm; }; - +extern AccelerometerThread *accelerometerThread; } // namespace concurrency #endif \ No newline at end of file diff --git a/src/AmbientLightingThread.h b/src/AmbientLightingThread.h index 6b3360b1f..7b44ca8a6 100644 --- a/src/AmbientLightingThread.h +++ b/src/AmbientLightingThread.h @@ -1,3 +1,5 @@ +#pragma once + #include "configuration.h" #ifdef HAS_NCP5623 @@ -81,6 +83,7 @@ class AmbientLightingThread : public concurrency::OSThread #endif return disable(); } + void start() { setIntervalFromNow(0); }; private: ScanI2C::DeviceType _type = ScanI2C::DeviceType::NONE; @@ -125,5 +128,6 @@ class AmbientLightingThread : public concurrency::OSThread #endif } }; +extern AmbientLightingThread *ambientLightingThread; } // namespace concurrency \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a6c1dd9fb..ece682725 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,11 +94,6 @@ NRF52Bluetooth *nrf52Bluetooth; #include "PowerFSMThread.h" -#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) -#include "AccelerometerThread.h" -#include "AmbientLightingThread.h" -#endif - #ifdef HAS_I2S #include "AudioThread.h" AudioThread *audioThread; @@ -197,10 +192,6 @@ uint32_t timeLastPowered = 0; static Periodic *ledPeriodic; static OSThread *powerFSMthread; -#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR -static OSThread *accelerometerThread; -#endif -static OSThread *ambientLightingThread; SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0); RadioInterface *rIf = NULL; diff --git a/src/main.h b/src/main.h index bb812b7b6..e81f6c5e6 100644 --- a/src/main.h +++ b/src/main.h @@ -53,6 +53,11 @@ extern Adafruit_DRV2605 drv; extern AudioThread *audioThread; #endif +#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) +#include "AccelerometerThread.h" +#include "AmbientLightingThread.h" +#endif + extern bool isVibrating; extern int TCPPort; // set by Portduino diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index d66a20432..2135d47aa 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -26,6 +26,9 @@ #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" #endif +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR +#include "AccelerometerThread.h" +#endif AdminModule *adminModule; bool hasOpenEditTransaction; @@ -391,10 +394,14 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) config.has_display = true; if (config.display.screen_on_secs == c.payload_variant.display.screen_on_secs && config.display.flip_screen == c.payload_variant.display.flip_screen && - config.display.wake_on_tap_or_motion == c.payload_variant.display.wake_on_tap_or_motion && config.display.oled == c.payload_variant.display.oled) { requiresReboot = false; } +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + if (config.display.wake_on_tap_or_motion == false && c.payload_variant.display.wake_on_tap_or_motion == true) { + accelerometerThread->start(); + } +#endif config.display = c.payload_variant.display; break; case meshtastic_Config_lora_tag: