Browse Source

add MQTT status to LED update, try to fix settings save for led polarity

pull/839/head
Markus Krause 2 years ago
parent
commit
48a6bf021c
  1. 22
      src/app.cpp
  2. 4
      src/app.h
  3. 4
      src/config/settings.h
  4. 2
      src/web/html/setup.html

22
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);
}
}
}

4
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..."));

4
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")];
}
}

2
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'])
)
])
);

Loading…
Cancel
Save