summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruvok2025-07-17 21:05:23 +0200
committeruvok2025-07-17 21:05:23 +0200
commit3f9e0e97aa0491d0143642f8302dd38afb42f479 (patch)
treeb4c023148cbb2fd1f6208be3a11ec362b1fbec39 /src
parentd7f81ae55d0f7fd1ec7739bc326fdfa3325b12ce (diff)
Split display config
Diffstat (limited to 'src')
-rw-r--r--src/display.cpp81
-rw-r--r--src/main.cpp80
2 files changed, 84 insertions, 77 deletions
diff --git a/src/display.cpp b/src/display.cpp
new file mode 100644
index 0000000..cde438f
--- /dev/null
+++ b/src/display.cpp
@@ -0,0 +1,81 @@
+#include "display.h"
+
+#include <Fonts/FreeMonoBold18pt7b.h>
+#include <Fonts/FreeMonoBold9pt7b.h>
+// #include <GxEPD2_3C.h>
+#include <GxEPD2_BW.h>
+
+#include "badge_config.h"
+
+#if UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_219_YBW
+// HINT: Update the library code, set budy timeout to 30 or 60 seconds!
+// Small color
+GxEPD2_3C<GxEPD2_213_Z19c, GxEPD2_213_Z19c::HEIGHT> display(GxEPD2_213_Z19c(22, 21, 17, 16));
+#elif UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_290_BW
+// larger b/w
+// or T5
+// GxEPD2_BW<GxEPD2_290_T5D, GxEPD2_290_T5D::HEIGHT> display(GxEPD2_290_T5D(22, 21, 17, 16));
+GxEPD2_BW<GxEPD2_290_M06, GxEPD2_290_M06::HEIGHT> display(GxEPD2_290_M06(22, 21, 17, 16));
+#elif UVOK_EPAP_DISPLAY == DISPLAY_ELECROW_290_BW
+/*
+#define SCK 12
+#define MOSI 11
+#define RES 47
+#define DC 46
+#define CS 45
+#define BUSY 48
+*/
+GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(45, 46, 47, 48));
+#else
+#error "define display"
+#endif
+
+void de::uvok::badge::display_init(void)
+{
+ Serial.println("Init display...");
+
+#if UVOK_EPAP_DISPLAY == DISPLAY_ELECROW_290_BW
+ // Turn on once, let controller handle the rest, lest I want to do re-init...
+ pinMode(7, OUTPUT); // Set pin 7 as output mode
+ digitalWrite(7, HIGH); // Set pin 7 to high level to turn on the screen power
+ display.init(115200, true);
+#else
+ display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
+#endif
+
+ display.hibernate();
+ Serial.println("Display done.");
+}
+
+#include "chee.c"
+
+void de::uvok::badge::display_demo(void)
+{
+#define TEXT_BORDER 10
+ // display.clearScreen();
+ static const char s_hungry[] = "hungry";
+ display.setRotation(1);
+ display.setTextColor(GxEPD_BLACK);
+ int16_t tbx, tby;
+ uint16_t tbw, tbh;
+ display.setFont(&FreeMonoBold9pt7b);
+ display.getTextBounds(s_hungry, 0, 0, &tbx, &tby, &tbw, &tbh);
+ // center the bounding box by transposition of the origin:
+ uint16_t x = display.width() - tbw - TEXT_BORDER - tbx;
+ uint16_t y = ((display.height() - tbh) / 2) - tby;
+ display.setFullWindow();
+ display.firstPage();
+ do
+ {
+ display.drawXBitmap(0, 0, chee_bits, chee_width, chee_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);
+
+ display.setCursor(x, y);
+ display.print(s_hungry);
+ } while (display.nextPage());
+
+ display.hibernate();
+#undef TEXT_BORDER
+}
diff --git a/src/main.cpp b/src/main.cpp
index 0f90d96..dbb929b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,11 +1,5 @@
#include <Arduino.h>
-#define GxEPD2_DISPLAY_CLASS GxEPD2_BW
-
-#include <Fonts/FreeMonoBold18pt7b.h>
-#include <Fonts/FreeMonoBold9pt7b.h>
-#include <GxEPD2_3C.h>
-#include <GxEPD2_BW.h>
#include <NimBLEDevice.h>
#include <WiFi.h>
@@ -14,6 +8,7 @@
#include <WebServer.h>
#include "badge_config.h"
+#include "display.h"
#if defined(BADGE_SSID_NAME) && defined(BADGE_SSID_PASS)
#define BADGE_USE_WIFI 1
@@ -22,28 +17,6 @@
#endif
NimBLEServer *server;
-#if UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_219_YBW
-// HINT: Update the library code, set budy timeout to 30 or 60 seconds!
-// Small color
-GxEPD2_3C<GxEPD2_213_Z19c, GxEPD2_213_Z19c::HEIGHT> display(GxEPD2_213_Z19c(22, 21, 17, 16));
-#elif UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_290_BW
-// larger b/w
-// or T5
-// GxEPD2_BW<GxEPD2_290_T5D, GxEPD2_290_T5D::HEIGHT> display(GxEPD2_290_T5D(22, 21, 17, 16));
-GxEPD2_BW<GxEPD2_290_M06, GxEPD2_290_M06::HEIGHT> display(GxEPD2_290_M06(22, 21, 17, 16));
-#elif UVOK_EPAP_DISPLAY == DISPLAY_ELECROW_290_BW
-/*
-#define SCK 12
-#define MOSI 11
-#define RES 47
-#define DC 46
-#define CS 45
-#define BUSY 48
-*/
-GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(45, 46, 47, 48));
-#else
-#error "define display"
-#endif
unsigned long pressedTime = 0;
unsigned long releasedTime = 0;
@@ -56,8 +29,6 @@ NimBLEAdvertising *pAdvertising;
WebServer httpServer(80);
HTTPUpdateServer httpUpdater;
-void display_helloWorld();
-
void setup()
{
Serial.begin(115200);
@@ -74,19 +45,7 @@ void setup()
pAdvertising = NimBLEDevice::getAdvertising();
pAdvertising->setName("NimBLE");
- Serial.println("Init display...");
-
-#if UVOK_EPAP_DISPLAY == DISPLAY_ELECROW_290_BW
- // Turn on once, let controller handle the rest, lest I want to do re-init...
- pinMode(7, OUTPUT); // Set pin 7 as output mode
- digitalWrite(7, HIGH); // Set pin 7 to high level to turn on the screen power
- display.init(115200, true);
-#else
- display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
-#endif
-
- display.hibernate();
- Serial.println("Display done.");
+ de::uvok::badge::display_init();
#if BADGE_USE_WIFI
WiFi.begin(BADGE_SSID_NAME, BADGE_SSID_PASS);
@@ -139,7 +98,7 @@ void loop()
else if (pressDuration > PRESS_TIME_DRAW)
{
Serial.println("Drawing...");
- display_helloWorld();
+ de::uvok::badge::display_demo();
}
// if (millis() - releasedTime > SLEEP_TIME && !pAdvertising->isAdvertising())
@@ -148,36 +107,3 @@ void loop()
// esp_light_sleep_start();
// }
}
-
-#include "chee.c"
-
-void display_helloWorld()
-{
-#define TEXT_BORDER 10
- // display.clearScreen();
- static const char s_hungry[] = "hungry";
- display.setRotation(1);
- display.setTextColor(GxEPD_BLACK);
- int16_t tbx, tby;
- uint16_t tbw, tbh;
- display.setFont(&FreeMonoBold9pt7b);
- display.getTextBounds(s_hungry, 0, 0, &tbx, &tby, &tbw, &tbh);
- // center the bounding box by transposition of the origin:
- uint16_t x = display.width() - tbw - TEXT_BORDER - tbx;
- uint16_t y = ((display.height() - tbh) / 2) - tby;
- display.setFullWindow();
- display.firstPage();
- do
- {
- display.drawXBitmap(0, 0, chee_bits, chee_width, chee_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);
-
- display.setCursor(x, y);
- display.print(s_hungry);
- } while (display.nextPage());
-
- display.hibernate();
-#undef TEXT_BORDER
-}