modify brightness to lower during nighttime

This commit is contained in:
2026-11-15 18:02:59 -05:00
parent b1db99ee8b
commit cb87b8ccc6
+19 -1
View File
@@ -10,6 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <ctime>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
@@ -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) { static bool parseColor(Color *c, const char *str) {
return sscanf(str, "%hhu,%hhu,%hhu", &c->r, &c->g, &c->b) == 3; return sscanf(str, "%hhu,%hhu,%hhu", &c->r, &c->g, &c->b) == 3;
} }
@@ -102,7 +119,7 @@ public:
LEDMatrix(TrackedAircraft *t) { LEDMatrix(TrackedAircraft *t) {
matrix_options.cols = 64; matrix_options.cols = 64;
matrix_options.brightness = 50; matrix_options.brightness = DAY_BRIGHTNESS;
runtime_opt.gpio_slowdown = 2; runtime_opt.gpio_slowdown = 2;
// load font from bdf file // load font from bdf file
@@ -131,6 +148,7 @@ public:
~LEDMatrix() { delete canvas; } ~LEDMatrix() { delete canvas; }
void draw_display_text() { void draw_display_text() {
update_brightness();
offscreen->Clear(); offscreen->Clear();
draw_logo(1, 1); draw_logo(1, 1);
for (Text t : display_text) { for (Text t : display_text) {