aem_def_keypad.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. 
  2. #include "aem_log.h"
  3. #include "aem_keypad.h"
  4. #include "aem_init.h"
  5. #include "aem_project.h"
  6. #include "aem_app_id.h"
  7. #include "aem_app_fwk.h"
  8. #include "aem_app_comm.h"
  9. #include "aem_launch_mgr.h"
  10. #include "aem_data_share.h"
  11. #include "aem_app_event.h"
  12. #include "aem_pop_if.h"
  13. #include "aem_pop_window_id.h"
  14. #include "aem_ble_data_share.h"
  15. #include "aem_watchface_mgr.h"
  16. #include "aem_low_power.h"
  17. #include "aem_sys.h"
  18. static void go_to_launch(void)
  19. {
  20. #ifndef CONFIG_SIMULATOR
  21. if (!is_aem_low_power_mode() || (is_aem_low_power_mode() && aem_get_battery_percentage() >= 20))
  22. {
  23. aem_goback_to_launch();
  24. }
  25. else
  26. #else
  27. if (!aem_app_is_actived(AEM_APP_ID_POWER_SAVING))
  28. {
  29. aem_goback_to_launch();
  30. }
  31. else
  32. #endif
  33. {
  34. if (aem_app_is_actived(AEM_APP_ID_POP_WINDOW))
  35. {
  36. aem_app_close(AEM_APP_ID_POP_WINDOW);
  37. }
  38. }
  39. }
  40. static void home_key_process(void)
  41. {
  42. if (aem_app_is_actived(AEM_APP_ID_APP_LIST))
  43. {
  44. go_to_launch();
  45. }
  46. else
  47. {
  48. if (aem_app_is_actived(AEM_APP_ID_LAUNCH))
  49. {
  50. if (aem_activity_is_actived(AEM_APP_LAUNCH))
  51. {
  52. aem_app_run(AEM_APP_ID_APP_LIST);
  53. }
  54. else
  55. {
  56. go_to_launch();
  57. }
  58. }
  59. else
  60. {
  61. if (aem_get_enter_app_from_applist() && !aem_app_is_actived(AEM_APP_ID_POP_WINDOW))
  62. {
  63. aem_app_run(AEM_APP_ID_APP_LIST);
  64. }
  65. else
  66. {
  67. go_to_launch();
  68. }
  69. }
  70. }
  71. }
  72. static void shortcut_key_process(void)
  73. {
  74. if (aem_app_is_actived(AEM_APP_ID_LAUNCH) || aem_app_is_actived(AEM_APP_ID_APP_LIST))
  75. {
  76. aem_app_run(aem_share_get_shortcut_app_id());
  77. }
  78. }
  79. static void shortcut_key_long_click_process(void)
  80. {
  81. aem_pop_power_info_t info = {0};
  82. info.head.pop_id = AEM_POP_ID_POWER;
  83. AEM_LOG_I("power_pop!!!\r\n");
  84. aem_send_app_evt_msg(APP_EVT_POP_WINDOW, (uint8_t *)&info, sizeof(aem_pop_power_info_t));
  85. }
  86. #define SCREEN_KEY_TICK 500
  87. static uint32_t s_scr_switch_key_tick = 0;
  88. static void screen_switch_key_click_process(void)
  89. {
  90. if (lv_tick_get() - s_scr_switch_key_tick > SCREEN_KEY_TICK)
  91. {
  92. AEM_LOG_I("screen key screen off \r\n");
  93. aem_screen_force_off();
  94. s_scr_switch_key_tick = lv_tick_get();
  95. }
  96. AEM_LOG_I("aem_keypad_do_event screen key tick:%d \r\n", s_scr_switch_key_tick);
  97. }
  98. static int32_t default_keypad_handler(aem_key_evt_info_t *evt_info)
  99. {
  100. if (NULL == evt_info)
  101. {
  102. return 0;
  103. }
  104. AEM_LOG_I("def_keypad id:%s click:%s \n", get_aem_key_name(evt_info->key_id), get_aem_key_click_type_name(evt_info->key_click_type));
  105. if (evt_info->key_id == AEM_HOME_KEY)
  106. {
  107. if (evt_info->key_click_type == AEM_KEY_SINGLE_CLICK)
  108. {
  109. home_key_process();
  110. }
  111. else if (evt_info->key_click_type == AEM_KEY_LONG_6S)
  112. {
  113. aem_flash_write_allow_set_flag(false);
  114. }
  115. else
  116. {
  117. aem_flash_write_allow_set_flag(true);
  118. }
  119. }
  120. else if (evt_info->key_id == AEM_SHORTCUT_KEY)
  121. {
  122. if (evt_info->key_click_type == AEM_KEY_SINGLE_CLICK)
  123. {
  124. shortcut_key_process();
  125. }
  126. else if (evt_info->key_click_type == AEM_KEY_LONG_6S)
  127. {
  128. shortcut_key_long_click_process();
  129. }
  130. }
  131. else if (evt_info->key_id == AEM_SCREEN_SWITCH_KEY)
  132. {
  133. if (evt_info->key_click_type == AEM_KEY_SINGLE_CLICK)
  134. {
  135. screen_switch_key_click_process();
  136. }
  137. }
  138. return 0;
  139. }
  140. int aem_def_keypad_init(void)
  141. {
  142. AEM_LOG_I("aem_def_keypad_init \r\n");
  143. aem_keypad_default_handler_register(default_keypad_handler);
  144. return 0;
  145. }
  146. AEM_INIT(aem_def_keypad_init, UI_SERVICE_INIT, 0);