From c91bd42a770aef2a859b3709c02e0d19dcd444f0 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Fri, 25 Aug 2023 13:15:55 +0200 Subject: [PATCH] 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 --- include/Led_Single.h | 4 ++++ src/Led_Single.cpp | 16 +++++++++++++++- src/Utils.cpp | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/Led_Single.h b/include/Led_Single.h index 22fc87a2..a5c601bd 100644 --- a/include/Led_Single.h +++ b/include/Led_Single.h @@ -19,6 +19,9 @@ public: void init(); void loop(); + void turnAllOff(); + void turnAllOn(); + private: enum class LedState_t { On, @@ -27,6 +30,7 @@ private: }; LedState_t _ledState[PINMAPPING_LED_COUNT]; + LedState_t _allState; TimeoutHelper _updateTimeout; TimeoutHelper _blinkTimeout; uint8_t _ledActive = 0; diff --git a/src/Led_Single.cpp b/src/Led_Single.cpp index 17690fe0..7ce6637f 100644 --- a/src/Led_Single.cpp +++ b/src/Led_Single.cpp @@ -20,6 +20,7 @@ void LedSingleClass::init() { _blinkTimeout.set(500); _updateTimeout.set(LEDSINGLE_UPDATE_INTERVAL); + turnAllOn(); for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) { auto& pin = PinMapping.get(); @@ -40,7 +41,7 @@ void LedSingleClass::loop() return; } - if (_updateTimeout.occured()) { + if (_updateTimeout.occured() && _allState == LedState_t::On) { const CONFIG_T& config = Configuration.get(); // Update network status @@ -68,6 +69,9 @@ void LedSingleClass::loop() } _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++) { @@ -93,3 +97,13 @@ void LedSingleClass::loop() } } } + +void LedSingleClass::turnAllOff() +{ + _allState = LedState_t::Off; +} + +void LedSingleClass::turnAllOn() +{ + _allState = LedState_t::On; +} diff --git a/src/Utils.cpp b/src/Utils.cpp index 997519d0..988c4aed 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2022 - 2023 Thomas Basler and others */ #include "Utils.h" +#include "Led_Single.h" #include uint32_t Utils::getChipId() @@ -56,6 +57,7 @@ int Utils::getTimezoneOffset() void Utils::restartDtu() { + LedSingle.turnAllOff(); yield(); delay(1000); yield();