Countdown WIP

This commit is contained in:
Patrick Haßel 2025-08-25 10:21:51 +02:00
parent 4fe7d9cb81
commit 3643baa0be
3 changed files with 79 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include "wifi.h" #include "wifi.h"
#include "mode/Mode.h" #include "mode/Mode.h"
#include "mode/ModeTimer.h" #include "mode/ModeTimer.h"
#include "mode/ModeCountdown.h"
void stepMode(); void stepMode();
@ -12,7 +13,7 @@ void buttonCallback(ButtonEvent event);
Display display; Display display;
ModeTimer mode; ModeCountdown mode;
Button button(23, buttonCallback); Button button(23, buttonCallback);

68
src/mode/ModeCountdown.h Normal file
View File

@ -0,0 +1,68 @@
#ifndef MODE_COUNTDOWN_H
#define MODE_COUNTDOWN_H
#include <Preferences.h>
#include "Mode.h"
#include "Rest.h"
class ModeCountdown final : public Mode {
uint32_t targetEpochSeconds = 0;
bool bars = false;
public:
explicit ModeCountdown() : Mode("Countdown") {
//
}
void init() override {
Preferences preferences;
preferences.begin("Countdown", true);
targetEpochSeconds = preferences.getULong("targetEpochSeconds", 1767222000);
bars = preferences.getBool("bars", false);
preferences.end();
}
void draw(Display &display) override {
const auto rest = Rest(targetEpochSeconds - time(nullptr));
if (rest.isPositive()) {
if (bars) {
drawCountdownBars(display, rest);
} else {
drawCountdownNumbers(display, rest);
}
} else {
drawAnimation(display);
}
}
private:
static void drawCountdownBars(const Display &display, const Rest &rest) {
// TODO
}
static void drawCountdownNumbers(Display &display, const Rest &rest) {
display.clear();
if (rest.daysPart > 9) {
display.print(15, 0, ALIGN_CENTER, FONT7, WHITE, "%d Tage", rest.daysPart);
} else if (rest.daysPart > 0) {
display.print(15, 0, ALIGN_CENTER, FONT7, WHITE, "%d T %d h", rest.daysPart, rest.hoursPart);
} else if (rest.hoursPart > 0) {
display.print(15, 0, ALIGN_CENTER, FONT7, WHITE, "%2d:%02d:%02d", rest.hoursPart, rest.minutesPart, rest.secondsPart);
} else if (rest.minutesPart > 0) {
display.print(15, 0, ALIGN_CENTER, FONT7, WHITE, "%2d:%02d", rest.minutesPart, rest.secondsPart);
} else if (rest.secondsPart > 0) {
display.print(15, 0, ALIGN_CENTER, FONT7, WHITE, "%2d.%1d", rest.minutesPart, rest.secondsPart, rest.decisPart);
}
}
static void drawAnimation(const Display &display) {
// TODO
}
};
#endif

View File

@ -3,6 +3,8 @@
struct Rest { struct Rest {
bool negative;
uint64_t millisTotal; uint64_t millisTotal;
uint64_t decisTotal; uint64_t decisTotal;
@ -25,8 +27,9 @@ struct Rest {
uint32_t daysPart; uint32_t daysPart;
explicit Rest(const uint32_t millisTotal) explicit Rest(const int64_t _millisTotal)
: millisTotal(millisTotal), : negative(_millisTotal < 0),
millisTotal(negative ? -_millisTotal : _millisTotal),
decisTotal(millisTotal / 100), decisTotal(millisTotal / 100),
secondsTotal(decisTotal / 10), secondsTotal(decisTotal / 10),
minutesTotal(secondsTotal / 60), minutesTotal(secondsTotal / 60),
@ -56,6 +59,10 @@ struct Rest {
Serial.printf("%3d.%02d:%02d:%02d.%d\n", daysPart, hoursPart, minutesPart, secondsPart, decisPart); Serial.printf("%3d.%02d:%02d:%02d.%d\n", daysPart, hoursPart, minutesPart, secondsPart, decisPart);
} }
bool isPositive() const {
return !negative;
}
}; };
#endif #endif