From 22544c225a0cec02aaeac5042c6e6bc713982ff3 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Tue, 11 Jul 2023 23:34:40 +0200 Subject: [PATCH] use task for interruptions: button and led --- src/esp_clock.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index b4131dc..88cd826 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -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(); }