From a1c5d8a579f40ab16dec96c7af9cb5d1817704ba Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Wed, 30 Aug 2023 00:18:18 +0200 Subject: [PATCH] Added timer pause/resume button and updated README --- README.md | 9 ++++++ src/lib/functions.cpp | 67 +++++++++++++++++++++++++++++++++++++++++-- src/lib/functions.hpp | 1 + src/tasks/button.cpp | 7 +++-- 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5d633d0..277cb14 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,15 @@ Improved code for BTClock with many features. Don't forget to copy `config.h.example` to `config.h`. Not necessary to adapt it, since everything should be configurable through the WebUI. +### Button actions + +(Top = 1 to bottom = 4) + +1. Start/stop timer (confirmed with LEDs) +2. Next screen +3. Previous screen +4. Show IP address + ## Software - [PlatformIO](https://platformio.org/platformio-ide). diff --git a/src/lib/functions.cpp b/src/lib/functions.cpp index 401a10f..32be979 100644 --- a/src/lib/functions.cpp +++ b/src/lib/functions.cpp @@ -37,9 +37,9 @@ void setupSoftAP() { byte mac[6]; WiFi.macAddress(mac); - softAP_SSID = String("BTClock" + String(mac[3], 16) + String(mac[1], 16)); + softAP_SSID = String("BTClock" + String(mac[5], 16) + String(mac[6], 16)); WiFi.setHostname(softAP_SSID.c_str()); - softAP_password = base64::encode(String(mac[2], 16) + String(mac[4], 16) + String(mac[5], 16) + String(mac[6], 16)).substring(2, 12); + softAP_password = base64::encode(String(mac[2], 16) + String(mac[4], 16) + String(mac[5], 16) + String(mac[6], 16)).substring(2, 10); } void setupComponents() @@ -132,7 +132,7 @@ void setupWifi() ESP.restart(); } - return; + return; } #endif @@ -237,6 +237,67 @@ void handleScreenTasks(uint screen) } } +void toggleScreenTimer() +{ + timerRunning = !timerRunning; + + if (!timerRunning) + { + Serial.println("Stopping screen timer..."); + for (int i = NEOPIXEL_COUNT; i >= 0; i--) + { + for (int j = NEOPIXEL_COUNT; j >= 0; j--) + { + uint32_t c = pixels.Color(0, 0, 0); + if (i == j) + c = pixels.Color(0, 255, 0); + pixels.setPixelColor(j, c); + } + + pixels.show(); + + delay(100); + } + + delay(900); + + pixels.clear(); + pixels.show(); + } + else + { + Serial.println("Starting screen timer..."); + + pixels.setPixelColor(3, pixels.Color(0, 255, 0)); + pixels.setPixelColor(2, pixels.Color(0, 0, 0)); + pixels.setPixelColor(1, pixels.Color(0, 0, 0)); + pixels.setPixelColor(0, pixels.Color(0, 0, 0)); + pixels.show(); + + delay(1000); + + for (int i = NEOPIXEL_COUNT; i--; i > 0) + { + + for (int j = NEOPIXEL_COUNT; j--; j > 0) + { + uint32_t c = pixels.Color(0, 0, 0); + if (i == j) + c = pixels.Color(0, 255, 0); + + pixels.setPixelColor(j, c); + } + + pixels.show(); + + delay(100); + } + + pixels.clear(); + pixels.show(); + } +} + int getBgColor() { return bgColor; diff --git a/src/lib/functions.hpp b/src/lib/functions.hpp index 11a921b..d5ce525 100644 --- a/src/lib/functions.hpp +++ b/src/lib/functions.hpp @@ -25,6 +25,7 @@ uint getCurrentScreen(); void setCurrentScreen(uint screen); void handleScreenTasks(uint screen); void showNetworkSettings(); +void toggleScreenTimer(); void timebasedChangeTask(void *parameter); diff --git a/src/tasks/button.cpp b/src/tasks/button.cpp index 15ea954..3fc758f 100644 --- a/src/tasks/button.cpp +++ b/src/tasks/button.cpp @@ -20,15 +20,16 @@ void buttonTask(void *parameter) { uint pin = mcp.getLastInterruptPin(); if (pin == 3) { - xTaskCreate(fullRefresh, "FullRefresh", 2048, NULL, 1, NULL); + // xTaskCreate(fullRefresh, "FullRefresh", 2048, NULL, 1, NULL); + toggleScreenTimer(); } else if (pin == 1) { - nextScreen(); + previousScreen(); } else if (pin == 2) { - previousScreen(); + nextScreen(); } else if (pin == 0) {