move loop tasks in their own namespaces
This commit is contained in:
parent
9e118cc1b9
commit
d69027658b
11
include/ir.h
11
include/ir.h
@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
namespace Ir {
|
namespace Ir {
|
||||||
|
|
||||||
|
void loop();
|
||||||
|
Task tLoop(TASK_IMMEDIATE, TASK_FOREVER, loop, &ts, true);
|
||||||
|
|
||||||
IRrecv irrecv(IR_INPUT_PIN);
|
IRrecv irrecv(IR_INPUT_PIN);
|
||||||
decode_results results;
|
decode_results results;
|
||||||
bool avrOn = false;
|
bool avrOn = false;
|
||||||
@ -40,10 +43,6 @@ namespace Ir {
|
|||||||
Display::adjustTime();
|
Display::adjustTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
|
||||||
irrecv.enableIRIn(); // Start the receiver
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (readCommand()) {
|
if (readCommand()) {
|
||||||
Display::tDisplay.setCallback(displayValue);
|
Display::tDisplay.setCallback(displayValue);
|
||||||
@ -72,6 +71,10 @@ namespace Ir {
|
|||||||
Mqtt::commands.pop();
|
Mqtt::commands.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
irrecv.enableIRIn(); // Start the receiver
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
namespace Ota
|
namespace Ota {
|
||||||
{
|
|
||||||
|
void loop();
|
||||||
|
Task tLoop(TASK_IMMEDIATE, TASK_FOREVER, loop, &ts, true);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
@ -25,6 +27,6 @@ namespace Ota
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,9 +17,9 @@ StatusRequest wifiConnected;
|
|||||||
#define STAY_CONNECTED_AFTER_BOOT 5*60
|
#define STAY_CONNECTED_AFTER_BOOT 5*60
|
||||||
|
|
||||||
void wifiConnectedCallback();
|
void wifiConnectedCallback();
|
||||||
void otaCallback();
|
void checkWifiCallback();
|
||||||
|
|
||||||
Task tOta(TASK_IMMEDIATE, TASK_FOREVER, otaCallback, &ts);
|
Task tCheckWifi(5000, TASK_FOREVER, checkWifiCallback, &ts);
|
||||||
Task tWifiReconnect(Wifi::reconnect, &ts);
|
Task tWifiReconnect(Wifi::reconnect, &ts);
|
||||||
Task tWifiConnected(wifiConnectedCallback, &ts);
|
Task tWifiConnected(wifiConnectedCallback, &ts);
|
||||||
|
|
||||||
@ -42,8 +42,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Ir::loop();
|
|
||||||
|
|
||||||
ts.execute();
|
ts.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,14 +51,15 @@ void wifiConnectedCallback() {
|
|||||||
Serial.println(asctime(localtime(&newTime)));
|
Serial.println(asctime(localtime(&newTime)));
|
||||||
Ntp::lastConnectedTime = newTime;
|
Ntp::lastConnectedTime = newTime;
|
||||||
}
|
}
|
||||||
tOta.enable();
|
Ota::tLoop.enable();
|
||||||
|
tCheckWifi.enable();
|
||||||
Mqtt::client.connect();
|
Mqtt::client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void otaCallback() {
|
void checkWifiCallback() {
|
||||||
Ota::loop();
|
|
||||||
if ((difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) && !Ir::avrOn) {
|
if ((difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) && !Ir::avrOn) {
|
||||||
Wifi::disconnect();
|
Wifi::disconnect();
|
||||||
tOta.disable();
|
Ota::tLoop.disable();
|
||||||
|
tCheckWifi.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user