From 38a1315599bbfd2c79fdae2f5456520aedb20f82 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 29 Dec 2022 16:26:25 -0600 Subject: [PATCH] Refactor OSThread consumers to use disable() --- src/concurrency/OSThread.cpp | 4 ++-- src/input/RotaryEncoderInterruptImpl1.cpp | 3 +-- src/input/cardKbI2cImpl.cpp | 4 +--- src/mesh/http/WebServer.cpp | 10 ++++------ src/modules/CannedMessageModule.cpp | 6 ++---- src/modules/ExternalNotificationModule.cpp | 3 +-- src/modules/esp32/AudioModule.cpp | 3 +-- src/modules/esp32/StoreForwardModule.cpp | 3 +-- src/mqtt/MQTT.cpp | 3 +-- 9 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/concurrency/OSThread.cpp b/src/concurrency/OSThread.cpp index c5adf297b..53058de6a 100644 --- a/src/concurrency/OSThread.cpp +++ b/src/concurrency/OSThread.cpp @@ -93,10 +93,10 @@ void OSThread::run() currentThread = NULL; } -void OSThread::disable() { +void OSThread::disable() +{ enabled = false; setInterval(INT32_MAX); - } /** diff --git a/src/input/RotaryEncoderInterruptImpl1.cpp b/src/input/RotaryEncoderInterruptImpl1.cpp index f5fd6855a..7bf66ac55 100644 --- a/src/input/RotaryEncoderInterruptImpl1.cpp +++ b/src/input/RotaryEncoderInterruptImpl1.cpp @@ -9,8 +9,7 @@ void RotaryEncoderInterruptImpl1::init() { if (!moduleConfig.canned_message.rotary1_enabled) { // Input device is disabled. - setInterval(INT32_MAX); - enabled = false; + disable(); return; } diff --git a/src/input/cardKbI2cImpl.cpp b/src/input/cardKbI2cImpl.cpp index 4b4fc764b..3d30fb867 100644 --- a/src/input/cardKbI2cImpl.cpp +++ b/src/input/cardKbI2cImpl.cpp @@ -12,9 +12,7 @@ void CardKbI2cImpl::init() { if (cardkb_found != CARDKB_ADDR) { - // Input device is not detected. - setInterval(INT32_MAX); - enabled = false; + disable(); return; } diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 95850f5d8..860c10219 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -166,17 +166,15 @@ void createSSLCert() WebServerThread *webServerThread; WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") { - if(!config.network.wifi_enabled) { - setInterval(INT32_MAX); - enabled = false; + if (!config.network.wifi_enabled) { + disable(); } } int32_t WebServerThread::runOnce() { - if(!config.network.wifi_enabled) { - setInterval(INT32_MAX); - enabled = false; + if (!config.network.wifi_enabled) { + disable(); } handleWebResponse(); diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 74a4aaeaf..682d0efdb 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -55,16 +55,14 @@ 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; + disable(); } else { DEBUG_MSG("CannedMessageModule is enabled\n"); this->inputObserver.observe(inputBroker); } } else { this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED; - setInterval(INT32_MAX); - enabled = false; + disable(); } } diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index 8746f8048..f22bdf8f1 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -199,8 +199,7 @@ ExternalNotificationModule::ExternalNotificationModule() } } else { DEBUG_MSG("External Notification Module Disabled\n"); - setInterval(INT32_MAX); - enabled = false; + disable(); } } diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index bd79be7cb..25762aa3f 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -139,8 +139,7 @@ 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; + disable(); DEBUG_MSG("Codec2 disabled (AudioModule %d, Region %s, permitted %d)\n", moduleConfig.audio.codec2_enabled, myRegion->name, myRegion->audioPermitted); } } diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index ec1e3d695..af0e60ed7 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -460,8 +460,7 @@ StoreForwardModule::StoreForwardModule() DEBUG_MSG("*** Initializing Store & Forward Module in Client mode\n"); } } else { - setInterval(INT32_MAX); - enabled = false; + disable(); } #endif } diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 8dcf7eb90..4cd6dcee4 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -137,8 +137,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_ // preflightSleepObserver.observe(&preflightSleep); } else { - setInterval(INT32_MAX); - enabled = false; + disable(); } }