From fe3d6588bc5d114d8c42097116033da917fb0a80 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Mon, 10 Jul 2023 18:30:10 +0200 Subject: [PATCH] Feature: Turn off LED 1 if no inverters are enabled for polling This means that e.g. at night, when polling at night is disabled, LED 1 will be turned off now. --- include/Datastore.h | 4 ++++ src/Datastore.cpp | 14 ++++++++++++++ src/Led_Single.cpp | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/Datastore.h b/include/Datastore.h index 4f9545a0d..84923195e 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -50,6 +50,9 @@ class DatastoreClass { // True if at least one inverter is producing bool getIsAtLeastOneProducing(); + // True if at least one inverter is enabled for polling + bool getIsAtLeastOnePollEnabled(); + // True if all enabled inverters are producing bool getIsAllEnabledProducing(); @@ -75,6 +78,7 @@ class DatastoreClass { bool _isAtLeastOneProducing = false; bool _isAllEnabledProducing = false; bool _isAllEnabledReachable = false; + bool _isAtLeastOnePollEnabled = false; }; extern DatastoreClass Datastore; \ No newline at end of file diff --git a/src/Datastore.cpp b/src/Datastore.cpp index 880ff174d..875a8777b 100644 --- a/src/Datastore.cpp +++ b/src/Datastore.cpp @@ -30,6 +30,7 @@ void DatastoreClass::loop() uint8_t isProducing = 0; uint8_t isReachable = 0; + uint8_t pollEnabledCount = 0; DAT_SEMAPHORE_TAKE(); @@ -62,6 +63,10 @@ void DatastoreClass::loop() continue; } + if (inv->getEnablePolling()) { + pollEnabledCount++; + } + if (inv->isProducing()) { isProducing++; } else { @@ -107,6 +112,7 @@ void DatastoreClass::loop() _isAtLeastOneProducing = isProducing > 0; _isAtLeastOneReachable = isReachable > 0; + _isAtLeastOnePollEnabled = pollEnabledCount > 0; _totalDcIrradiation = _totalDcIrradiationInstalled > 0 ? _totalDcPowerIrradiation / _totalDcIrradiationInstalled * 100.0f : 0; @@ -235,3 +241,11 @@ bool DatastoreClass::getIsAllEnabledReachable() DAT_SEMAPHORE_GIVE(); return retval; } + +bool DatastoreClass::getIsAtLeastOnePollEnabled() +{ + DAT_SEMAPHORE_TAKE(); + bool retval = _isAtLeastOnePollEnabled; + DAT_SEMAPHORE_GIVE(); + return retval; +} diff --git a/src/Led_Single.cpp b/src/Led_Single.cpp index bd87ba1d6..17690fe0e 100644 --- a/src/Led_Single.cpp +++ b/src/Led_Single.cpp @@ -57,7 +57,7 @@ void LedSingleClass::loop() // Update inverter status _ledState[1] = LedState_t::Off; - if (Hoymiles.getNumInverters()) { + if (Hoymiles.getNumInverters() && Datastore.getIsAtLeastOnePollEnabled()) { // set LED status if (Datastore.getIsAllEnabledReachable() && Datastore.getIsAllEnabledProducing()) { _ledState[1] = LedState_t::On;