diff options
author | uvok | 2025-07-19 19:15:42 +0200 |
---|---|---|
committer | uvok | 2025-07-19 19:15:42 +0200 |
commit | 12f19e6ac90513038d71a1e9018e8b40f8abfc68 (patch) | |
tree | 38e44421de9402be67ad081c9d9f277043e33ba9 /src | |
parent | 356ff1961c1341c4d6b863b90b9a4e06bef44329 (diff) |
Implement preview mode
Diffstat (limited to 'src')
-rw-r--r-- | src/display.cpp | 39 | ||||
-rw-r--r-- | src/gpio.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 1 |
3 files changed, 28 insertions, 13 deletions
diff --git a/src/display.cpp b/src/display.cpp index 1cb270d..f115fd1 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -32,9 +32,9 @@ GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(45, 46, static uint8_t displayed = 0; -#include "hungry.c" #include "chleepy.c" #include "hug.c" +#include "hungry.c" #include "uvok.c" void de::uvok::badge::display_init(void) @@ -97,14 +97,14 @@ const struct const char *text; } imgs[] = {IMAGE_DATA_T(chleepy, "sleepy"), IMAGE_DATA(hungry), IMAGE_DATA_T(hug, "cuddly"), IMAGE_DATA(uvok)}; -#define NUM_IMGS (sizeof(imgs) / sizeof(imgs[0])) +const int de::uvok::badge::image_count = (sizeof(imgs) / sizeof(imgs[0])); -static void displayDo(void) +typedef enum { DISPLAY_PREVIEW, DISPLAY_FULL} display_mode_t; +static void displayDo(display_mode_t preview) { Serial.printf("Print image %d\n", displayed); - const char *strings[] = {"sleepy", "hungry"}; - display.setRotation(1); + display.setRotation(3); display.setTextColor(GxEPD_BLACK); display.setFont(&FreeMonoBold9pt7b); @@ -122,8 +122,18 @@ static void displayDo(void) display.firstPage(); do { - display.drawXBitmap(0, 0, (unsigned char *)imgs[displayed].bits, imgs[displayed].width, imgs[displayed].height, - GxEPD_BLACK); + if (!preview) + { + display.setFullWindow(); + display.drawXBitmap(0, 0, (unsigned char *)imgs[displayed].bits, imgs[displayed].width, + imgs[displayed].height, GxEPD_BLACK); + } + else + { + display.setPartialWindow(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, + tbh + 2 * TEXT_BORDER); + } + display.fillRect(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, tbh + 2 * TEXT_BORDER, GxEPD_WHITE); display.setCursor(x, y); @@ -134,15 +144,20 @@ static void displayDo(void) void de::uvok::badge::display_prev(void) { displayed--; - if (displayed >= NUM_IMGS) - displayed = NUM_IMGS - 1; - displayDo(); + if (displayed >= image_count) + displayed = image_count - 1; + displayDo(DISPLAY_PREVIEW); } void de::uvok::badge::display_next(void) { - displayed = (displayed + 1) % NUM_IMGS; - displayDo(); + displayed = (displayed + 1) % image_count; + displayDo(DISPLAY_PREVIEW); +} + +void de::uvok::badge::display_refresh(void) +{ + displayDo(DISPLAY_FULL); } /* diff --git a/src/gpio.cpp b/src/gpio.cpp index a419d99..6746a48 100644 --- a/src/gpio.cpp +++ b/src/gpio.cpp @@ -11,7 +11,6 @@ // Elecrow #define EXIT_KEY 1 #define HOME_KEY 2 -#define OK_KEY 5 #endif #define GPIO_STACK 2048 diff --git a/src/main.cpp b/src/main.cpp index d4b9fd9..75c4d8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,6 +60,7 @@ void loop() { if (pressDuration == NEXT_KEY) de::uvok::badge::display_next(); if (pressDuration == PRV_KEY) de::uvok::badge::display_prev(); + if (pressDuration == OK_KEY) de::uvok::badge::display_refresh(); } else if (pressDuration > PRESS_TIME_BLE_ADV) { |