use task for interruptions: button and led

This commit is contained in:
Nicu Hodos 2023-07-11 23:34:40 +02:00
parent 584fa688c3
commit 22544c225a

View File

@ -10,7 +10,6 @@ void onButtonCallback();
Scheduler ts;
Task tCheckWifi(5 * TASK_MINUTE, TASK_ONCE, checkWifiCallback, &ts);
Task tWifiConnected(TASK_IMMEDIATE, TASK_ONCE, onWifiConnected, &ts);
Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts);
#include "wifi.h"
#include "mqtt.h"
@ -22,6 +21,12 @@ Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts);
#define BUTTON D3
Task tButton(TASK_IMMEDIATE, TASK_ONCE, []() {
Display::displayTemp(Bmp::data.readTemp());
}, &ts);
Task tLed(TASK_IMMEDIATE, TASK_ONCE, []() {
Mqtt::publish(Mqtt::ledMqtt->stateTopic, digitalRead(LED_BUILTIN) ? "OFF" : "ON");
}, &ts);
void setup() {
@ -73,9 +78,5 @@ ICACHE_RAM_ATTR void onButtonPressed() {
}
ICACHE_RAM_ATTR void onLed() {
Mqtt::publish(Mqtt::ledMqtt->stateTopic, digitalRead(LED_BUILTIN) ? "OFF" : "ON");
}
void onButtonCallback() {
Display::displayTemp(Bmp::data.readTemp());
tLed.restart();
}