sys_event.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file system event notify
  8. */
  9. #if defined(CONFIG_SYS_LOG)
  10. #define SYS_LOG_NO_NEWLINE
  11. #ifdef SYS_LOG_DOMAIN
  12. #undef SYS_LOG_DOMAIN
  13. #endif
  14. #define SYS_LOG_DOMAIN "sys_event"
  15. #endif
  16. #include <os_common_api.h>
  17. #include <srv_manager.h>
  18. #include <mem_manager.h>
  19. #include <msg_manager.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <sys_event.h>
  23. #ifdef CONFIG_UI_MANAGER
  24. #include <ui_manager.h>
  25. #endif
  26. #ifdef CONFIG_TWS
  27. #include <btservice_api.h>
  28. #include <bt_manager.h>
  29. #endif
  30. static const struct sys_event_ui_map *sys_event_map = NULL;
  31. static int sys_event_map_size = 0;
  32. static void sys_event_send_message_cb(struct app_msg *msg, int result, void *not_used)
  33. {
  34. if (msg && msg->ptr)
  35. mem_free(msg->ptr);
  36. }
  37. void sys_event_send_message_new(uint32_t message, uint8_t cmd, void* extra_data, int extra_data_size)
  38. {
  39. struct app_msg msg = {0};
  40. if (extra_data && extra_data_size) {
  41. msg.ptr = mem_malloc(extra_data_size + 1);
  42. if (!msg.ptr){
  43. SYS_LOG_ERR("mem_malloc fail");
  44. return;
  45. }
  46. memset(msg.ptr, 0, extra_data_size + 1);
  47. memcpy(msg.ptr, extra_data, extra_data_size);
  48. msg.callback = sys_event_send_message_cb;
  49. }
  50. #ifdef CONFIG_TWS
  51. #ifndef CONFIG_SNOOP_LINK_TWS
  52. if (bt_manager_tws_get_dev_role() == BTSRV_TWS_MASTER) {
  53. bt_manager_tws_send_event(TWS_SYSTEM_EVENT, message);
  54. }
  55. #endif
  56. #endif
  57. msg.type = message;
  58. msg.cmd = cmd;
  59. send_async_msg("main", &msg);
  60. }
  61. #ifdef CONFIG_AEM_WATCH_SUPPORT
  62. extern void aem_input_event_handle(uint32_t key_event);
  63. void sys_event_report_input(uint32_t key_event)
  64. {
  65. aem_input_event_handle(key_event);
  66. }
  67. #else
  68. void sys_event_report_input(uint32_t key_event)
  69. {
  70. struct app_msg msg = {0};
  71. msg.type = MSG_KEY_INPUT;
  72. msg.value = key_event;
  73. send_async_msg("main", &msg);
  74. }
  75. #endif
  76. void sys_event_notify(uint32_t event)
  77. {
  78. #ifdef CONFIG_TWS
  79. #ifndef CONFIG_SNOOP_LINK_TWS
  80. if (bt_manager_tws_get_dev_role() == BTSRV_TWS_MASTER &&
  81. event != SYS_EVENT_TWS_CONNECTED &&
  82. event != SYS_EVENT_TWS_DISCONNECTED) {
  83. /* Tws master/slave all will receive TWS_CONNECTED/TWS_DISCONNECTED event */
  84. bt_manager_tws_send_event_sync(TWS_UI_EVENT, event);
  85. return;
  86. }
  87. #endif
  88. #endif
  89. struct app_msg msg = {0};
  90. msg.type = MSG_SYS_EVENT;
  91. msg.cmd = event;
  92. send_async_msg("main", &msg);
  93. }
  94. void sys_event_map_register(const struct sys_event_ui_map *event_map, int size, int sys_view_id)
  95. {
  96. if (!sys_event_map) {
  97. sys_event_map = event_map;
  98. sys_event_map_size = size;
  99. } else {
  100. SYS_LOG_ERR("failed\n");
  101. }
  102. }
  103. void sys_event_process(uint32_t event)
  104. {
  105. int ui_event = 0;
  106. if (!sys_event_map)
  107. return;
  108. for (int i = 0; i < sys_event_map_size; i++) {
  109. if (sys_event_map[i].sys_event == event) {
  110. ui_event = sys_event_map[i].ui_event;
  111. break;
  112. }
  113. }
  114. if (ui_event != 0) {
  115. #ifdef CONFIG_UI_MANAGER
  116. SYS_LOG_INF("ui_event %d\n", ui_event);
  117. ui_manager_send_async(0, MSG_VIEW_PAINT, ui_event);
  118. #endif
  119. }
  120. }