diff --git a/src/input/RotaryEncoderInterruptBase.cpp b/src/input/RotaryEncoderInterruptBase.cpp index 6914824fd..f6df7fb2c 100644 --- a/src/input/RotaryEncoderInterruptBase.cpp +++ b/src/input/RotaryEncoderInterruptBase.cpp @@ -54,7 +54,7 @@ int32_t RotaryEncoderInterruptBase::runOnce() this->action = ROTARY_ACTION_NONE; - return 30000; // TODO: technically this can be MAX_INT + return INT32_MAX; } void RotaryEncoderInterruptBase::intPressHandler() diff --git a/src/input/RotaryEncoderInterruptBase.h b/src/input/RotaryEncoderInterruptBase.h index c468f4dc6..88d619178 100644 --- a/src/input/RotaryEncoderInterruptBase.h +++ b/src/input/RotaryEncoderInterruptBase.h @@ -7,7 +7,7 @@ enum RotaryEncoderInterruptBaseStateType { ROTARY_EVENT_OCCURRED, ROTARY_EVENT_C enum RotaryEncoderInterruptBaseActionType { ROTARY_ACTION_NONE, ROTARY_ACTION_PRESSED, ROTARY_ACTION_CW, ROTARY_ACTION_CCW }; -class RotaryEncoderInterruptBase : public Observable, private concurrency::OSThread +class RotaryEncoderInterruptBase : public Observable, public concurrency::OSThread { public: explicit RotaryEncoderInterruptBase(const char *name); diff --git a/src/input/RotaryEncoderInterruptImpl1.cpp b/src/input/RotaryEncoderInterruptImpl1.cpp index bc897deef..f5fd6855a 100644 --- a/src/input/RotaryEncoderInterruptImpl1.cpp +++ b/src/input/RotaryEncoderInterruptImpl1.cpp @@ -9,6 +9,8 @@ void RotaryEncoderInterruptImpl1::init() { if (!moduleConfig.canned_message.rotary1_enabled) { // Input device is disabled. + setInterval(INT32_MAX); + enabled = false; return; } diff --git a/src/input/cardKbI2cImpl.cpp b/src/input/cardKbI2cImpl.cpp index de0fbbd38..4b4fc764b 100644 --- a/src/input/cardKbI2cImpl.cpp +++ b/src/input/cardKbI2cImpl.cpp @@ -13,6 +13,8 @@ void CardKbI2cImpl::init() if (cardkb_found != CARDKB_ADDR) { // Input device is not detected. + setInterval(INT32_MAX); + enabled = false; return; } diff --git a/src/input/kbI2cBase.h b/src/input/kbI2cBase.h index 086078cea..2fdacbc28 100644 --- a/src/input/kbI2cBase.h +++ b/src/input/kbI2cBase.h @@ -5,7 +5,7 @@ class KbI2cBase : public Observable, - private concurrency::OSThread + public concurrency::OSThread { public: explicit KbI2cBase(const char *name); diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index c1844b0cb..95850f5d8 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -165,11 +165,20 @@ void createSSLCert() WebServerThread *webServerThread; -WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} +WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") { + if(!config.network.wifi_enabled) { + setInterval(INT32_MAX); + enabled = false; + } +} int32_t WebServerThread::runOnce() { - // DEBUG_MSG("WebServerThread::runOnce()\n"); + if(!config.network.wifi_enabled) { + setInterval(INT32_MAX); + enabled = false; + } + handleWebResponse(); if (requestRestart && (millis() / 1000) > requestRestart) { diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 4357ee2ca..a36e95a05 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -55,10 +55,18 @@ CannedMessageModule::CannedMessageModule() if ((this->splitConfiguredMessages() <= 0) && (cardkb_found != CARDKB_ADDR)) { DEBUG_MSG("CannedMessageModule: No messages are configured. Module is disabled\n"); this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED; + setInterval(INT32_MAX); + enabled = false; } else { DEBUG_MSG("CannedMessageModule is enabled\n"); this->inputObserver.observe(inputBroker); } + setInterval(INT32_MAX); + enabled = false; + } else { + this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED; + setInterval(INT32_MAX); + enabled = false; } } diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index be3e6cd8b..8746f8048 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -199,6 +199,7 @@ ExternalNotificationModule::ExternalNotificationModule() } } else { DEBUG_MSG("External Notification Module Disabled\n"); + setInterval(INT32_MAX); enabled = false; } } diff --git a/src/modules/RemoteHardwareModule.cpp b/src/modules/RemoteHardwareModule.cpp index 26f1c4dba..419885822 100644 --- a/src/modules/RemoteHardwareModule.cpp +++ b/src/modules/RemoteHardwareModule.cpp @@ -48,64 +48,66 @@ static uint64_t digitalReads(uint64_t mask) RemoteHardwareModule::RemoteHardwareModule() : ProtobufModule("remotehardware", PortNum_REMOTE_HARDWARE_APP, &HardwareMessage_msg), concurrency::OSThread( - "remotehardware") + "RemoteHardwareModule") { } bool RemoteHardwareModule::handleReceivedProtobuf(const MeshPacket &req, HardwareMessage *pptr) { - auto p = *pptr; - DEBUG_MSG("Received RemoteHardware typ=%d\n", p.type); + if (moduleConfig.remote_hardware.enabled) { + auto p = *pptr; + DEBUG_MSG("Received RemoteHardware typ=%d\n", p.type); - switch (p.type) { - case HardwareMessage_Type_WRITE_GPIOS: - // Print notification to LCD screen - screen->print("Write GPIOs\n"); + switch (p.type) { + case HardwareMessage_Type_WRITE_GPIOS: + // Print notification to LCD screen + screen->print("Write GPIOs\n"); - for (uint8_t i = 0; i < NUM_GPIOS; i++) { - uint64_t mask = 1 << i; - if (p.gpio_mask & mask) { - digitalWrite(i, (p.gpio_value & mask) ? 1 : 0); + for (uint8_t i = 0; i < NUM_GPIOS; i++) { + uint64_t mask = 1 << i; + if (p.gpio_mask & mask) { + digitalWrite(i, (p.gpio_value & mask) ? 1 : 0); + } } + pinModes(p.gpio_mask, OUTPUT); + + break; + + case HardwareMessage_Type_READ_GPIOS: { + // Print notification to LCD screen + if (screen) + screen->print("Read GPIOs\n"); + + uint64_t res = digitalReads(p.gpio_mask); + + // Send the reply + HardwareMessage r = HardwareMessage_init_default; + r.type = HardwareMessage_Type_READ_GPIOS_REPLY; + r.gpio_value = res; + r.gpio_mask = p.gpio_mask; + MeshPacket *p2 = allocDataProtobuf(r); + setReplyTo(p2, req); + myReply = p2; + break; } - pinModes(p.gpio_mask, OUTPUT); - break; + case HardwareMessage_Type_WATCH_GPIOS: { + watchGpios = p.gpio_mask; + lastWatchMsec = 0; // Force a new publish soon + previousWatch = ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish) + enabled = true; // Let our thread run at least once + DEBUG_MSG("Now watching GPIOs 0x%llx\n", watchGpios); + break; + } - case HardwareMessage_Type_READ_GPIOS: { - // Print notification to LCD screen - if (screen) - screen->print("Read GPIOs\n"); + case HardwareMessage_Type_READ_GPIOS_REPLY: + case HardwareMessage_Type_GPIOS_CHANGED: + break; // Ignore - we might see our own replies - uint64_t res = digitalReads(p.gpio_mask); - - // Send the reply - HardwareMessage r = HardwareMessage_init_default; - r.type = HardwareMessage_Type_READ_GPIOS_REPLY; - r.gpio_value = res; - r.gpio_mask = p.gpio_mask; - MeshPacket *p2 = allocDataProtobuf(r); - setReplyTo(p2, req); - myReply = p2; - break; - } - - case HardwareMessage_Type_WATCH_GPIOS: { - watchGpios = p.gpio_mask; - lastWatchMsec = 0; // Force a new publish soon - previousWatch = ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish) - enabled = true; // Let our thread run at least once - DEBUG_MSG("Now watching GPIOs 0x%llx\n", watchGpios); - break; - } - - case HardwareMessage_Type_READ_GPIOS_REPLY: - case HardwareMessage_Type_GPIOS_CHANGED: - break; // Ignore - we might see our own replies - - default: - DEBUG_MSG("Hardware operation %d not yet implemented! FIXME\n", p.type); - break; + default: + DEBUG_MSG("Hardware operation %d not yet implemented! FIXME\n", p.type); + break; + } } return false; @@ -113,7 +115,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const MeshPacket &req, Hardwar int32_t RemoteHardwareModule::runOnce() { - if (watchGpios) { + if (moduleConfig.remote_hardware.enabled && watchGpios) { uint32_t now = millis(); if (now - lastWatchMsec >= WATCH_INTERVAL_MSEC) { @@ -134,6 +136,7 @@ int32_t RemoteHardwareModule::runOnce() } else { // No longer watching anything - stop using CPU enabled = false; + return INT32_MAX; } return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg) diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index eb8f0986b..00d8df9d2 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -222,6 +222,7 @@ int32_t SerialModule::runOnce() } else { DEBUG_MSG("Serial Module Disabled\n"); + enabled = false; return INT32_MAX; } } @@ -303,9 +304,6 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp) } } } - - } else { - DEBUG_MSG("Serial Module Disabled\n"); } return ProcessMessage::CONTINUE; // Let others look at this message also if they want } diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 11955f3f6..500acd7f7 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -67,6 +67,7 @@ int32_t EnvironmentTelemetryModule::runOnce() if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled)) { // If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it + enabled = false; return result; } diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index e7132fcc4..bd79be7cb 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -139,6 +139,8 @@ AudioModule::AudioModule() : SinglePortModule("AudioModule", PortNum_AUDIO_APP), DEBUG_MSG(" using %d frames of %d bytes for a total payload length of %d bytes\n", encode_frame_num, encode_codec_size, encode_frame_size); xTaskCreate(&run_codec2, "codec2_task", 30000, NULL, 5, &codec2HandlerTask); } else { + setInterval(INT32_MAX); + enabled = false; DEBUG_MSG("Codec2 disabled (AudioModule %d, Region %s, permitted %d)\n", moduleConfig.audio.codec2_enabled, myRegion->name, myRegion->audioPermitted); } } @@ -259,6 +261,7 @@ int32_t AudioModule::runOnce() return 100; } else { DEBUG_MSG("Audio Module Disabled\n"); + enabled = false; return INT32_MAX; } diff --git a/src/modules/esp32/RangeTestModule.cpp b/src/modules/esp32/RangeTestModule.cpp index d706f8ed3..5e52fea40 100644 --- a/src/modules/esp32/RangeTestModule.cpp +++ b/src/modules/esp32/RangeTestModule.cpp @@ -82,6 +82,7 @@ int32_t RangeTestModule::runOnce() return (senderHeartbeat); } else { + enabled = false; return (INT32_MAX); // This thread does not need to run as a receiver } @@ -94,6 +95,7 @@ int32_t RangeTestModule::runOnce() } #endif + enabled = false; return (INT32_MAX); } diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index 54a250d2a..ec1e3d695 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -52,6 +52,7 @@ int32_t StoreForwardModule::runOnce() return (this->packetTimeMax); } #endif + enabled = false; // Client doesn't need periodical return (INT32_MAX); } @@ -458,6 +459,9 @@ StoreForwardModule::StoreForwardModule() is_client = true; DEBUG_MSG("*** Initializing Store & Forward Module in Client mode\n"); } + } else { + setInterval(INT32_MAX); + enabled = false; } #endif } diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index df2d9b093..8dcf7eb90 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -128,12 +128,18 @@ void mqttInit() MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE) { - assert(!mqtt); - mqtt = this; + if(moduleConfig.mqtt.enabled) { - pubSub.setCallback(mqttCallback); + assert(!mqtt); + mqtt = this; - // preflightSleepObserver.observe(&preflightSleep); + pubSub.setCallback(mqttCallback); + + // preflightSleepObserver.observe(&preflightSleep); + } else { + setInterval(INT32_MAX); + enabled = false; + } } bool MQTT::connected() @@ -238,6 +244,10 @@ bool MQTT::wantsLink() const int32_t MQTT::runOnce() { + if(!moduleConfig.mqtt.enabled) { + enabled = false; + return INT32_MAX; + } bool wantConnection = wantsLink(); // If connected poll rapidly, otherwise only occasionally check for a wifi connection change and ability to contact server