diff options
| -rw-r--r-- | include/badge/display.h | 4 | ||||
| -rw-r--r-- | src/display.cpp | 72 |
2 files changed, 51 insertions, 25 deletions
diff --git a/include/badge/display.h b/include/badge/display.h index d1053f2..aa04b4f 100644 --- a/include/badge/display.h +++ b/include/badge/display.h @@ -2,7 +2,7 @@ #include "indicator.h" #include <stdint.h> -#include <string> +#include <string> namespace de::uvok::badge { @@ -14,6 +14,6 @@ namespace de::uvok::badge uint8_t display_prev(void); uint8_t display_refresh(void); void display_direct(uint8_t num); - void display_text(const std::string& text); + void display_text(const std::string &text); void display_indicator(DisplayIndicator); } // namespace de::uvok::badge 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 <algorithm> +#include <array> +#include <iterator> +#include <string_view> + #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); |
