diff --git a/LEDMatrix.cpp b/LEDMatrix.cpp index 7d5154c..7111249 100644 --- a/LEDMatrix.cpp +++ b/LEDMatrix.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,22 @@ private: } } + static constexpr int DAY_BRIGHTNESS = 50; + static constexpr int NIGHT_BRIGHTNESS = 10; + static constexpr int NIGHT_START_HOUR = 22; + static constexpr int NIGHT_END_HOUR = 9; + + void update_brightness() { + time_t now = time(nullptr); + struct tm local; + localtime_r(&now, &local); + bool night = local.tm_hour >= NIGHT_START_HOUR || local.tm_hour < NIGHT_END_HOUR; + uint8_t target = night ? NIGHT_BRIGHTNESS : DAY_BRIGHTNESS; + if (canvas->brightness() != target) { + canvas->SetBrightness(target); + } + } + static bool parseColor(Color *c, const char *str) { return sscanf(str, "%hhu,%hhu,%hhu", &c->r, &c->g, &c->b) == 3; } @@ -102,7 +119,7 @@ public: LEDMatrix(TrackedAircraft *t) { matrix_options.cols = 64; - matrix_options.brightness = 50; + matrix_options.brightness = DAY_BRIGHTNESS; runtime_opt.gpio_slowdown = 2; // load font from bdf file @@ -131,6 +148,7 @@ public: ~LEDMatrix() { delete canvas; } void draw_display_text() { + update_brightness(); offscreen->Clear(); draw_logo(1, 1); for (Text t : display_text) {