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, __}, diff --git a/src/Display.h b/src/Display.h index 7e8d7c1..7955c26 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) { // } @@ -74,7 +73,7 @@ public: pixels[mapPixel(x, y)] = false; } } - setBrightness(32); + setBrightness(64); clear(); show(); } @@ -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]) { diff --git a/src/mode/ModeTimer.h b/src/mode/ModeTimer.h index d264c4d..ba72794 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]() { @@ -127,6 +134,7 @@ public: } if (!countdown.isRunning()) { init(); + doBeep(1); countdown.start(); } else { pause.toggle(); @@ -140,7 +148,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 +192,6 @@ public: } private: - void doBeep(const uint32_t count) { beepSet(true); beep.startCount(count * 2 - 1); @@ -215,7 +232,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 +241,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 13da39c..a85a34d 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 { bool negative;