From 900cf664b4c04bdb03c4c03c9d3a1cc92e355cd6 Mon Sep 17 00:00:00 2001 From: Nicolae Hodos Date: Tue, 7 Dec 2021 10:53:43 +0100 Subject: [PATCH] move loop tasks in their namespaces --- include/ir.h | 11 +++++++---- include/ota.h | 8 +++++--- src/esp_clock.cpp | 14 +++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/ir.h b/include/ir.h index 1a14334..df8ea5e 100644 --- a/include/ir.h +++ b/include/ir.h @@ -12,6 +12,9 @@ namespace Ir { + void loop(); + Task tLoop(TASK_IMMEDIATE, TASK_FOREVER, loop, &ts, true); + IRrecv irrecv(IR_INPUT_PIN); decode_results results; bool avrOn = false; @@ -40,10 +43,6 @@ namespace Ir { Display::adjustTime(); } - void setup() { - irrecv.enableIRIn(); // Start the receiver - } - void loop() { if (readCommand()) { Display::tDisplay.setCallback(displayValue); @@ -72,6 +71,10 @@ namespace Ir { Mqtt::commands.pop(); } } + + void setup() { + irrecv.enableIRIn(); // Start the receiver + } } #else diff --git a/include/ota.h b/include/ota.h index 69b736f..b834a8a 100644 --- a/include/ota.h +++ b/include/ota.h @@ -1,7 +1,9 @@ #include -namespace Ota -{ +namespace Ota { + + void loop(); + Task tLoop(TASK_IMMEDIATE, TASK_FOREVER, loop, &ts, true); void setup() { ArduinoOTA.onStart([]() { @@ -25,6 +27,6 @@ namespace Ota } void loop() { - ArduinoOTA.handle(); + ArduinoOTA.handle(); } } diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index 2869b64..085f3d9 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -17,10 +17,9 @@ StatusRequest wifiConnected; #define STAY_CONNECTED_AFTER_BOOT 5*60 void wifiConnectedCallback(); -void otaCallback(); +void checkWifiCallback(); -Task tOta(TASK_IMMEDIATE, TASK_FOREVER, otaCallback, &ts); -Task tIr(TASK_IMMEDIATE, TASK_FOREVER, Ir::loop, &ts); +Task tCheckWifi(5000, TASK_FOREVER, checkWifiCallback, &ts); Task tWifiReconnect(Wifi::reconnect, &ts); Task tWifiConnected(wifiConnectedCallback, &ts); @@ -52,14 +51,15 @@ void wifiConnectedCallback() { Serial.println(asctime(localtime(&newTime))); Ntp::lastConnectedTime = newTime; } - tOta.enable(); + Ota::tLoop.enable(); + tCheckWifi.enable(); Mqtt::client.connect(); } -void otaCallback() { - Ota::loop(); +void checkWifiCallback() { if ((difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) && !Ir::avrOn) { Wifi::disconnect(); - tOta.disable(); + Ota::tLoop.disable(); + tCheckWifi.disable(); } }