Decouple antiburn from wakeup touch

This commit is contained in:
fvanroie 2021-10-10 03:13:36 +02:00
parent ec9882714d
commit 758b3daa54
4 changed files with 51 additions and 36 deletions

View File

@ -3,6 +3,7 @@
#include "hasplib.h" #include "hasplib.h"
#include "dev/device.h" #include "dev/device.h"
// #include "lv_datetime.h"
#ifdef ARDUINO #ifdef ARDUINO
#include "ArduinoLog.h" #include "ArduinoLog.h"
@ -147,58 +148,71 @@ void hasp_get_sleep_state(char* payload)
} }
/** /**
* Anti Burn-in protection * Anti Burn-in protection
*/ */
static lv_task_t* anti_burnin_task; static lv_task_t* anti_burnin_task;
void hasp_anti_burnin_cb(lv_task_t* task) void hasp_stop_anti_burn(lv_obj_t* layer)
{ {
lv_color_t color[6] = {LV_COLOR_BLACK, LV_COLOR_WHITE, LV_COLOR_RED, LV_COLOR_LIME, LV_COLOR_BLUE};
lv_obj_set_style_local_bg_color(lv_disp_get_layer_sys(NULL), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,
color[task->repeat_count % 5]);
// task is about to get deleted
if(task->repeat_count == 1) {
// lv_obj_set_style_local_bg_opa(lv_disp_get_layer_sys(NULL), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0);
anti_burnin_task = NULL; anti_burnin_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"));
} }
/** void hasp_anti_burnin_cb(lv_task_t* task)
* Enable/Disable Anti Burn-in protection
*/
void hasp_set_anti_burnin(bool en)
{ {
lv_obj_t* layer = lv_disp_get_layer_sys(NULL); lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
if(!layer) return; if(!layer) return;
if(en) { 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_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100); lv_obj_set_style_local_bg_color(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color[task->repeat_count % 5]);
anti_burnin_task = lv_task_create(hasp_anti_burnin_cb, 2000, LV_TASK_PRIO_LOWEST, NULL); lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_task_set_repeat_count(anti_burnin_task, 25);
LOG_INFO(TAG_HASP, F("Anti burn-in enabled")); // task is about to get deleted
if(task->repeat_count == 1) hasp_stop_anti_burn(layer);
}
/**
* Enable/Disable Anti Burn-in protection
*/
void hasp_set_anti_burn(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) {
// 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);
} else { } else {
if(anti_burnin_task) lv_task_del(anti_burnin_task); LOG_INFO(TAG_HASP, F("Antiburn %s"), D_INFO_FAILED);
anti_burnin_task = NULL; }
lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0); } else {
LOG_INFO(TAG_HASP, F("Anti burn-in disabled")); if(anti_burnin_task) {
lv_task_del(anti_burnin_task);
hasp_stop_anti_burn(layer);
}
} }
} }
/** /**
* Enable/Disable Wake-up Touch * Enable/Disable Wake-up Touch
*/ */
void hasp_set_wakeup_touch(bool en) void hasp_set_wakeup_touch(bool en)
{ {
lv_obj_set_click(lv_disp_get_layer_sys(NULL), en); lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
if(en) { if(!layer) return;
lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), wakeup_event_handler);
LOG_INFO(TAG_HASP, F("Wakeup touch enabled")); if(lv_obj_get_click(layer) != en) {
} else { lv_obj_set_event_cb(layer, first_touch_event_handler);
LOG_INFO(TAG_HASP, F("Wakeup touch disabled")); lv_obj_set_click(layer, en);
LOG_INFO(TAG_HASP, F("First touch %s"), en ? D_SETTING_ENABLED : D_SETTING_DISABLED);
} }
hasp_set_anti_burnin(en);
} }
/** /**

View File

@ -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_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_sleep_time(uint16_t short_time, uint16_t long_time);
void hasp_set_wakeup_touch(bool en); void hasp_set_wakeup_touch(bool en);
void hasp_set_anti_burnin(bool en); void hasp_set_anti_burn(int32_t repeat_count,uint32_t period);
void hasp_init(void); void hasp_init(void);
void hasp_load_json(void); void hasp_load_json(void);

View File

@ -311,7 +311,7 @@ static void log_event(const char* name, lv_event_t event)
* @param obj pointer to a button matrix * @param obj pointer to a button matrix
* @param event type of event that occured * @param event type of event that occured
*/ */
void wakeup_event_handler(lv_obj_t* obj, lv_event_t event) void first_touch_event_handler(lv_obj_t* obj, lv_event_t event)
{ {
// log_event("wakeup", event); // log_event("wakeup", event);
@ -321,6 +321,7 @@ void wakeup_event_handler(lv_obj_t* obj, lv_event_t event)
dispatch_backlight(NULL, "on", TAG_EVENT); // backlight on and also disable wakeup touch dispatch_backlight(NULL, "on", TAG_EVENT); // backlight on and also disable wakeup touch
} }
hasp_set_wakeup_touch(false); // only disable wakeup touch hasp_set_wakeup_touch(false); // only disable wakeup touch
hasp_set_anti_burn(0, 0); // disable antiburn task
} }
} }

View File

@ -17,7 +17,7 @@ void event_timer_clock(lv_task_t* task);
// Object event Handlers // Object event Handlers
void delete_event_handler(lv_obj_t* obj, lv_event_t event); void delete_event_handler(lv_obj_t* obj, lv_event_t event);
void wakeup_event_handler(lv_obj_t* obj, lv_event_t event); void first_touch_event_handler(lv_obj_t* obj, lv_event_t event);
void generic_event_handler(lv_obj_t* obj, lv_event_t event); void generic_event_handler(lv_obj_t* obj, lv_event_t event);
void toggle_event_handler(lv_obj_t* obj, lv_event_t event); void toggle_event_handler(lv_obj_t* obj, lv_event_t event);
void slider_event_handler(lv_obj_t* obj, lv_event_t event); void slider_event_handler(lv_obj_t* obj, lv_event_t event);