diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | include/badge_config.h.template | 5 | ||||
-rw-r--r-- | ota_part.csv | 5 | ||||
-rw-r--r-- | platformio.ini | 12 | ||||
-rw-r--r-- | src/main.cpp | 129 |
5 files changed, 96 insertions, 56 deletions
@@ -3,3 +3,4 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +include/badge_config.h diff --git a/include/badge_config.h.template b/include/badge_config.h.template new file mode 100644 index 0000000..ec32e05 --- /dev/null +++ b/include/badge_config.h.template @@ -0,0 +1,5 @@ +#pragma once + +#define UVOK_EPAP_DISPLAY 290 +#define BADGE_SSID_NAME +#define BADGE_SSID_PASS
\ No newline at end of file diff --git a/ota_part.csv b/ota_part.csv new file mode 100644 index 0000000..7dfecdc --- /dev/null +++ b/ota_part.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x4000, +otadata, data, ota, 0xd000, 0x2000, +app0, app, ota_0, 0x10000, 0x1E0000, +app1, app, ota_1, 0x1F0000, 0x1E0000, diff --git a/platformio.ini b/platformio.ini index 92c0256..8d623a6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,16 +13,16 @@ platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 -board_build.partitions = min_part.csv +board_build.partitions = ota_part.csv lib_deps = zinggjm/GxEPD2@^1.6.4 h2zero/NimBLE-Arduino@^2.3.2 -[env:esp32_ota] -extends = env:esp32dev -upload_protocol = espota -upload_port = 172.16.8.1 -#upload_flags = --auth=xxx +; [env:esp32_ota] +; extends = env:esp32dev +#upload_protocol = espota +#upload_port = 172.16.8.1 +#upload_flags = --auth=xxx [platformio] build_cache_dir = ~/.cache/pio-ccache 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() |