Feature: Turn off LEDs before reboot

Thanks for the idea to @StefanOberhumer
This prevents always on LEDs if the device profile does not contain LEDs pins anymore after the reboot
This commit is contained in:
Thomas Basler 2023-08-25 13:15:55 +02:00
parent 77a90095d9
commit c91bd42a77
3 changed files with 21 additions and 1 deletions

View File

@ -19,6 +19,9 @@ public:
void init(); void init();
void loop(); void loop();
void turnAllOff();
void turnAllOn();
private: private:
enum class LedState_t { enum class LedState_t {
On, On,
@ -27,6 +30,7 @@ private:
}; };
LedState_t _ledState[PINMAPPING_LED_COUNT]; LedState_t _ledState[PINMAPPING_LED_COUNT];
LedState_t _allState;
TimeoutHelper _updateTimeout; TimeoutHelper _updateTimeout;
TimeoutHelper _blinkTimeout; TimeoutHelper _blinkTimeout;
uint8_t _ledActive = 0; uint8_t _ledActive = 0;

View File

@ -20,6 +20,7 @@ void LedSingleClass::init()
{ {
_blinkTimeout.set(500); _blinkTimeout.set(500);
_updateTimeout.set(LEDSINGLE_UPDATE_INTERVAL); _updateTimeout.set(LEDSINGLE_UPDATE_INTERVAL);
turnAllOn();
for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) { for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
auto& pin = PinMapping.get(); auto& pin = PinMapping.get();
@ -40,7 +41,7 @@ void LedSingleClass::loop()
return; return;
} }
if (_updateTimeout.occured()) { if (_updateTimeout.occured() && _allState == LedState_t::On) {
const CONFIG_T& config = Configuration.get(); const CONFIG_T& config = Configuration.get();
// Update network status // Update network status
@ -68,6 +69,9 @@ void LedSingleClass::loop()
} }
_updateTimeout.reset(); _updateTimeout.reset();
} else if (_updateTimeout.occured() && _allState == LedState_t::Off) {
_ledState[0] = LedState_t::Off;
_ledState[1] = LedState_t::Off;
} }
for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) { for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
@ -93,3 +97,13 @@ void LedSingleClass::loop()
} }
} }
} }
void LedSingleClass::turnAllOff()
{
_allState = LedState_t::Off;
}
void LedSingleClass::turnAllOn()
{
_allState = LedState_t::On;
}

View File

@ -3,6 +3,7 @@
* Copyright (C) 2022 - 2023 Thomas Basler and others * Copyright (C) 2022 - 2023 Thomas Basler and others
*/ */
#include "Utils.h" #include "Utils.h"
#include "Led_Single.h"
#include <Esp.h> #include <Esp.h>
uint32_t Utils::getChipId() uint32_t Utils::getChipId()
@ -56,6 +57,7 @@ int Utils::getTimezoneOffset()
void Utils::restartDtu() void Utils::restartDtu()
{ {
LedSingle.turnAllOff();
yield(); yield();
delay(1000); delay(1000);
yield(); yield();