123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- #include <lvgl.h>
- #include "ui_mem.h"
- #include "app_ui.h"
- #include "aem_log.h"
- #include "aem_adapter_debug.h"
- #include "aem_app_activity.h"
- #include "aem_sys_function_interface.h"
- #include "aem_app_comm.h"
- #ifndef CONFIG_SIMULATOR
- #include <drivers/input/input_dev.h>
- extern int tpkey_put_point(struct input_value *value, uint32_t timestamp);
- struct input_value *released_val = NULL;
- #else
- #include "lv_drivers/win32drv.h"
- #endif // !CONFIG_SIMULATOR
- static uint8_t mem_type = MEM_GUI;
- static lv_obj_t *s_memory = NULL;
- static uint32_t s_ticks = 0;
- static lv_obj_t *s_tp_point = NULL;
- static lv_obj_t *s_tp_label = NULL;
- static lv_point_t s_tp_dot[2] = { 0 };
- typedef struct
- {
- size_t free;
- size_t allocated;
- } memory_data_t;
- typedef struct
- {
- memory_data_t gui;
- memory_data_t res;
- } memory_info_t;
- static memory_info_t s_mem_info = { 0 };
- void aem_mem_gui_dump(void)
- {
- if (s_memory == NULL)
- return;
- mem_type = MEM_GUI;
- ui_mem_dump(MEM_GUI);
- }
- void aem_mem_res_dump(void)
- {
- if (s_memory == NULL)
- return;
- mem_type = MEM_RES;
- ui_mem_dump(MEM_RES);
- }
- void aem_mem_refresh_ui(size_t free, size_t allocated)
- {
- if (os_current_get() != aem_get_task_id(AEM_UI_TASK))
- {
- AEM_LOG_W("aem_mem_refresh_ui cur id == %d ui id %d \r\n", os_current_get(), aem_get_task_id(AEM_UI_TASK));
- return;
- }
- if (s_memory == NULL)
- return;
- if (MEM_GUI == mem_type)
- {
- if (s_mem_info.gui.free == free)
- return;
- s_mem_info.gui.free = free;
- s_mem_info.gui.allocated = allocated;
- }
- else if (MEM_RES == mem_type)
- {
- if (s_mem_info.res.free == free)
- return;
- s_mem_info.res.free = free;
- s_mem_info.res.allocated = allocated;
- }
- lv_label_set_text_fmt(s_memory, "RES:#000000 %d#F #000000 %d#U\nGUI:#000000 %d#F #000000 %d#U",
- s_mem_info.res.free, s_mem_info.res.allocated, s_mem_info.gui.free, s_mem_info.gui.allocated);
- aem_act_info_t *info = aem_get_active_activity();
- AEM_LOG_W("aem_dump act: %s, gui: %zd free, %zd allocated; res: %zd free, %zd allocated\r\n",
- info->name, s_mem_info.gui.free, s_mem_info.gui.allocated, s_mem_info.res.free, s_mem_info.res.allocated);
- }
- lv_obj_t *aem_get_mem_print_obj(void)
- {
- return s_memory;
- }
- static void mem_dump_evt(lv_event_t *e)
- {
- if ((os_uptime_get_32() - s_ticks) > 300)
- {
- s_ticks = os_uptime_get_32();
- aem_mem_gui_dump();
- aem_mem_res_dump();
- }
- }
- void aem_mem_obj_create(void)
- {
- if (s_memory != NULL)
- return;
- s_memory = lv_label_create(lv_layer_top());
- // lv_obj_set_width(s_memory, 300);
- if (s_memory)
- {
- lv_obj_clear_flag(s_memory, LV_OBJ_FLAG_CLICKABLE);
- lv_obj_set_style_pad_all(s_memory, 5, LV_PART_MAIN);
- lv_obj_set_style_bg_opa(s_memory, LV_OPA_50, LV_PART_MAIN);
- lv_obj_set_style_bg_color(s_memory, lv_color_white(), LV_PART_MAIN);
- lv_obj_set_style_text_opa(s_memory, LV_OPA_COVER, LV_PART_MAIN);
- lv_obj_set_style_text_color(s_memory, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);
- lv_obj_set_style_text_font(s_memory, aem_font_sub(), LV_PART_MAIN);
- lv_obj_set_style_text_align(s_memory, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
- lv_label_set_recolor(s_memory, true);
- lv_label_set_text(s_memory, "RES: F U\nGUI: F U");
- lv_obj_align(s_memory, LV_ALIGN_BOTTOM_MID, 0, -35);
- lv_obj_add_event_cb(s_memory, mem_dump_evt, LV_EVENT_DRAW_POST_END, NULL);
- }
- }
- void aem_mem_obj_del(void)
- {
- if (s_memory != NULL)
- {
- lv_obj_del(s_memory);
- s_memory = NULL;
- }
- }
- void aem_set_tp_test(lv_coord_t x, lv_coord_t y)
- {
- if (s_tp_point)
- {
- if (s_tp_dot[0].x == 0 && s_tp_dot[0].y == 0)
- {
- s_tp_dot[0].x = x;
- s_tp_dot[0].y = y;
- s_tp_dot[1].x = x;
- s_tp_dot[1].y = y;
- lv_obj_clear_flag(s_tp_point, LV_OBJ_FLAG_HIDDEN);
- }
- else if (x == 0 && y == 0)
- {
- s_tp_dot[0].x = 0;
- s_tp_dot[0].y = 0;
- s_tp_dot[1].x = 0;
- s_tp_dot[1].y = 0;
- lv_obj_add_flag(s_tp_point, LV_OBJ_FLAG_HIDDEN);
- return;
- }
- else
- {
- s_tp_dot[1].x = x;
- s_tp_dot[1].y = y;
- }
- lv_line_set_points(s_tp_point, s_tp_dot, 2);
- }
- if (s_tp_label)
- {
- lv_label_set_text_fmt(s_tp_label, "release x:%d / y:%d\npress x:%d / y:%d", s_tp_dot[1].x, s_tp_dot[1].y, s_tp_dot[0].x, s_tp_dot[0].y);
- }
- }
- bool aem_get_tp_test(void)
- {
- if (s_tp_point || s_tp_label)
- {
- return true;
- }
- return false;
- }
- void aem_tp_test_create(void)
- {
- if (s_tp_point == NULL)
- {
- s_tp_point = lv_line_create(lv_layer_top());
- if (s_tp_point)
- {
- //lv_line_set_y_invert(s_tp_point, true);
- lv_obj_clear_flag(s_tp_point, LV_OBJ_FLAG_CLICKABLE);
- lv_obj_set_style_line_rounded(s_tp_point, true, LV_PART_MAIN);
- lv_obj_set_style_line_color(s_tp_point, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);
- lv_obj_set_style_line_width(s_tp_point, 10, LV_PART_MAIN);
- }
- }
- if (s_tp_label == NULL)
- {
- s_tp_label = lv_label_create(lv_layer_top());
- if (s_tp_label)
- {
- lv_obj_clear_flag(s_tp_label, LV_OBJ_FLAG_CLICKABLE);
- lv_obj_set_style_pad_all(s_tp_label, 5, LV_PART_MAIN);
- lv_obj_set_style_bg_opa(s_tp_label, LV_OPA_50, LV_PART_MAIN);
- lv_obj_set_style_bg_color(s_tp_label, lv_color_white(), LV_PART_MAIN);
- lv_obj_set_style_text_opa(s_tp_label, LV_OPA_COVER, LV_PART_MAIN);
- lv_obj_set_style_text_color(s_tp_label, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);
- lv_obj_set_style_text_font(s_tp_label, aem_font_sub(), LV_PART_MAIN);
- lv_obj_set_style_text_align(s_tp_label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
- lv_label_set_text(s_tp_label, "x:0 / y:0");
- lv_obj_align(s_tp_label, LV_ALIGN_BOTTOM_MID, 0, -35);
- }
- }
- }
- void aem_tp_test_destroy(void)
- {
- if (s_tp_point)
- {
- lv_obj_del(s_tp_point);
- s_tp_point = NULL;
- }
- if (s_tp_label)
- {
- lv_obj_del(s_tp_label);
- s_tp_label = NULL;
- }
- }
- #ifndef CONFIG_SIMULATOR
- static void sliding_simulation_exec_cb(void * var, int32_t value)
- {
- if (var == NULL)
- return;
- struct input_value *val = var;
- if (val)
- {
- if (val->point.loc_x == (DEF_UI_HEIGHT >> 1))
- {
- val->point.loc_y = value;
- }
- else if (val->point.loc_y == (DEF_UI_HEIGHT >> 1))
- {
- val->point.loc_x = value;
- }
-
- tpkey_put_point(val, k_cycle_get_32());
- }
- }
- static void sliding_simulation_deleted_cb(lv_anim_t *a)
- {
- if (a == NULL)
- return;
-
- struct input_value *val = a->var;
- if (val)
- {
- // if (val->point.loc_x == (DEF_UI_HEIGHT >> 1))
- // {
- // val->point.loc_y = a->end_value;
- // }
- // else if (val->point.loc_y == (DEF_UI_HEIGHT >> 1))
- // {
- // val->point.loc_x = a->end_value;
- // }
- // tpkey_put_point(val, k_cycle_get_32());
- val->point.pessure_value = 0;
- tpkey_put_point(val, k_cycle_get_32());
- lv_mem_free(val);
- released_val = NULL;
- }
- }
- #endif // !CONFIG_SIMULATOR
- void aem_sliding_simulation(lv_dir_t dir, uint16_t steps)
- {
- if (os_current_get() != aem_get_task_id(AEM_UI_TASK))
- {
- AEM_LOG_W("aem_mem_refresh_ui cur id == %d ui id %d \r\n", os_current_get(), aem_get_task_id(AEM_UI_TASK));
- return;
- }
- #ifndef CONFIG_SIMULATOR
- if (released_val)
- return;
- struct input_value val;
- val.point.pessure_value = 1;
- released_val = (struct input_value *)lv_mem_alloc(sizeof(struct input_value));
- released_val->point.pessure_value = 1;
- lv_anim_t a;
- lv_anim_init(&a);
- lv_anim_set_var(&a, released_val);
- lv_anim_set_time(&a, 50);
- lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)sliding_simulation_exec_cb);
- lv_anim_set_deleted_cb(&a, (lv_anim_deleted_cb_t)sliding_simulation_deleted_cb);
-
- switch (dir)
- {
- case LV_DIR_LEFT:
- {
- val.point.gesture = 3;
- val.point.loc_x = (DEF_UI_WIDTH >> 1) + (steps >> 1);
- val.point.loc_y = DEF_UI_HEIGHT >> 1;
- released_val->point.gesture = 3;
- released_val->point.loc_x = (DEF_UI_WIDTH >> 1) - (steps >> 1);
- released_val->point.loc_y = DEF_UI_HEIGHT >> 1;
- lv_anim_set_values(&a, val.point.loc_x, released_val->point.loc_x);
- break;
- }
- case LV_DIR_RIGHT:
- {
- val.point.gesture = 4;
- val.point.loc_x = (DEF_UI_WIDTH >> 1) - (steps >> 1);
- val.point.loc_y = DEF_UI_HEIGHT >> 1;
- released_val->point.gesture = 4;
- released_val->point.loc_x = (DEF_UI_WIDTH >> 1) + (steps >> 1);
- released_val->point.loc_y = DEF_UI_HEIGHT >> 1;
-
- lv_anim_set_values(&a, val.point.loc_x, released_val->point.loc_x);
- break;
- }
- case LV_DIR_TOP:
- {
- val.point.gesture = 2;
- val.point.loc_x = DEF_UI_WIDTH >> 1;
- val.point.loc_y = (DEF_UI_HEIGHT >> 1) + (steps >> 1);
- released_val->point.gesture = 2;
- released_val->point.loc_x = DEF_UI_WIDTH >> 1;
- released_val->point.loc_y = (DEF_UI_HEIGHT >> 1) - (steps >> 1);
-
- lv_anim_set_values(&a, val.point.loc_y, released_val->point.loc_y);
- break;
- }
- case LV_DIR_BOTTOM:
- {
- val.point.gesture = 1;
- val.point.loc_x = DEF_UI_WIDTH >> 1;
- val.point.loc_y = (DEF_UI_HEIGHT >> 1) - (steps >> 1);
- released_val->point.gesture = 1;
- released_val->point.loc_x = DEF_UI_WIDTH >> 1;
- released_val->point.loc_y = (DEF_UI_HEIGHT >> 1) + (steps >> 1);
-
- lv_anim_set_values(&a, val.point.loc_y, released_val->point.loc_y);
- break;
- }
- default:
- break;
- }
- // tpkey_put_point(&val, k_cycle_get_32());
- lv_anim_start(&a);
- #else
- lv_win32_set_pointer_state(AEM_TP_STATE_PRESSED, dir, steps);
- #endif // !CONFIG_SIMULATOR
- }
- void aem_lv_assert_obj(const lv_obj_t *obj, const lv_obj_class_t *class_p)
- {
- if (obj == NULL)
- {
- AEM_LOG_E("The object is NULL");
- return;
- }
- if (lv_obj_has_class(obj, class_p) == false)
- {
- AEM_LOG_E("%p != %p Incompatible object type.", obj->class_p, class_p);
- }
- }
|