diff options
author | uvok | 2025-07-15 20:55:48 +0200 |
---|---|---|
committer | uvok | 2025-07-15 20:55:48 +0200 |
commit | 89525668c3c8cf32b34e215ad740153c61e4c067 (patch) | |
tree | 479f6621b7f2d897d4c801b6d389f3d6179f082a /src | |
parent | 134c17cb2363859034b80a46a99f4c2e9870a567 (diff) |
Draw on button push
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp index cd0739c..838fde0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,16 @@ #define GxEPD2_DISPLAY_CLASS GxEPD2_BW -#include <GxEPD2_BW.h> -#include <GxEPD2_3C.h> -#include <Fonts/FreeMonoBold9pt7b.h> #include <Fonts/FreeMonoBold18pt7b.h> +#include <Fonts/FreeMonoBold9pt7b.h> +#include <GxEPD2_3C.h> +#include <GxEPD2_BW.h> #include <NimBLEDevice.h> #include <WiFi.h> // #include <ArduinoOTA.h> -#include <WebServer.h> #include <HTTPUpdateServer.h> +#include <WebServer.h> #include "badge_config.h" @@ -38,7 +38,8 @@ GxEPD2_BW<GxEPD2_290_M06, GxEPD2_290_M06::HEIGHT> display(GxEPD2_290_M06(22, 21, unsigned long pressedTime = 0; unsigned long releasedTime = 0; #define BUTTON_PIN 0 -#define LONG_PRESS_TIME 3000 +#define PRESS_TIME_DRAW 1000 +#define PRESS_TIME_BLE_ADV 3000 #define SLEEP_TIME 10000 NimBLEAdvertising *pAdvertising; @@ -65,7 +66,6 @@ void setup() pAdvertising->setName("NimBLE"); Serial.println("Init display..."); display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse - display_helloWorld(); display.hibernate(); Serial.println("Display done."); @@ -94,6 +94,7 @@ void loop() static int lastState = HIGH; int buttonState = digitalRead(BUTTON_PIN); + long pressDuration = 0; if (lastState == HIGH && buttonState == LOW) { Serial.println("``\\__"); @@ -105,26 +106,35 @@ void loop() lastState = HIGH; Serial.println("__/``"); releasedTime = millis(); - long pressDuration = releasedTime - pressedTime; - if (pressDuration > LONG_PRESS_TIME && !pAdvertising->isAdvertising()) + pressDuration = releasedTime - pressedTime; + }; + if (pressDuration > PRESS_TIME_BLE_ADV) + { + if (!pAdvertising->isAdvertising()) { Serial.println("Long press detected. Starting advertising..."); pAdvertising->start(10000); } + } + else if (pressDuration > PRESS_TIME_DRAW) + { + Serial.println("Drawing..."); + display_helloWorld(); + } - // if (millis() - releasedTime > SLEEP_TIME && !pAdvertising->isAdvertising()) - // { - // Serial.println("Go to sleep..."); - // esp_light_sleep_start(); - // } - }; + // if (millis() - releasedTime > SLEEP_TIME && !pAdvertising->isAdvertising()) + // { + // Serial.println("Go to sleep..."); + // 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); @@ -134,7 +144,7 @@ void display_helloWorld() 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) / 2) - tbx; + uint16_t x = display.width() - tbw - TEXT_BORDER - tbx; uint16_t y = ((display.height() - tbh) / 2) - tby; display.setFullWindow(); display.firstPage(); @@ -142,9 +152,13 @@ void display_helloWorld() { 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, tby, tbw, tbh, GxEPD_WHITE); + 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 } |