mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-30 02:36:20 +02:00
add MQTT status to LED update, try to fix settings save for led polarity
This commit is contained in:
parent
1eabd0f470
commit
48a6bf021c
4 changed files with 20 additions and 12 deletions
22
src/app.cpp
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));
|
mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
setupLed(mConfig->led.led_high_active);
|
setupLed();
|
||||||
|
|
||||||
mWeb.setup(this, &mSys, mConfig);
|
mWeb.setup(this, &mSys, mConfig);
|
||||||
mWeb.setProtection(strlen(mConfig->sys.adminPwd) != 0);
|
mWeb.setProtection(strlen(mConfig->sys.adminPwd) != 0);
|
||||||
|
@ -353,7 +353,7 @@ void app::tickSend(void) {
|
||||||
}
|
}
|
||||||
yield();
|
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) {
|
if (mConfig->led.led0 != 0xff) {
|
||||||
pinMode(mConfig->led.led0, OUTPUT);
|
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_off = (mConfig->led.led_high_active != 0) ? LOW : HIGH;
|
||||||
uint8_t led_on = (is_high_active != 0) ? HIGH : LOW;
|
uint8_t led_on = (mConfig->led.led_high_active != 0) ? HIGH : LOW;
|
||||||
|
|
||||||
if (mConfig->led.led0 != 0xff) {
|
if (mConfig->led.led0 != 0xff) {
|
||||||
Inverter<> *iv = mSys.getInverterByPos(0);
|
Inverter<> *iv = mSys.getInverterByPos(0);
|
||||||
|
@ -415,4 +415,12 @@ void app::updateLed(uint8_t is_high_active) {
|
||||||
digitalWrite(mConfig->led.led0, led_off);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,8 +213,8 @@ class app : public IApp, public ah::Scheduler {
|
||||||
|
|
||||||
void mqttSubRxCb(JsonObject obj);
|
void mqttSubRxCb(JsonObject obj);
|
||||||
|
|
||||||
void setupLed(uint8_t is_high_active);
|
void setupLed();
|
||||||
void updateLed(uint8_t is_high_active);
|
void updateLed();
|
||||||
|
|
||||||
void tickReboot(void) {
|
void tickReboot(void) {
|
||||||
DPRINTLN(DBG_INFO, F("Rebooting..."));
|
DPRINTLN(DBG_INFO, F("Rebooting..."));
|
||||||
|
|
|
@ -519,11 +519,11 @@ class settings {
|
||||||
if(set) {
|
if(set) {
|
||||||
obj[F("0")] = mCfg.led.led0;
|
obj[F("0")] = mCfg.led.led0;
|
||||||
obj[F("1")] = mCfg.led.led1;
|
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 {
|
} else {
|
||||||
mCfg.led.led0 = obj[F("0")];
|
mCfg.led.led0 = obj[F("0")];
|
||||||
mCfg.led.led1 = obj[F("1")];
|
mCfg.led.led1 = obj[F("1")];
|
||||||
mCfg.led.led_high_active = obj[F("2")];
|
mCfg.led.led_high_active = obj[F("led_high_active")];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -678,7 +678,7 @@
|
||||||
ml("div", { class: "row mb-3" }, [
|
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-3 my-2" }, "LED polarity"),
|
||||||
ml("div", { class: "col-12 col-sm-9" },
|
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…
Add table
Reference in a new issue