46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#ifndef CLOCK_H
|
|
#define CLOCK_H
|
|
|
|
#include "mode/Mode.h"
|
|
|
|
class Clock : public Mode<Clock> {
|
|
|
|
public:
|
|
|
|
explicit Clock(Display *display) :
|
|
Mode(display) {
|
|
// nothing
|
|
}
|
|
|
|
~Clock() override = default;
|
|
|
|
const char *getName() override {
|
|
return "Clock";
|
|
}
|
|
|
|
void doStep(microseconds_t dt) override {
|
|
tm info{};
|
|
time_t now;
|
|
time(&now);
|
|
localtime_r(&now, &info);
|
|
bool ok = info.tm_year >= (2023 - 1900);
|
|
|
|
display->clear();
|
|
uint8_t x = 2;
|
|
x += display->print(x, 1, ok ? info.tm_hour / 10 : 13, WHITE);
|
|
x++;
|
|
x += display->print(x, 1, ok ? info.tm_hour % 10 : 13, WHITE);
|
|
x += display->print(x, 1, 10, WHITE);
|
|
x += display->print(x, 1, ok ? info.tm_min / 10 : 13, WHITE);
|
|
x++;
|
|
x += display->print(x, 1, ok ? info.tm_min % 10 : 13, WHITE);
|
|
x += display->print(x, 1, 10, WHITE);
|
|
x += display->print(x, 1, ok ? info.tm_sec / 10 : 13, WHITE);
|
|
x++;
|
|
x += display->print(x, 1, ok ? info.tm_sec % 10 : 13, WHITE);
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|