Add generic thread module (#5484)

* compiling, untested

* use INCLUDE not EXLUDE for option to include module

* protobuf update

* working genericthread module

Update protobufs

* use EXCLUDE style instead of INCLUDE

* Update Modules.cpp

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
Tavis
2025-04-11 07:38:44 -10:00
committed by GitHub
parent e957009019
commit e7ce910c3b
4 changed files with 58 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ build_flags = -Wno-missing-field-initializers
-DMESHTASTIC_EXCLUDE_REMOTEHARDWARE=1 -DMESHTASTIC_EXCLUDE_REMOTEHARDWARE=1
-DMESHTASTIC_EXCLUDE_HEALTH_TELEMETRY=1 -DMESHTASTIC_EXCLUDE_HEALTH_TELEMETRY=1
-DMESHTASTIC_EXCLUDE_POWERSTRESS=1 ; exclude power stress test module from main firmware -DMESHTASTIC_EXCLUDE_POWERSTRESS=1 ; exclude power stress test module from main firmware
-DMESHTASTIC_EXCLUDE_GENERIC_THREAD_MODULE=1
#-DBUILD_EPOCH=$UNIX_TIME #-DBUILD_EPOCH=$UNIX_TIME
#-D OLED_PL=1 #-D OLED_PL=1

View File

@@ -0,0 +1,28 @@
#include "GenericThreadModule.h"
#include "MeshService.h"
#include "configuration.h"
#include <Arduino.h>
/*
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);
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "MeshModule.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
#include <functional>
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;

View File

@@ -65,6 +65,10 @@
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_POWER_TELEMETRY #if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_POWER_TELEMETRY
#include "modules/Telemetry/PowerTelemetry.h" #include "modules/Telemetry/PowerTelemetry.h"
#endif #endif
#if !MESHTASTIC_EXCLUDE_GENERIC_THREAD_MODULE
#include "modules/GenericThreadModule.h"
#endif
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
#if defined(USE_SX1280) && !MESHTASTIC_EXCLUDE_AUDIO #if defined(USE_SX1280) && !MESHTASTIC_EXCLUDE_AUDIO
#include "modules/esp32/AudioModule.h" #include "modules/esp32/AudioModule.h"
@@ -131,6 +135,9 @@ void setupModules()
#if !MESHTASTIC_EXCLUDE_DROPZONE #if !MESHTASTIC_EXCLUDE_DROPZONE
dropzoneModule = new DropzoneModule(); dropzoneModule = new DropzoneModule();
#endif
#if !MESHTASTIC_EXCLUDE_GENERIC_THREAD_MODULE
new GenericThreadModule();
#endif #endif
// Note: if the rest of meshtastic doesn't need to explicitly use your module, you do not need to assign the instance // 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. // 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 // NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra
// acks // acks
routingModule = new RoutingModule(); routingModule = new RoutingModule();
} }