From 48a6bf021cf11f79ca71a25fa9eae571779d3748 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Sat, 1 Apr 2023 13:00:38 +0200 Subject: [PATCH] add MQTT status to LED update, try to fix settings save for led polarity --- src/app.cpp | 22 +++++++++++++++------- src/app.h | 4 ++-- src/config/settings.h | 4 ++-- src/web/html/setup.html | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 088454f6..9ec6ff26 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -69,7 +69,7 @@ void app::setup() { mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } #endif - setupLed(mConfig->led.led_high_active); + setupLed(); mWeb.setup(this, &mSys, mConfig); mWeb.setProtection(strlen(mConfig->sys.adminPwd) != 0); @@ -353,7 +353,7 @@ void app::tickSend(void) { } yield(); - updateLed(mConfig->led.led_high_active); + updateLed(); } //----------------------------------------------------------------------------- @@ -386,9 +386,9 @@ void app::mqttSubRxCb(JsonObject obj) { } //----------------------------------------------------------------------------- -void app::setupLed(uint8_t is_high_active) { +void app::setupLed(void) { - uint8_t led_off = (is_high_active != 0) ? LOW : HIGH; + uint8_t led_off = (mConfig->led.led_high_active != 0) ? LOW : HIGH; if (mConfig->led.led0 != 0xff) { pinMode(mConfig->led.led0, OUTPUT); @@ -401,10 +401,10 @@ void app::setupLed(uint8_t is_high_active) { } //----------------------------------------------------------------------------- -void app::updateLed(uint8_t is_high_active) { +void app::updateLed(void) { - uint8_t led_off = (is_high_active != 0) ? LOW : HIGH; - uint8_t led_on = (is_high_active != 0) ? HIGH : LOW; + uint8_t led_off = (mConfig->led.led_high_active != 0) ? LOW : HIGH; + uint8_t led_on = (mConfig->led.led_high_active != 0) ? HIGH : LOW; if (mConfig->led.led0 != 0xff) { Inverter<> *iv = mSys.getInverterByPos(0); @@ -415,4 +415,12 @@ void app::updateLed(uint8_t is_high_active) { digitalWrite(mConfig->led.led0, led_off); } } + + if (mConfig->led.led1 != 0xff) { + if (getMqttIsConnected()) { + digitalWrite(mConfig->led.led1, led_on); + } else { + digitalWrite(mConfig->led.led1, led_off); + } + } } diff --git a/src/app.h b/src/app.h index 252434ae..6dfc404c 100644 --- a/src/app.h +++ b/src/app.h @@ -213,8 +213,8 @@ class app : public IApp, public ah::Scheduler { void mqttSubRxCb(JsonObject obj); - void setupLed(uint8_t is_high_active); - void updateLed(uint8_t is_high_active); + void setupLed(); + void updateLed(); void tickReboot(void) { DPRINTLN(DBG_INFO, F("Rebooting...")); diff --git a/src/config/settings.h b/src/config/settings.h index 7449a0b6..e895a8a9 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -519,11 +519,11 @@ class settings { if(set) { obj[F("0")] = mCfg.led.led0; obj[F("1")] = mCfg.led.led1; - obj[F("2")] = mCfg.led.led_high_active; + obj[F("led_high_active")] = mCfg.led.led_high_active; } else { mCfg.led.led0 = obj[F("0")]; mCfg.led.led1 = obj[F("1")]; - mCfg.led.led_high_active = obj[F("2")]; + mCfg.led.led_high_active = obj[F("led_high_active")]; } } diff --git a/src/web/html/setup.html b/src/web/html/setup.html index fbe29010..97bf5608 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -678,7 +678,7 @@ ml("div", { class: "row mb-3" }, [ ml("div", { class: "col-12 col-sm-3 my-2" }, "LED polarity"), ml("div", { class: "col-12 col-sm-9" }, - sel('pinLedHighActive', led_high_active, obj["led_high_active"]) + sel('pinLedHighActive', led_high_active, obj['led_high_active']) ) ]) );