From 7e5b24a11af337adf3973b7053ac18d7c75a2ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Fri, 10 Jan 2025 13:11:39 +0100 Subject: [PATCH] configCentis --- src/app/AppMatch.h | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app/AppMatch.h b/src/app/AppMatch.h index 9a11dc2..8159b33 100644 --- a/src/app/AppMatch.h +++ b/src/app/AppMatch.h @@ -10,10 +10,15 @@ #define CONFIG_SECONDS_KEY "seconds" #define CONFIG_SECONDS_DEFAULT (6 * 60) +#define CONFIG_CENTIS_KEY "centis" +#define CONFIG_CENTIS_DEFAULT (6 * 60) + class AppMatch final : public App { unsigned long configMillis = 0; + bool configCentis = false; + unsigned long totalMillis = 0; unsigned long totalCentis = 0; @@ -57,6 +62,14 @@ public: configWrite(); return true; } + } else if (key.equals(CONFIG_CENTIS_KEY)) { + const auto newCentis = valueStr.equals("true"); + if (configCentis != newCentis) { + configCentis = newCentis; + configSet(CONFIG_CENTIS_KEY, newCentis); + configWrite(); + return true; + } } return false; } @@ -64,13 +77,14 @@ public: protected: void _start() override { - const auto seconds = configGet(CONFIG_SECONDS_KEY, CONFIG_SECONDS_DEFAULT); + configMillis = configGet(CONFIG_SECONDS_KEY, CONFIG_SECONDS_DEFAULT) * 1000; + configCentis = configGet(CONFIG_CENTIS_KEY, CONFIG_CENTIS_DEFAULT); + info("config:"); - info(" seconds = %ld", seconds); + info(" seconds = %ld", configMillis / 1000); + info(" centis = %s", configCentis ? "true" : "false"); - configMillis = seconds * 1000; totalMillis = configMillis; - setState(PAUSE, true); } @@ -109,14 +123,14 @@ protected: } } - if (state == MINUTES) { + if (state == MINUTES || (state == SECONDS && !configCentis)) { if (updateSeconds != totalSeconds) { updateSeconds = totalSeconds; markDirty(); } } - if (state == SECONDS) { + if (state == SECONDS && configCentis) { markDirty(); } } @@ -137,12 +151,14 @@ protected: display.printf("%2d:%02d", totalMinutes, partSeconds); info("%2d:%02d", totalMinutes, partSeconds); } else if (totalMillis > 0) { - display.printf("%2d.%02d", partSeconds, partCentis); + if (configCentis) { + display.printf("%2d.%02d", partSeconds, partCentis); + } else { + display.printf(" %2d", partSeconds); + } } else { display.printf("00:00"); } - } else if (state == PAUSE) { - display.printf("PAUS"); } } @@ -176,7 +192,7 @@ private: state = newState; switch (state) { case PAUSE: - blinkEnable(500); + blinkEnable(0); break; case MINUTES: updateSeconds = totalSeconds;