fixed accidental reset when restarting the interface via button and keeping the button pressed

This commit is contained in:
RaffaelW 2025-02-21 22:26:18 +01:00
parent aaae5ac91b
commit b1d3e6bd69

View file

@ -96,17 +96,18 @@ void onButtonPress()
switch (action) switch (action)
{ {
case ResetConfig: case ResetConfig:
ledBlink(100);
config.begin("dmx", false); config.begin("dmx", false);
config.clear(); config.clear();
config.end(); config.end();
delay(1000);
ESP.restart(); ESP.restart();
break; break;
case Restart: case Restart:
config.begin("dmx", false);
config.putBool("restart-via-btn", true);
config.end();
ESP.restart(); ESP.restart();
break; break;
case None: case None:
@ -125,12 +126,13 @@ void setup()
// LED // LED
config.begin("dmx", true); config.begin("dmx", true);
brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS); brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS);
bool restartViaButton = config.getBool("restart-via-btn", false);
config.end(); config.end();
analogWrite(PIN_LED, brightness_led); analogWrite(PIN_LED, brightness_led);
// Button // Button
pinMode(PIN_BUTTON, INPUT_PULLUP); pinMode(PIN_BUTTON, INPUT_PULLUP);
if (digitalRead(PIN_BUTTON) == LOW) if (digitalRead(PIN_BUTTON) == LOW && !restartViaButton)
{ {
ledBlink(100); ledBlink(100);
unsigned long startTime = millis(); unsigned long startTime = millis();
@ -148,6 +150,10 @@ void setup()
} }
} }
config.begin("dmx", false);
config.putBool("restart-via-btn", false);
config.end();
ledBlink(500); ledBlink(500);
attachInterrupt(PIN_BUTTON, onButtonPress, FALLING); attachInterrupt(PIN_BUTTON, onButtonPress, FALLING);