This commit is contained in:
Patrick Haßel 2021-12-26 13:58:31 +01:00
parent a8d7392619
commit aad95e9292
2 changed files with 137 additions and 1 deletions

View File

@ -4,10 +4,12 @@
#include "display/Display.h" #include "display/Display.h"
#include "mode/Pong/Pong.h" #include "mode/Pong/Pong.h"
#include "mode/Test/Border.h" #include "mode/Test/Border.h"
#include "mode/Clock/Clock.h"
enum ModeId { enum ModeId {
NONE, NONE,
BORDER, BORDER,
CLOCK,
GAME_OF_LIFE_BLACK_WHITE, GAME_OF_LIFE_BLACK_WHITE,
GAME_OF_LIFE_WHITE_FADE, GAME_OF_LIFE_WHITE_FADE,
GAME_OF_LIFE_COLOR_FADE, GAME_OF_LIFE_COLOR_FADE,
@ -17,7 +19,7 @@ enum ModeId {
Display display(32, 8); Display display(32, 8);
ModeId newModeId = GAME_OF_LIFE_COLOR_FADE; ModeId newModeId = GAME_OF_LIFE_WHITE_FADE;
ModeId currentModeId = NONE; ModeId currentModeId = NONE;
@ -132,6 +134,9 @@ void loadNewMode() {
case BORDER: case BORDER:
mode = new Border(&display); mode = new Border(&display);
break; break;
case CLOCK:
mode = new Clock(&display);
break;
case GAME_OF_LIFE_BLACK_WHITE: case GAME_OF_LIFE_BLACK_WHITE:
mode = new GameOfLife(&display, BLACK_WHITE); mode = new GameOfLife(&display, BLACK_WHITE);
break; break;

View File

@ -3,8 +3,139 @@
#include "mode/Mode.h" #include "mode/Mode.h"
#define X true
#define _ false
class Clock : public Mode { class Clock : public Mode {
private:
bool SYMBOLS[11][35] = {
{
X, X, X,
X, _, X,
X, _, X,
X, _, X,
X, X, X,
},
{
_, _, X,
_, X, X,
_, _, X,
_, _, X,
_, _, X,
},
{
X, X, X,
_, _, X,
X, X, X,
X, _, _,
X, X, X,
},
{
X, X, X,
_, _, X,
_, X, X,
_, _, X,
X, X, X,
},
{
X, _, X,
X, _, X,
X, X, X,
_, _, X,
_, _, X,
},
{
X, X, X,
X, _, _,
X, X, X,
_, _, X,
X, X, X,
},
{
X, X, X,
X, _, _,
X, X, X,
X, _, X,
X, X, X,
},
{
X, X, X,
_, _, X,
_, X, _,
X, _, _,
X, _, _,
},
{
X, X, X,
X, _, X,
X, X, X,
X, _, X,
X, X, X,
},
{
X, X, X,
X, _, X,
X, X, X,
_, _, X,
X, X, X,
},
{
_, _, _,
_, X, _,
_, _, _,
_, X, _,
_, _, _,
},
};
public:
explicit Clock(Display *display) :
Mode(display) {
// nothing
}
~Clock() override = default;
const char *getName() override {
return "Clock";
}
void step(millis_t dt) override {
tm time{};
getLocalTime(&time);
display->clear();
uint8_t x = 0;
print(&x, time.tm_hour / 10);
x++;
print(&x, time.tm_hour % 10);
print(&x, 10);
print(&x, time.tm_min / 10);
x++;
print(&x, time.tm_min % 10);
print(&x, 10);
print(&x, time.tm_sec / 10);
x++;
print(&x, time.tm_sec % 10);
}
void print(uint8_t *pos, uint8_t index) {
if (index > 10) {
Serial.printf("Cannot print symbol #%u.", index);
return;
}
bool *symbolBit = SYMBOLS[index];
for (uint8_t y = 0; y < 5; ++y) {
for (uint8_t x = 0; x < 3; ++x) {
uint8_t value = *(symbolBit++) ? 255 : 0;
display->set(*pos + x, y, value, value, value);
}
}
*pos += 3;
}
}; };
#endif #endif