From ea342ab3c1565e36395b3ea96969e8d1371f062c Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 9 May 2026 11:15:09 +0200 Subject: Display default image on start it's a fucking pain in the head otherwise. --- src/display.cpp | 72 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/display.cpp b/src/display.cpp index 68f97b0..76939ce 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -11,6 +11,11 @@ #include "badge/config.h" #include "badge/util.h" +#include +#include +#include +#include + #if UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_219_YBW // HINT: Update the library code, set budy timeout to 30 or 60 seconds! // Small color @@ -52,6 +57,35 @@ static std::string displayed_text; static bool is_initial = true; static constexpr uint8_t rotation = 1; +#define IMAGE_DATA(name, text) \ + (ImageInfo) \ + { \ + name##_bits, name##_width, name##_height, text \ + } + +struct ImageInfo +{ + // I always thought making the struct const makes all members const, yet I still get warnings... + const char *bits; + const int width; + const int height; + const char *text; +}; + +constexpr std::array imgs{ +#include "./images.cfg" + +}; + +const int de::uvok::badge::image_count = imgs.size(); + +typedef enum +{ + DISPLAY_PREVIEW, + DISPLAY_FULL, + DISPLAY_QRCODE +} display_mode_t; + void de::uvok::badge::display_init() { LOG_F("Init display...\n"); @@ -71,30 +105,22 @@ void de::uvok::badge::display_init() qrc.setScale(2); qrc.getGenerator().setErrorCorrectionLevel(QRCodeECCLevel::Medium); + const auto uvok_pos = std::find_if( + // + imgs.begin(), + // + imgs.end(), + // + [](const ImageInfo &info) { + std::string_view s(info.text); + return s.find("uvok") != std::string::npos; + }); + if (uvok_pos < imgs.end()) + { + display_direct(uvok_pos - imgs.begin()); + } } -#define IMAGE_DATA(name, text) {name##_bits, name##_width, name##_height, text} - -const struct -{ - // I always thought making the struct const makes all membery const, yet I still get warnings... - const char *bits; - const int width; - const int height; - const char *text; -} imgs[] = { -#include "./images.cfg" -}; - -const int de::uvok::badge::image_count = (ARRAY_LENGTH(imgs)); - -typedef enum -{ - DISPLAY_PREVIEW, - DISPLAY_FULL, - DISPLAY_QRCODE -} display_mode_t; - static void displayQRCode() { do @@ -189,7 +215,7 @@ void de::uvok::badge::display_direct(uint8_t num) displayDo(DISPLAY_FULL); } -void de::uvok::badge::display_text(const std::string& text) +void de::uvok::badge::display_text(const std::string &text) { displayed_text = text; displayDo(DISPLAY_QRCODE); -- cgit v1.2.3