summaryrefslogtreecommitdiff
path: root/src/display.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/display.cpp')
-rw-r--r--src/display.cpp79
1 files changed, 76 insertions, 3 deletions
diff --git a/src/display.cpp b/src/display.cpp
index 54da2db..c69fbb0 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -30,6 +30,12 @@ GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(45, 46,
#error "define display"
#endif
+static uint8_t displayed = 0;
+
+#include "hungry.c"
+#include "chleepy.c"
+#include "hug.c"
+
void de::uvok::badge::display_init(void)
{
Serial.println("Init display...");
@@ -47,8 +53,6 @@ void de::uvok::badge::display_init(void)
Serial.println("Display done.");
}
-#include "chee.c"
-
void de::uvok::badge::display_demo(void)
{
#define TEXT_BORDER 10
@@ -67,7 +71,7 @@ void de::uvok::badge::display_demo(void)
display.firstPage();
do
{
- display.drawXBitmap(0, 0, chee_bits, chee_width, chee_height, GxEPD_BLACK);
+ display.drawXBitmap(0, 0, (unsigned char *)chleepy_bits, chleepy_width, chleepy_height, GxEPD_BLACK);
display.getTextBounds(s_hungry, x, y, &tbx, &tby, &tbw, &tbh);
display.fillRect(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, tbh + 2 * TEXT_BORDER,
GxEPD_WHITE);
@@ -79,3 +83,72 @@ void de::uvok::badge::display_demo(void)
display.hibernate();
#undef TEXT_BORDER
}
+
+#define IMAGE_DATA_T(name, text) {name##_bits, name##_width, name##_height, text}
+#define IMAGE_DATA(name) {name##_bits, name##_width, name##_height, #name}
+
+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[] = {IMAGE_DATA_T(chleepy, "sleepy"), IMAGE_DATA(hungry), IMAGE_DATA_T(hug, "cuddly")};
+
+#define NUM_IMGS (sizeof(imgs) / sizeof(imgs[0]))
+
+static void displayDo(void)
+{
+ Serial.printf("Print image %d\n", displayed);
+ const char *strings[] = {"sleepy", "hungry"};
+
+ display.setRotation(1);
+ display.setTextColor(GxEPD_BLACK);
+ display.setFont(&FreeMonoBold9pt7b);
+
+ const char *display_text = imgs[displayed].text;
+ int16_t tbx, tby;
+ uint16_t tbw, tbh;
+ display.getTextBounds(display_text, 0, 0, &tbx, &tby, &tbw, &tbh);
+
+ constexpr int TEXT_BORDER = 10;
+ const uint16_t x = display.width() - tbw - TEXT_BORDER - tbx;
+ const uint16_t y = ((display.height() - tbh) / 2) - tby;
+ // re-calculate right-centered
+ display.getTextBounds(display_text, x, y, &tbx, &tby, &tbw, &tbh);
+
+ display.firstPage();
+ do
+ {
+ display.drawXBitmap(0, 0, (unsigned char *)imgs[displayed].bits, imgs[displayed].width, imgs[displayed].height,
+ GxEPD_BLACK);
+ display.fillRect(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, tbh + 2 * TEXT_BORDER,
+ GxEPD_WHITE);
+ display.setCursor(x, y);
+ display.print(display_text);
+ } while (display.nextPage());
+}
+
+void de::uvok::badge::display_prev(void)
+{
+ displayed--;
+ if (displayed >= NUM_IMGS)
+ displayed = NUM_IMGS - 1;
+ displayDo();
+}
+
+void de::uvok::badge::display_next(void)
+{
+ displayed = (displayed + 1) % NUM_IMGS;
+ displayDo();
+}
+
+/*
+// ->
+#include "output_h4x4a.xbm"
+#include "output_o8x8.xbm"
+
+
+
+*/ \ No newline at end of file