aem_adapter_debug.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #include <lvgl.h>
  2. #include "ui_mem.h"
  3. #include "app_ui.h"
  4. #include "aem_log.h"
  5. #include "aem_adapter_debug.h"
  6. #include "aem_app_activity.h"
  7. #include "aem_sys_function_interface.h"
  8. #include "aem_app_comm.h"
  9. #ifndef CONFIG_SIMULATOR
  10. #include <drivers/input/input_dev.h>
  11. extern int tpkey_put_point(struct input_value *value, uint32_t timestamp);
  12. struct input_value *released_val = NULL;
  13. #else
  14. #include "lv_drivers/win32drv.h"
  15. #endif // !CONFIG_SIMULATOR
  16. static uint8_t mem_type = MEM_GUI;
  17. static lv_obj_t *s_memory = NULL;
  18. static uint32_t s_ticks = 0;
  19. static lv_obj_t *s_tp_point = NULL;
  20. static lv_obj_t *s_tp_label = NULL;
  21. static lv_point_t s_tp_dot[2] = { 0 };
  22. typedef struct
  23. {
  24. size_t free;
  25. size_t allocated;
  26. } memory_data_t;
  27. typedef struct
  28. {
  29. memory_data_t gui;
  30. memory_data_t res;
  31. } memory_info_t;
  32. static memory_info_t s_mem_info = { 0 };
  33. void aem_mem_gui_dump(void)
  34. {
  35. if (s_memory == NULL)
  36. return;
  37. mem_type = MEM_GUI;
  38. ui_mem_dump(MEM_GUI);
  39. }
  40. void aem_mem_res_dump(void)
  41. {
  42. if (s_memory == NULL)
  43. return;
  44. mem_type = MEM_RES;
  45. ui_mem_dump(MEM_RES);
  46. }
  47. void aem_mem_refresh_ui(size_t free, size_t allocated)
  48. {
  49. if (os_current_get() != aem_get_task_id(AEM_UI_TASK))
  50. {
  51. 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));
  52. return;
  53. }
  54. if (s_memory == NULL)
  55. return;
  56. if (MEM_GUI == mem_type)
  57. {
  58. if (s_mem_info.gui.free == free)
  59. return;
  60. s_mem_info.gui.free = free;
  61. s_mem_info.gui.allocated = allocated;
  62. }
  63. else if (MEM_RES == mem_type)
  64. {
  65. if (s_mem_info.res.free == free)
  66. return;
  67. s_mem_info.res.free = free;
  68. s_mem_info.res.allocated = allocated;
  69. }
  70. lv_label_set_text_fmt(s_memory, "RES:#000000 %d#F #000000 %d#U\nGUI:#000000 %d#F #000000 %d#U",
  71. s_mem_info.res.free, s_mem_info.res.allocated, s_mem_info.gui.free, s_mem_info.gui.allocated);
  72. aem_act_info_t *info = aem_get_active_activity();
  73. AEM_LOG_W("aem_dump act: %s, gui: %zd free, %zd allocated; res: %zd free, %zd allocated\r\n",
  74. info->name, s_mem_info.gui.free, s_mem_info.gui.allocated, s_mem_info.res.free, s_mem_info.res.allocated);
  75. }
  76. lv_obj_t *aem_get_mem_print_obj(void)
  77. {
  78. return s_memory;
  79. }
  80. static void mem_dump_evt(lv_event_t *e)
  81. {
  82. if ((os_uptime_get_32() - s_ticks) > 300)
  83. {
  84. s_ticks = os_uptime_get_32();
  85. aem_mem_gui_dump();
  86. aem_mem_res_dump();
  87. }
  88. }
  89. void aem_mem_obj_create(void)
  90. {
  91. if (s_memory != NULL)
  92. return;
  93. s_memory = lv_label_create(lv_layer_top());
  94. // lv_obj_set_width(s_memory, 300);
  95. if (s_memory)
  96. {
  97. lv_obj_clear_flag(s_memory, LV_OBJ_FLAG_CLICKABLE);
  98. lv_obj_set_style_pad_all(s_memory, 5, LV_PART_MAIN);
  99. lv_obj_set_style_bg_opa(s_memory, LV_OPA_50, LV_PART_MAIN);
  100. lv_obj_set_style_bg_color(s_memory, lv_color_white(), LV_PART_MAIN);
  101. lv_obj_set_style_text_opa(s_memory, LV_OPA_COVER, LV_PART_MAIN);
  102. lv_obj_set_style_text_color(s_memory, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);
  103. lv_obj_set_style_text_font(s_memory, aem_font_sub(), LV_PART_MAIN);
  104. lv_obj_set_style_text_align(s_memory, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
  105. lv_label_set_recolor(s_memory, true);
  106. lv_label_set_text(s_memory, "RES: F U\nGUI: F U");
  107. lv_obj_align(s_memory, LV_ALIGN_BOTTOM_MID, 0, -35);
  108. lv_obj_add_event_cb(s_memory, mem_dump_evt, LV_EVENT_DRAW_POST_END, NULL);
  109. }
  110. }
  111. void aem_mem_obj_del(void)
  112. {
  113. if (s_memory != NULL)
  114. {
  115. lv_obj_del(s_memory);
  116. s_memory = NULL;
  117. }
  118. }
  119. void aem_set_tp_test(lv_coord_t x, lv_coord_t y)
  120. {
  121. if (s_tp_point)
  122. {
  123. if (s_tp_dot[0].x == 0 && s_tp_dot[0].y == 0)
  124. {
  125. s_tp_dot[0].x = x;
  126. s_tp_dot[0].y = y;
  127. s_tp_dot[1].x = x;
  128. s_tp_dot[1].y = y;
  129. lv_obj_clear_flag(s_tp_point, LV_OBJ_FLAG_HIDDEN);
  130. }
  131. else if (x == 0 && y == 0)
  132. {
  133. s_tp_dot[0].x = 0;
  134. s_tp_dot[0].y = 0;
  135. s_tp_dot[1].x = 0;
  136. s_tp_dot[1].y = 0;
  137. lv_obj_add_flag(s_tp_point, LV_OBJ_FLAG_HIDDEN);
  138. return;
  139. }
  140. else
  141. {
  142. s_tp_dot[1].x = x;
  143. s_tp_dot[1].y = y;
  144. }
  145. lv_line_set_points(s_tp_point, s_tp_dot, 2);
  146. }
  147. if (s_tp_label)
  148. {
  149. 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);
  150. }
  151. }
  152. bool aem_get_tp_test(void)
  153. {
  154. if (s_tp_point || s_tp_label)
  155. {
  156. return true;
  157. }
  158. return false;
  159. }
  160. void aem_tp_test_create(void)
  161. {
  162. if (s_tp_point == NULL)
  163. {
  164. s_tp_point = lv_line_create(lv_layer_top());
  165. if (s_tp_point)
  166. {
  167. //lv_line_set_y_invert(s_tp_point, true);
  168. lv_obj_clear_flag(s_tp_point, LV_OBJ_FLAG_CLICKABLE);
  169. lv_obj_set_style_line_rounded(s_tp_point, true, LV_PART_MAIN);
  170. lv_obj_set_style_line_color(s_tp_point, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);
  171. lv_obj_set_style_line_width(s_tp_point, 10, LV_PART_MAIN);
  172. }
  173. }
  174. if (s_tp_label == NULL)
  175. {
  176. s_tp_label = lv_label_create(lv_layer_top());
  177. if (s_tp_label)
  178. {
  179. lv_obj_clear_flag(s_tp_label, LV_OBJ_FLAG_CLICKABLE);
  180. lv_obj_set_style_pad_all(s_tp_label, 5, LV_PART_MAIN);
  181. lv_obj_set_style_bg_opa(s_tp_label, LV_OPA_50, LV_PART_MAIN);
  182. lv_obj_set_style_bg_color(s_tp_label, lv_color_white(), LV_PART_MAIN);
  183. lv_obj_set_style_text_opa(s_tp_label, LV_OPA_COVER, LV_PART_MAIN);
  184. lv_obj_set_style_text_color(s_tp_label, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);
  185. lv_obj_set_style_text_font(s_tp_label, aem_font_sub(), LV_PART_MAIN);
  186. lv_obj_set_style_text_align(s_tp_label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
  187. lv_label_set_text(s_tp_label, "x:0 / y:0");
  188. lv_obj_align(s_tp_label, LV_ALIGN_BOTTOM_MID, 0, -35);
  189. }
  190. }
  191. }
  192. void aem_tp_test_destroy(void)
  193. {
  194. if (s_tp_point)
  195. {
  196. lv_obj_del(s_tp_point);
  197. s_tp_point = NULL;
  198. }
  199. if (s_tp_label)
  200. {
  201. lv_obj_del(s_tp_label);
  202. s_tp_label = NULL;
  203. }
  204. }
  205. #ifndef CONFIG_SIMULATOR
  206. static void sliding_simulation_exec_cb(void * var, int32_t value)
  207. {
  208. if (var == NULL)
  209. return;
  210. struct input_value *val = var;
  211. if (val)
  212. {
  213. if (val->point.loc_x == (DEF_UI_HEIGHT >> 1))
  214. {
  215. val->point.loc_y = value;
  216. }
  217. else if (val->point.loc_y == (DEF_UI_HEIGHT >> 1))
  218. {
  219. val->point.loc_x = value;
  220. }
  221. tpkey_put_point(val, k_cycle_get_32());
  222. }
  223. }
  224. static void sliding_simulation_deleted_cb(lv_anim_t *a)
  225. {
  226. if (a == NULL)
  227. return;
  228. struct input_value *val = a->var;
  229. if (val)
  230. {
  231. // if (val->point.loc_x == (DEF_UI_HEIGHT >> 1))
  232. // {
  233. // val->point.loc_y = a->end_value;
  234. // }
  235. // else if (val->point.loc_y == (DEF_UI_HEIGHT >> 1))
  236. // {
  237. // val->point.loc_x = a->end_value;
  238. // }
  239. // tpkey_put_point(val, k_cycle_get_32());
  240. val->point.pessure_value = 0;
  241. tpkey_put_point(val, k_cycle_get_32());
  242. lv_mem_free(val);
  243. released_val = NULL;
  244. }
  245. }
  246. #endif // !CONFIG_SIMULATOR
  247. void aem_sliding_simulation(lv_dir_t dir, uint16_t steps)
  248. {
  249. if (os_current_get() != aem_get_task_id(AEM_UI_TASK))
  250. {
  251. 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));
  252. return;
  253. }
  254. #ifndef CONFIG_SIMULATOR
  255. if (released_val)
  256. return;
  257. struct input_value val;
  258. val.point.pessure_value = 1;
  259. released_val = (struct input_value *)lv_mem_alloc(sizeof(struct input_value));
  260. released_val->point.pessure_value = 1;
  261. lv_anim_t a;
  262. lv_anim_init(&a);
  263. lv_anim_set_var(&a, released_val);
  264. lv_anim_set_time(&a, 50);
  265. lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)sliding_simulation_exec_cb);
  266. lv_anim_set_deleted_cb(&a, (lv_anim_deleted_cb_t)sliding_simulation_deleted_cb);
  267. switch (dir)
  268. {
  269. case LV_DIR_LEFT:
  270. {
  271. val.point.gesture = 3;
  272. val.point.loc_x = (DEF_UI_WIDTH >> 1) + (steps >> 1);
  273. val.point.loc_y = DEF_UI_HEIGHT >> 1;
  274. released_val->point.gesture = 3;
  275. released_val->point.loc_x = (DEF_UI_WIDTH >> 1) - (steps >> 1);
  276. released_val->point.loc_y = DEF_UI_HEIGHT >> 1;
  277. lv_anim_set_values(&a, val.point.loc_x, released_val->point.loc_x);
  278. break;
  279. }
  280. case LV_DIR_RIGHT:
  281. {
  282. val.point.gesture = 4;
  283. val.point.loc_x = (DEF_UI_WIDTH >> 1) - (steps >> 1);
  284. val.point.loc_y = DEF_UI_HEIGHT >> 1;
  285. released_val->point.gesture = 4;
  286. released_val->point.loc_x = (DEF_UI_WIDTH >> 1) + (steps >> 1);
  287. released_val->point.loc_y = DEF_UI_HEIGHT >> 1;
  288. lv_anim_set_values(&a, val.point.loc_x, released_val->point.loc_x);
  289. break;
  290. }
  291. case LV_DIR_TOP:
  292. {
  293. val.point.gesture = 2;
  294. val.point.loc_x = DEF_UI_WIDTH >> 1;
  295. val.point.loc_y = (DEF_UI_HEIGHT >> 1) + (steps >> 1);
  296. released_val->point.gesture = 2;
  297. released_val->point.loc_x = DEF_UI_WIDTH >> 1;
  298. released_val->point.loc_y = (DEF_UI_HEIGHT >> 1) - (steps >> 1);
  299. lv_anim_set_values(&a, val.point.loc_y, released_val->point.loc_y);
  300. break;
  301. }
  302. case LV_DIR_BOTTOM:
  303. {
  304. val.point.gesture = 1;
  305. val.point.loc_x = DEF_UI_WIDTH >> 1;
  306. val.point.loc_y = (DEF_UI_HEIGHT >> 1) - (steps >> 1);
  307. released_val->point.gesture = 1;
  308. released_val->point.loc_x = DEF_UI_WIDTH >> 1;
  309. released_val->point.loc_y = (DEF_UI_HEIGHT >> 1) + (steps >> 1);
  310. lv_anim_set_values(&a, val.point.loc_y, released_val->point.loc_y);
  311. break;
  312. }
  313. default:
  314. break;
  315. }
  316. // tpkey_put_point(&val, k_cycle_get_32());
  317. lv_anim_start(&a);
  318. #else
  319. lv_win32_set_pointer_state(AEM_TP_STATE_PRESSED, dir, steps);
  320. #endif // !CONFIG_SIMULATOR
  321. }
  322. void aem_lv_assert_obj(const lv_obj_t *obj, const lv_obj_class_t *class_p)
  323. {
  324. if (obj == NULL)
  325. {
  326. AEM_LOG_E("The object is NULL");
  327. return;
  328. }
  329. if (lv_obj_has_class(obj, class_p) == false)
  330. {
  331. AEM_LOG_E("%p != %p Incompatible object type.", obj->class_p, class_p);
  332. }
  333. }