diff --git a/platformio.ini b/platformio.ini index 647114537..e1eabf952 100644 --- a/platformio.ini +++ b/platformio.ini @@ -50,6 +50,7 @@ build_flags = -Wno-missing-field-initializers -DMESHTASTIC_EXCLUDE_REMOTEHARDWARE=1 -DMESHTASTIC_EXCLUDE_HEALTH_TELEMETRY=1 -DMESHTASTIC_EXCLUDE_POWERSTRESS=1 ; exclude power stress test module from main firmware + -DMESHTASTIC_EXCLUDE_GENERIC_THREAD_MODULE=1 #-DBUILD_EPOCH=$UNIX_TIME #-D OLED_PL=1 diff --git a/src/modules/GenericThreadModule.cpp b/src/modules/GenericThreadModule.cpp new file mode 100644 index 000000000..eb92566bd --- /dev/null +++ b/src/modules/GenericThreadModule.cpp @@ -0,0 +1,28 @@ +#include "GenericThreadModule.h" +#include "MeshService.h" +#include "configuration.h" +#include + +/* +Generic Thread Module allows for the execution of custom code at a set interval. +*/ +GenericThreadModule *genericThreadModule; + +GenericThreadModule::GenericThreadModule() : concurrency::OSThread("GenericThreadModule") {} + +int32_t GenericThreadModule::runOnce() +{ + + bool enabled = true; + if (!enabled) + return disable(); + + if (firstTime) { + // do something the first time we run + firstTime = 0; + LOG_INFO("first time GenericThread running"); + } + + LOG_INFO("GenericThread executing"); + return (my_interval); +} diff --git a/src/modules/GenericThreadModule.h b/src/modules/GenericThreadModule.h new file mode 100644 index 000000000..05f7946bb --- /dev/null +++ b/src/modules/GenericThreadModule.h @@ -0,0 +1,21 @@ +#pragma once + +#include "MeshModule.h" +#include "concurrency/OSThread.h" +#include "configuration.h" +#include +#include + +class GenericThreadModule : private concurrency::OSThread +{ + bool firstTime = 1; + + public: + GenericThreadModule(); + + protected: + unsigned int my_interval = 10000; // interval in millisconds + virtual int32_t runOnce() override; +}; + +extern GenericThreadModule *genericThreadModule; diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index e2a4a970c..1f2b50057 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -65,6 +65,10 @@ #if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_POWER_TELEMETRY #include "modules/Telemetry/PowerTelemetry.h" #endif +#if !MESHTASTIC_EXCLUDE_GENERIC_THREAD_MODULE +#include "modules/GenericThreadModule.h" +#endif + #ifdef ARCH_ESP32 #if defined(USE_SX1280) && !MESHTASTIC_EXCLUDE_AUDIO #include "modules/esp32/AudioModule.h" @@ -131,6 +135,9 @@ void setupModules() #if !MESHTASTIC_EXCLUDE_DROPZONE dropzoneModule = new DropzoneModule(); +#endif +#if !MESHTASTIC_EXCLUDE_GENERIC_THREAD_MODULE + new GenericThreadModule(); #endif // Note: if the rest of meshtastic doesn't need to explicitly use your module, you do not need to assign the instance // to a global variable. @@ -249,4 +256,4 @@ void setupModules() // NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra // acks routingModule = new RoutingModule(); -} \ No newline at end of file +}