summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruvok2025-07-13 20:01:23 +0200
committeruvok2025-07-13 20:01:23 +0200
commit6cef347445e220644c4af49429ed532cf2a5f609 (patch)
treefdcc890fc5e35a30c2cd1206ff6cf738061c084d /src
Add q&d badge project
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..3613e36
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,107 @@
+#include <Arduino.h>
+
+#define GxEPD2_DISPLAY_CLASS GxEPD2_BW
+
+#include <GxEPD2_BW.h>
+#include <GxEPD2_3C.h>
+#include <Fonts/FreeMonoBold9pt7b.h>
+#include <Fonts/FreeMonoBold24pt7b.h>
+#include <NimBLEDevice.h>
+
+NimBLEServer *server;
+// 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));
+// latger b/w
+GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(22, 21, 17, 16));
+
+unsigned long pressedTime = 0;
+unsigned long releasedTime = 0;
+#define BUTTON_PIN 0
+#define LONG_PRESS_TIME 3000
+#define SLEEP_TIME 10000
+NimBLEAdvertising *pAdvertising;
+
+void display_helloWorld();
+
+void setup()
+{
+ Serial.begin(115200);
+ Serial.println("Yes, it works!");
+
+ NimBLEDevice::init("Espadge");
+ server = NimBLEDevice::createServer();
+ NimBLEService *service = new NimBLEService("ca260000-b4bb-46b2-bd06-b7b7a61ea990");
+ auto c = service->createCharacteristic("ca260001-b4bb-46b2-bd06-b7b7a61ea990");
+ service->start();
+ c->setValue("1");
+
+ server->addService(service);
+
+ pAdvertising = NimBLEDevice::getAdvertising();
+ 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.");
+
+ // doesn't work as expected?
+ // gpio_wakeup_enable(GPIO_NUM_0, GPIO_INTR_LOW_LEVEL);
+ // esp_sleep_enable_gpio_wakeup();
+ // esp_light_sleep_start();
+}
+
+void loop()
+{
+ static int lastState = HIGH;
+ int buttonState = digitalRead(BUTTON_PIN);
+ if (lastState == HIGH && buttonState == LOW)
+ {
+ Serial.println("``\\__");
+ pressedTime = millis();
+ lastState = LOW;
+ }
+ else if (lastState == LOW && buttonState == HIGH)
+ {
+ lastState = HIGH;
+ Serial.println("__/``");
+ releasedTime = millis();
+ long pressDuration = releasedTime - pressedTime;
+
+ if (pressDuration > LONG_PRESS_TIME && !pAdvertising->isAdvertising())
+ {
+ Serial.println("Long press detected. Starting advertising...");
+ pAdvertising->start(10000);
+ }
+
+ // if (millis() - releasedTime > SLEEP_TIME && !pAdvertising->isAdvertising())
+ // {
+ // Serial.println("Go to sleep...");
+ // esp_light_sleep_start();
+ // }
+ };
+}
+
+void display_helloWorld()
+{
+ // display.clearScreen();
+ static const char HelloWorld[] = "Hello World!";
+ display.setRotation(1);
+ display.setFont(&FreeMonoBold24pt7b);
+ display.setTextColor(GxEPD_BLACK);
+ int16_t tbx, tby;
+ uint16_t tbw, tbh;
+ display.getTextBounds(HelloWorld, 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 y = ((display.height() - tbh) / 2) - tby;
+ display.setFullWindow();
+ display.firstPage();
+ do
+ {
+ display.fillScreen(GxEPD_YELLOW);
+ display.setCursor(x, y);
+ display.print(HelloWorld);
+ } while (display.nextPage());
+} \ No newline at end of file