add double buffer, better draw, and last seen removal

This commit is contained in:
2026-11-15 16:05:55 -05:00
parent 05dd732786
commit 323056c95c
3 changed files with 71 additions and 28 deletions
+22 -16
View File
@@ -33,7 +33,8 @@ private:
const char *bdf_6x12 = "./external/rpi-rgb-led-matrix/fonts/6x12.bdf";
rgb_matrix::Font font;
RGBMatrix *canvas;
RGBMatrix *canvas = nullptr;
FrameCanvas *offscreen = nullptr;
std::vector<Text> display_text;
Text flight_operator = {"", 3, 17, 0, WHITE};
@@ -60,7 +61,8 @@ private:
std::string flight_number;
int i = 0;
while (!std::isdigit(callsign[i])) {
while (i < static_cast<int>(callsign.size()) &&
!std::isdigit(static_cast<unsigned char>(callsign[i]))) {
i++;
}
@@ -88,6 +90,8 @@ public:
throw std::runtime_error("Canvas creation failed");
}
offscreen = canvas->CreateFrameCanvas();
display_text = {
{"ALT", 24, 3, 0, WHITE},
{"SPD", 24, 10, 0, WHITE},
@@ -101,42 +105,44 @@ public:
~LEDMatrix() { delete canvas; }
void draw_display_text() {
offscreen->Clear();
for (Text t : display_text) {
rgb_matrix::DrawText(canvas, font, t.x, t.y + font.baseline(), t.color,
rgb_matrix::DrawText(offscreen, font, t.x, t.y + font.baseline(), t.color,
NULL, t.text.c_str(), t.spacing);
}
rgb_matrix::DrawText(canvas, font, flight_number.x, flight_number.y + font.baseline(), flight_number.color,
rgb_matrix::DrawText(offscreen, font, flight_number.x, flight_number.y + font.baseline(), flight_number.color,
NULL, flight_number.text.c_str(), flight_number.spacing);
rgb_matrix::DrawText(canvas, font, flight_operator.x, flight_operator.y + font.baseline(), flight_operator.color,
rgb_matrix::DrawText(offscreen, font, flight_operator.x, flight_operator.y + font.baseline(), flight_operator.color,
NULL, flight_operator.text.c_str(), flight_operator.spacing);
rgb_matrix::DrawText(canvas, font, altitude.x, altitude.y + font.baseline(), altitude.color,
rgb_matrix::DrawText(offscreen, font, altitude.x, altitude.y + font.baseline(), altitude.color,
NULL, altitude.text.c_str(), altitude.spacing);
rgb_matrix::DrawText(canvas, font, speed.x, speed.y + font.baseline(), speed.color,
rgb_matrix::DrawText(offscreen, font, speed.x, speed.y + font.baseline(), speed.color,
NULL, speed.text.c_str(), speed.spacing);
rgb_matrix::DrawText(canvas, font, track.x, track.y + font.baseline(), track.color,
rgb_matrix::DrawText(offscreen, font, track.x, track.y + font.baseline(), track.color,
NULL, track.text.c_str(), track.spacing);
rgb_matrix::DrawText(canvas, font, vertical_speed.x, vertical_speed.y + font.baseline(), vertical_speed.color,
rgb_matrix::DrawText(offscreen, font, vertical_speed.x, vertical_speed.y + font.baseline(), vertical_speed.color,
NULL, vertical_speed.text.c_str(), vertical_speed.spacing);
offscreen = canvas->SwapOnVSync(offscreen);
}
void draw() {
if (!current_aircraft->callsign->empty()) {
if (current_aircraft->callsign && !current_aircraft->callsign->empty()) {
std::string current_callsign = *current_aircraft->callsign;
auto [op, num] = get_callsign_structure(current_callsign);
// if general November reg
if (op == "N") {
flight_operator.text = "GA";
flight_number.text = num.substr(num.length(), 4);
flight_number.text = num.substr(0, 4);
// if other flight number
} else {
flight_operator.text = op;
flight_number.text = num.substr(num.length(), 4);
flight_number.text = num.substr(0, 4);
}
}
if (*current_aircraft->altitude) {
if (current_aircraft->altitude) {
int current_altitude = *current_aircraft->altitude;
// if over 10k feet show flight level
if (current_altitude >= 10'000) {
@@ -148,19 +154,19 @@ public:
}
}
if (*current_aircraft->ground_speed) {
if (current_aircraft->ground_speed) {
int current_ground_speed = *current_aircraft->ground_speed;
speed.text = std::to_string(current_ground_speed);
}
if (*current_aircraft->track) {
if (current_aircraft->track) {
int current_track = *current_aircraft->track;
track.text = std::to_string(current_track);
}
if (*current_aircraft->vertical_rate) {
if (current_aircraft->vertical_rate) {
int current_vertical_speed = *current_aircraft->vertical_rate;
vertical_speed.text = std::to_string(current_vertical_speed);