From 87509eb5f15c5faf9bb961a4018a34f37e427b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Tue, 26 Aug 2025 19:04:59 +0200 Subject: [PATCH 1/5] ceiling Rest time depending on smallest displayed time-unit --- src/mode/ModeTimer.h | 33 +++++++++++++++++++++++++++++---- src/mode/Rest.h | 7 +++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/mode/ModeTimer.h b/src/mode/ModeTimer.h index d264c4d..a002036 100644 --- a/src/mode/ModeTimer.h +++ b/src/mode/ModeTimer.h @@ -8,6 +8,14 @@ #include "Rest.h" #include "Timer.h" +#define DEC_MIL ( 100 ) +#define SEC_MIL ( 1000 ) +#define MIN_MIL ( 60 * SEC_MIL ) +#define HOU_MIL ( 60 * MIN_MIL ) +#define DAY_MIL ( 24 * HOU_MIL ) + +#define ENABLE_DECIS false + enum Stage { FIRST_HALF, SECOND_HALF, LAST_MINUTE, FINALE }; @@ -69,7 +77,6 @@ class ModeTimer final : public Mode { Rest last{0}; public: - explicit ModeTimer() : Mode("Timer"), countdown("countdown", [this]() { @@ -140,7 +147,17 @@ public: } void draw(Display &display) override { - rest = Rest(countdown.getRestMillis()); + if (countdown.getRestMillis() >= DAY_MIL) { + rest = Rest(intCeilDiv(countdown.getRestMillis(), HOU_MIL) * HOU_MIL); + } else if (countdown.getRestMillis() >= MIN_MIL) { + rest = Rest(intCeilDiv(countdown.getRestMillis(), SEC_MIL) * SEC_MIL); + } else { +#if ENABLE_DECIS + rest = Rest(intCeilDiv(countdown.getRestMillis(), DEC_MIL) * DEC_MIL); +#else + rest = Rest(intCeilDiv(countdown.getRestMillis(), SEC_MIL) * SEC_MIL); +#endif + } display.clear(); if (flash.isRunning()) { @@ -174,7 +191,6 @@ public: } private: - void doBeep(const uint32_t count) { beepSet(true); beep.startCount(count * 2 - 1); @@ -215,7 +231,8 @@ private: dirty |= rest.hourChanged(last); dirtyPrint = true; } else if (rest.hoursTotal > 0) { - display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d:%02d:%02d", rest.hoursPart, rest.minutesPart, rest.secondsPart); + display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d:%02d:%02d", rest.hoursPart, rest.minutesPart, + rest.secondsPart); dirty |= rest.secondChanged(last); dirtyPrint = true; } else if (rest.minutesTotal > 0) { @@ -223,7 +240,15 @@ private: dirty |= rest.secondChanged(last); dirtyPrint = true; } else { +#if ENABLE_DECIS display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d.%d", rest.secondsPart, rest.decisPart); +#else + if (rest.secondsTotal > 9) { + display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d", rest.secondsPart, rest.secondsPart); + } else { + display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d %d %d", rest.secondsPart, rest.secondsPart, rest.secondsPart); + } +#endif dirty |= rest.deciChanged(last); dirtyPrint |= rest.secondChanged(last); } diff --git a/src/mode/Rest.h b/src/mode/Rest.h index cacd8a3..59297e5 100644 --- a/src/mode/Rest.h +++ b/src/mode/Rest.h @@ -1,6 +1,13 @@ #ifndef REST_H #define REST_H +inline uint32_t intCeilDiv(const uint32_t dividend, const uint32_t divisor) { + if (dividend == 0) { + return 0; + } + return (dividend + divisor - 1) / divisor; +} + struct Rest { uint64_t millisTotal; From 2613a099a7b92ed3443c28be8662a632a7361764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Tue, 26 Aug 2025 19:05:24 +0200 Subject: [PATCH 2/5] FIX pixels outside Display check --- src/Display.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Display.h b/src/Display.h index 7e8d7c1..4c2b712 100644 --- a/src/Display.h +++ b/src/Display.h @@ -54,7 +54,6 @@ class Display { } public: - explicit Display(): leds(8 * 32, GPIO_NUM_13,NEO_GRB + NEO_KHZ800) { // } @@ -86,11 +85,11 @@ public: } void setPixel(const int x, const int y, const Color &color) { - const auto index = mapPixel(x, y); - if (index >= 8 * 32) { - Serial.printf("[ERROR] No pixel at (%d, %d) = %d >= %d\n", x, y, index, 8 * 32); + if (x >= 32 || y >= 8) { + Serial.printf("[ERROR] No pixel at (%d, %d) >= %d\n", x, y, 8 * 32); return; } + const auto index = mapPixel(x, y); #if LEDS_ENABLED leds.setPixelColor(index, color.r, color.g, color.b); #endif @@ -155,7 +154,8 @@ public: } template - int printSymbol(const int x, const int y, const int index, const Color &color, const bool symbols[][symbolHeight][symbolWidth]) { + int printSymbol(const int x, const int y, const int index, const Color &color, + const bool symbols[][symbolHeight][symbolWidth]) { for (int innerY = 0; innerY < symbolHeight; innerY++) { for (int innerX = 0; innerX < symbolWidth; innerX++) { if (symbols[index][innerY][innerX]) { From 91bdf7a7ad1ae38f528be2c5910f8aac1ebfd40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Tue, 26 Aug 2025 19:12:00 +0200 Subject: [PATCH 3/5] FONT changed: Colon, 1 --- src/Display.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Display.cpp b/src/Display.cpp index 9eb7866..293f821 100644 --- a/src/Display.cpp +++ b/src/Display.cpp @@ -43,13 +43,13 @@ const bool DOT7[][7][1] = { {XX}, }, { - {__}, - {XX}, - {__}, {__}, {__}, {XX}, {__}, + {XX}, + {__}, + {__}, }, { {__}, @@ -94,13 +94,13 @@ const bool NUM7[][7][4] = { {__, XX, XX, __}, }, { + {__, __, __, XX}, {__, __, XX, XX}, {__, XX, __, XX}, {XX, __, __, XX}, {__, __, __, XX}, {__, __, __, XX}, {__, __, __, XX}, - {__, __, __, XX}, }, { {__, XX, XX, __}, From a0744e90596b7c93844e8854be34f858147235a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Tue, 26 Aug 2025 19:14:42 +0200 Subject: [PATCH 4/5] beep at start --- src/mode/ModeTimer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mode/ModeTimer.h b/src/mode/ModeTimer.h index a002036..ba72794 100644 --- a/src/mode/ModeTimer.h +++ b/src/mode/ModeTimer.h @@ -134,6 +134,7 @@ public: } if (!countdown.isRunning()) { init(); + doBeep(1); countdown.start(); } else { pause.toggle(); From db68ca0a873b76ae3671bcd514ae7ae76a4001e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Tue, 26 Aug 2025 19:18:30 +0200 Subject: [PATCH 5/5] brightness 64/256 --- src/Display.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Display.h b/src/Display.h index 4c2b712..7955c26 100644 --- a/src/Display.h +++ b/src/Display.h @@ -73,7 +73,7 @@ public: pixels[mapPixel(x, y)] = false; } } - setBrightness(32); + setBrightness(64); clear(); show(); }