From 47eb19b9b2f41b4cbf2a3bbf7e13d1c15ab87923 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 6 Nov 2021 02:01:42 +0100 Subject: [PATCH] Dispatch antiburn on connect #134 --- src/hasp/hasp.cpp | 4 ++-- src/hasp/hasp.h | 2 +- src/hasp/hasp_dispatch.cpp | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index f4aff22c..065f4cfb 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -203,9 +203,9 @@ void hasp_set_antiburn(int32_t repeat_count, uint32_t period) /** * Check if Anti Burn-in protection is enabled */ -bool hasp_get_antiburn() +hasp_event_t hasp_get_antiburn() { - return antiburn_task != NULL; + return (antiburn_task != NULL) ? HASP_EVENT_ON : HASP_EVENT_OFF; } /** diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index 554755f1..bc4b3b78 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -69,7 +69,7 @@ void hasp_set_sleep_state(uint8_t state); void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time); void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time); void hasp_set_wakeup_touch(bool en); -bool hasp_get_antiburn(); +hasp_event_t hasp_get_antiburn(); void hasp_set_antiburn(int32_t repeat_count,uint32_t period); void hasp_init(void); diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index ea0092ca..559011f0 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -953,8 +953,12 @@ void dispatch_web_update(const char*, const char* espOtaUrl, uint8_t source) void dispatch_antiburn(const char*, const char* payload, uint8_t source) { - bool state = Parser::is_true(payload); // ON, TRUE, YES or 1 - hasp_set_antiburn(state ? 30 : 0, 1000); // ON = 25 cycles of 1000 milli seconds (i.e. 25 sec) + if(strlen(payload) > 0) { + bool state = Parser::is_true(payload); // ON, TRUE, YES or 1 + hasp_set_antiburn(state ? 30 : 0, 1000); // ON = 25 cycles of 1000 milli seconds (i.e. 25 sec) + } else { + dispatch_state_antiburn(hasp_get_antiburn()); + } } // restart the device @@ -1167,6 +1171,7 @@ void dispatch_current_state(uint8_t source) dispatch_current_page(); dispatch_send_sensordata(NULL, NULL, source); dispatch_send_discovery(NULL, NULL, source); + dispatch_state_antiburn(hasp_get_antiburn()); } // Format filesystem and erase EEPROM