From f807698cdde72fca2b9b3d2cf3aa3617efdf3076 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 5 Dec 2021 13:22:55 +0100 Subject: [PATCH] use TaskScheduler - use task for displaying colon - update display only when minute changes --- include/display.h | 24 +++++++++++++++++++----- include/ir.h | 2 +- platformio.ini | 1 + src/esp_clock.cpp | 11 +++++------ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/display.h b/include/display.h index 19f287e..8cb2181 100644 --- a/include/display.h +++ b/include/display.h @@ -9,7 +9,12 @@ namespace Display { + void displayColon(); + uint8_t brightness = BRIGHTNESS; + int currentMin = -1; + + Task blinkColon(500, TASK_FOREVER, displayColon, &ts, true); // Create display object Adafruit_7segment clockDisplay = Adafruit_7segment(); @@ -35,6 +40,7 @@ namespace Display { void changeBrightness(bool increase) { increase ? brightness = (brightness + 2) % 15 : brightness = (brightness - 2) % 15; + clockDisplay.setBrightness(brightness); } void adjustBrightness() { @@ -44,12 +50,20 @@ namespace Display { } else { brightness = 1; } + clockDisplay.setBrightness(brightness); } - void displayColon(bool on) { - clockDisplay.setBrightness(brightness); - clockDisplay.drawColon(on); + void displayColon() { + static bool colonOn = false; + + if (colonOn && currentMin != minute()) { + currentMin = minute(); + displayTime(); + } + clockDisplay.drawColon(colonOn); clockDisplay.writeDisplay(); + + colonOn = !colonOn; } void displayValue(int value) { @@ -60,6 +74,6 @@ namespace Display { clockDisplay.begin(DISPLAY_ADDRESS); clockDisplay.setBrightness(brightness); displayTime(); - displayColon(false); + displayColon(); } -} \ No newline at end of file +} diff --git a/include/ir.h b/include/ir.h index 6e38967..0894f48 100644 --- a/include/ir.h +++ b/include/ir.h @@ -64,7 +64,7 @@ namespace Ir { void loop() { if (readCommand()) { Display::displayValue(lastCommand); - Display::displayColon(false); + // Display::displayColon(false); delay(1000); switch (lastCommand) { diff --git a/platformio.ini b/platformio.ini index 84cbd60..b8e069d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,6 +20,7 @@ lib_deps = jchristensen/Timezone@^1.2.4 ottowinter/AsyncMqttClient-esphome@^0.8.5 crankyoldgit/IRremoteESP8266@^2.7.18 + arkhipenko/TaskScheduler@^3.4.0 [env:dev_mode] build_flags = -D IR=1 diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index 78d74d3..b08b246 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -1,4 +1,8 @@ #include + +#include +Scheduler ts; + #include "wifi.h" #include "ota.h" #include "ntp_time.h" @@ -42,11 +46,6 @@ void loop() { wifi.disconnect(); } } - Display::displayTime(); - Display::displayColon(true); - delay(500); - Display::displayColon(false); - delay(500); - yield(); + ts.execute(); }