mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Antiburn improvements
This commit is contained in:
parent
b3eba99558
commit
5b83b4ca88
@ -178,26 +178,29 @@ void hasp_get_sleep_state(char* payload)
|
||||
*/
|
||||
static lv_task_t* antiburn_task;
|
||||
|
||||
void hasp_stop_antiburn(lv_obj_t* layer)
|
||||
void hasp_stop_antiburn()
|
||||
{
|
||||
lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
|
||||
if(layer) lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
||||
if(antiburn_task) lv_task_del(antiburn_task);
|
||||
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
|
||||
gui_hide_pointer(false);
|
||||
dispatch_state_antiburn(HASP_EVENT_OFF);
|
||||
}
|
||||
|
||||
void hasp_antiburn_cb(lv_task_t* task)
|
||||
{
|
||||
lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
|
||||
if(!layer) return;
|
||||
|
||||
lv_color_t color[5] = {LV_COLOR_BLACK, LV_COLOR_WHITE, LV_COLOR_RED, LV_COLOR_LIME, LV_COLOR_BLUE};
|
||||
lv_obj_set_style_local_bg_color(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color[task->repeat_count % 5]);
|
||||
lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
|
||||
if(layer) {
|
||||
lv_color_t color[5] = {LV_COLOR_BLACK, LV_COLOR_WHITE, LV_COLOR_RED, LV_COLOR_LIME, LV_COLOR_BLUE};
|
||||
lv_obj_set_style_local_bg_color(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color[task->repeat_count % 5]);
|
||||
lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
|
||||
if(task->repeat_count != 1) return; // don't stop yet
|
||||
}
|
||||
|
||||
// task is about to get deleted
|
||||
if(task->repeat_count == 1) hasp_stop_antiburn(layer);
|
||||
hasp_stop_antiburn();
|
||||
dispatch_state_antiburn(HASP_EVENT_OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,10 +208,10 @@ void hasp_antiburn_cb(lv_task_t* task)
|
||||
*/
|
||||
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) {
|
||||
lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
|
||||
if(!layer) return;
|
||||
|
||||
if(!antiburn_task) antiburn_task = lv_task_create(hasp_antiburn_cb, period, LV_TASK_PRIO_LOWEST, NULL);
|
||||
if(antiburn_task) {
|
||||
lv_obj_set_event_cb(layer, first_touch_event_handler);
|
||||
@ -216,15 +219,11 @@ void hasp_set_antiburn(int32_t repeat_count, uint32_t period)
|
||||
lv_task_set_repeat_count(antiburn_task, repeat_count);
|
||||
lv_task_set_period(antiburn_task, period);
|
||||
gui_hide_pointer(true);
|
||||
dispatch_state_antiburn(HASP_EVENT_ON);
|
||||
} else {
|
||||
LOG_INFO(TAG_HASP, F("Antiburn %s"), D_INFO_FAILED);
|
||||
}
|
||||
} else {
|
||||
if(antiburn_task) {
|
||||
lv_task_del(antiburn_task);
|
||||
hasp_stop_antiburn(layer);
|
||||
}
|
||||
hasp_stop_antiburn();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,7 @@ void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time);
|
||||
void hasp_set_sleep_offset(uint32_t offset);
|
||||
void hasp_set_wakeup_touch(bool en);
|
||||
void hasp_set_antiburn(int32_t repeat_count, uint32_t period);
|
||||
void hasp_stop_antiburn();
|
||||
hasp_event_t hasp_get_antiburn();
|
||||
|
||||
void hasp_init(void);
|
||||
|
@ -335,12 +335,20 @@ void first_touch_event_handler(lv_obj_t* obj, lv_event_t event)
|
||||
// log_event("wakeup", event);
|
||||
|
||||
if(event == LV_EVENT_RELEASED && obj == lv_disp_get_layer_sys(NULL)) {
|
||||
hasp_update_sleep_state(); // wakeup?
|
||||
if(!haspDevice.get_backlight_power()) {
|
||||
dispatch_backlight(NULL, "on", TAG_EVENT); // backlight on and also disable wakeup touch
|
||||
} else {
|
||||
hasp_set_wakeup_touch(false); // only disable wakeup touch
|
||||
}
|
||||
hasp_set_wakeup_touch(false); // only disable wakeup touch
|
||||
hasp_set_antiburn(0, 0); // disable antiburn task
|
||||
|
||||
// Idle off
|
||||
hasp_update_sleep_state(); // wakeup?
|
||||
|
||||
// Disable antiburn task
|
||||
hasp_event_t old_state = hasp_get_antiburn();
|
||||
hasp_stop_antiburn();
|
||||
hasp_event_t new_state = hasp_get_antiburn();
|
||||
if(old_state != new_state) dispatch_state_antiburn(new_state); // publish the new state
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user