mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add antiburn command
This commit is contained in:
parent
b92586b36e
commit
886a394421
@ -150,17 +150,17 @@ void hasp_get_sleep_state(char* payload)
|
||||
/**
|
||||
* Anti Burn-in protection
|
||||
*/
|
||||
static lv_task_t* anti_burnin_task;
|
||||
static lv_task_t* antiburn_task;
|
||||
|
||||
void hasp_stop_anti_burn(lv_obj_t* layer)
|
||||
void hasp_stop_antiburn(lv_obj_t* layer)
|
||||
{
|
||||
anti_burnin_task = NULL;
|
||||
antiburn_task = NULL;
|
||||
lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
||||
hasp_set_wakeup_touch(haspDevice.get_backlight_power() == false); // enabled if backlight is OFF
|
||||
LOG_INFO(TAG_HASP, F("Antiburn disabled"));
|
||||
dispatch_state_antiburn(HASP_EVENT_OFF);
|
||||
}
|
||||
|
||||
void hasp_anti_burnin_cb(lv_task_t* task)
|
||||
void hasp_antiburn_cb(lv_task_t* task)
|
||||
{
|
||||
lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
|
||||
if(!layer) return;
|
||||
@ -170,36 +170,44 @@ void hasp_anti_burnin_cb(lv_task_t* task)
|
||||
lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
|
||||
|
||||
// task is about to get deleted
|
||||
if(task->repeat_count == 1) hasp_stop_anti_burn(layer);
|
||||
if(task->repeat_count == 1) hasp_stop_antiburn(layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Anti Burn-in protection
|
||||
*/
|
||||
void hasp_set_anti_burn(int32_t repeat_count, uint32_t period)
|
||||
void hasp_set_antiburn(int32_t repeat_count, uint32_t period)
|
||||
{
|
||||
lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
|
||||
if(!layer) return;
|
||||
|
||||
if(repeat_count != 0) {
|
||||
anti_burnin_task = lv_task_create(hasp_anti_burnin_cb, period, LV_TASK_PRIO_LOWEST, NULL);
|
||||
if(anti_burnin_task) {
|
||||
antiburn_task = lv_task_create(hasp_antiburn_cb, period, LV_TASK_PRIO_LOWEST, NULL);
|
||||
if(antiburn_task) {
|
||||
// hasp_set_wakeup_touch(true);
|
||||
lv_obj_set_event_cb(layer, first_touch_event_handler);
|
||||
lv_obj_set_click(layer, true);
|
||||
lv_task_set_repeat_count(anti_burnin_task, repeat_count);
|
||||
LOG_INFO(TAG_HASP, F("Antiburn %s"), D_SETTING_ENABLED);
|
||||
lv_task_set_repeat_count(antiburn_task, repeat_count);
|
||||
dispatch_state_antiburn(HASP_EVENT_ON);
|
||||
} else {
|
||||
LOG_INFO(TAG_HASP, F("Antiburn %s"), D_INFO_FAILED);
|
||||
}
|
||||
} else {
|
||||
if(anti_burnin_task) {
|
||||
lv_task_del(anti_burnin_task);
|
||||
hasp_stop_anti_burn(layer);
|
||||
if(antiburn_task) {
|
||||
lv_task_del(antiburn_task);
|
||||
hasp_stop_antiburn(layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Anti Burn-in protection is enabled
|
||||
*/
|
||||
bool hasp_get_antiburn()
|
||||
{
|
||||
return antiburn_task != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Wake-up Touch
|
||||
*/
|
||||
|
@ -69,7 +69,8 @@ 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);
|
||||
void hasp_set_anti_burn(int32_t repeat_count,uint32_t period);
|
||||
bool hasp_get_antiburn();
|
||||
void hasp_set_antiburn(int32_t repeat_count,uint32_t period);
|
||||
|
||||
void hasp_init(void);
|
||||
void hasp_load_json(void);
|
||||
|
@ -48,7 +48,7 @@ dispatch_conf_t dispatch_setings = {.teleperiod = 300};
|
||||
|
||||
uint16_t dispatchSecondsToNextTeleperiod = 0;
|
||||
uint8_t nCommands = 0;
|
||||
haspCommand_t commands[25];
|
||||
haspCommand_t commands[26];
|
||||
|
||||
moodlight_t moodlight = {.brightness = 255};
|
||||
|
||||
@ -107,6 +107,18 @@ void dispatch_state_brightness(const char* topic, hasp_event_t eventid, int32_t
|
||||
dispatch_state_subtopic(topic, payload);
|
||||
}
|
||||
|
||||
void dispatch_state_antiburn( hasp_event_t eventid)
|
||||
{
|
||||
char topic[9];
|
||||
char payload[64];
|
||||
char eventname[8];
|
||||
|
||||
Parser::get_event_name(eventid, eventname, sizeof(eventname));
|
||||
snprintf_P(topic, sizeof(topic), PSTR("antiburn"));
|
||||
snprintf_P(payload, sizeof(payload), PSTR("{\"state\":\"%s\"}"), eventname);
|
||||
dispatch_state_subtopic(topic, payload);
|
||||
}
|
||||
|
||||
void dispatch_state_val(const char* topic, hasp_event_t eventid, int32_t val)
|
||||
{
|
||||
char payload[64];
|
||||
@ -939,6 +951,12 @@ void dispatch_web_update(const char*, const char* espOtaUrl, uint8_t source)
|
||||
#endif
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// restart the device
|
||||
void dispatch_reboot(bool saveConfig)
|
||||
{
|
||||
@ -1280,6 +1298,7 @@ void dispatchSetup()
|
||||
dispatch_add_command(PSTR("run"), dispatch_exec);
|
||||
dispatch_add_command(PSTR("service"), dispatch_service);
|
||||
dispatch_add_command(PSTR("wakeup"), dispatch_wakeup_obsolete);
|
||||
dispatch_add_command(PSTR("antiburn"), dispatch_antiburn);
|
||||
dispatch_add_command(PSTR("calibrate"), dispatch_calibrate);
|
||||
dispatch_add_command(PSTR("update"), dispatch_web_update);
|
||||
dispatch_add_command(PSTR("reboot"), dispatch_reboot);
|
||||
|
@ -83,6 +83,7 @@ void dispatch_state_subtopic(const char* subtopic, const char* payload);
|
||||
void dispatch_state_eventid(const char* topic, hasp_event_t eventid);
|
||||
void dispatch_state_brightness(const char* topic, hasp_event_t eventid, int32_t val);
|
||||
void dispatch_state_val(const char* topic, hasp_event_t eventid, int32_t val);
|
||||
void dispatch_state_antiburn(hasp_event_t eventid);
|
||||
|
||||
/* ===== Getter and Setter Functions ===== */
|
||||
|
||||
|
@ -321,7 +321,7 @@ void first_touch_event_handler(lv_obj_t* obj, lv_event_t event)
|
||||
dispatch_backlight(NULL, "on", TAG_EVENT); // backlight on and also disable wakeup touch
|
||||
}
|
||||
hasp_set_wakeup_touch(false); // only disable wakeup touch
|
||||
hasp_set_anti_burn(0, 0); // disable antiburn task
|
||||
hasp_set_antiburn(0, 0); // disable antiburn task
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user