add logo handling
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "TrackedAircraft.h"
|
||||
#include "assets/logos/logos.h"
|
||||
#include "external/rpi-rgb-led-matrix/include/graphics.h"
|
||||
#include "external/rpi-rgb-led-matrix/include/led-matrix.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <getopt.h>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
@@ -44,8 +46,48 @@ private:
|
||||
Text track = {"DEG", 41, 17, 0, WHITE};
|
||||
Text vertical_speed = {"VS", 41, 24, 0, WHITE};
|
||||
|
||||
const char *ga_logo_path = "";
|
||||
const char *ufo_logo_path = "";
|
||||
std::vector<uint8_t> ga_logo;
|
||||
std::vector<uint8_t> ufo_logo;
|
||||
const uint8_t *current_logo = nullptr;
|
||||
|
||||
TrackedAircraft *current_aircraft;
|
||||
|
||||
static std::vector<uint8_t> load_logo(const char *path) {
|
||||
std::vector<uint8_t> data;
|
||||
if (!path || !*path) {
|
||||
return data;
|
||||
}
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
data.assign(std::istreambuf_iterator<char>(f), {});
|
||||
if (data.size() != LOGO_SIZE * LOGO_SIZE * 3) {
|
||||
data.clear();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static const uint8_t *find_logo(const std::string &code) {
|
||||
for (int i = 0; i < LOGO_COUNT; i++) {
|
||||
if (code == LOGOS[i].code) {
|
||||
return LOGOS[i].rgb;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void draw_logo(int x, int y) {
|
||||
if (!current_logo) {
|
||||
return;
|
||||
}
|
||||
for (int row = 0; row < LOGO_SIZE; row++) {
|
||||
for (int col = 0; col < LOGO_SIZE; col++) {
|
||||
const uint8_t *px = current_logo + (row * LOGO_SIZE + col) * 3;
|
||||
offscreen->SetPixel(x + col, y + row, px[0], px[1], px[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool parseColor(Color *c, const char *str) {
|
||||
return sscanf(str, "%hhu,%hhu,%hhu", &c->r, &c->g, &c->b) == 3;
|
||||
}
|
||||
@@ -99,6 +141,9 @@ public:
|
||||
{"FPM", 24, 24, 0, WHITE},
|
||||
};
|
||||
|
||||
ga_logo = load_logo(ga_logo_path);
|
||||
ufo_logo = load_logo(ufo_logo_path);
|
||||
|
||||
current_aircraft = t;
|
||||
}
|
||||
|
||||
@@ -106,6 +151,7 @@ public:
|
||||
|
||||
void draw_display_text() {
|
||||
offscreen->Clear();
|
||||
draw_logo(1, 1);
|
||||
for (Text t : display_text) {
|
||||
rgb_matrix::DrawText(offscreen, font, t.x, t.y + font.baseline(), t.color,
|
||||
NULL, t.text.c_str(), t.spacing);
|
||||
@@ -134,11 +180,16 @@ public:
|
||||
if (op == "N") {
|
||||
flight_operator.text = "GA";
|
||||
flight_number.text = num.substr(0, 4);
|
||||
current_logo = ga_logo.empty() ? nullptr : ga_logo.data();
|
||||
|
||||
// if other flight number
|
||||
} else {
|
||||
flight_operator.text = op;
|
||||
flight_number.text = num.substr(0, 4);
|
||||
current_logo = find_logo(op);
|
||||
if (!current_logo && !ufo_logo.empty()) {
|
||||
current_logo = ufo_logo.data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user