summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruvok2025-07-14 19:15:10 +0200
committeruvok2025-07-14 19:15:10 +0200
commit66ecb693177f3a209a0ddd7c7629c5ed9e4f673f (patch)
treeb994bfb1be7e88405d3cf7c920239d9cb455cb20 /src
parentfc2453884805226016538a174053ed24f22b4677 (diff)
Add badge config header, enable ota
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp129
1 files changed, 79 insertions, 50 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 3613e36..83321a5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,12 +8,30 @@
#include <Fonts/FreeMonoBold24pt7b.h>
#include <NimBLEDevice.h>
+#include <WiFi.h>
+#include <ArduinoOTA.h>
+
+#include "badge_config.h"
+
+#if defined(BADGE_SSID_NAME) && defined(BADGE_SSID_PASS)
+#define BADGE_USE_WIFI 1
+#else
+#define BADGE_USE_WIFI 0
+#endif
+
NimBLEServer *server;
+#if UVOK_EPAP_DISPLAY == 219
// 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));
+GxEPD2_3C<GxEPD2_213_Z19c, GxEPD2_213_Z19c::HEIGHT> display(GxEPD2_213_Z19c(22, 21, 17, 16));
+#elif UVOK_EPAP_DISPLAY == 290
+// 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));
+#else
+#error "define display"
+#endif
unsigned long pressedTime = 0;
unsigned long releasedTime = 0;
@@ -26,61 +44,72 @@ 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();
+ 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.");
+
+#if BADGE_USE_WIFI
+ WiFi.begin(BADGE_SSID_NAME, BADGE_SSID_PASS);
+ while (WiFi.status() != WL_CONNECTED)
+ delay(500);
+ ArduinoOTA.begin();
+#endif
+
+ // 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 BADGE_USE_WIFI
+ ArduinoOTA.handle();
+#endif
- if (pressDuration > LONG_PRESS_TIME && !pAdvertising->isAdvertising())
+static int lastState = HIGH;
+ int buttonState = digitalRead(BUTTON_PIN);
+ if (lastState == HIGH && buttonState == LOW)
{
- Serial.println("Long press detected. Starting advertising...");
- pAdvertising->start(10000);
+ 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();
- // }
- };
+ // if (millis() - releasedTime > SLEEP_TIME && !pAdvertising->isAdvertising())
+ // {
+ // Serial.println("Go to sleep...");
+ // esp_light_sleep_start();
+ // }
+ };
}
void display_helloWorld()