From b1d3e6bd691de3d45936b317a63295a372562e14 Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Fri, 21 Feb 2025 22:26:18 +0100 Subject: [PATCH] fixed accidental reset when restarting the interface via button and keeping the button pressed --- src/main.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9204603..516d94d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,17 +96,18 @@ void onButtonPress() switch (action) { case ResetConfig: - ledBlink(100); - config.begin("dmx", false); config.clear(); config.end(); - delay(1000); ESP.restart(); break; case Restart: + config.begin("dmx", false); + config.putBool("restart-via-btn", true); + config.end(); + ESP.restart(); break; case None: @@ -125,12 +126,13 @@ void setup() // LED config.begin("dmx", true); brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS); + bool restartViaButton = config.getBool("restart-via-btn", false); config.end(); analogWrite(PIN_LED, brightness_led); // Button pinMode(PIN_BUTTON, INPUT_PULLUP); - if (digitalRead(PIN_BUTTON) == LOW) + if (digitalRead(PIN_BUTTON) == LOW && !restartViaButton) { ledBlink(100); unsigned long startTime = millis(); @@ -148,6 +150,10 @@ void setup() } } + config.begin("dmx", false); + config.putBool("restart-via-btn", false); + config.end(); + ledBlink(500); attachInterrupt(PIN_BUTTON, onButtonPress, FALLING);