test_touch_element.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* ---------------------------------------------------------- README ------------------------------------------------
  2. * This doc is aimed at explain some important code block and do some records for the test result, if developer or
  3. * test-owner has some question in reading this code implementation, please read it first.
  4. *
  5. * CODE Block:
  6. * `code-block-1`: Touch Element lib need some time to finish the initialization so as to configure the right threshold.
  7. * Since some hardware issue(Must to pass 2 times "meas_done" interrupt), Touch Element lib will spend
  8. * some time(Maybe <30ms) to finish the initialization, every operations (interrupts) happen to touch
  9. * sensor will be ignored before initialization. That's why "vTaskDelay()" could be saw in after call
  10. * "touch_element_start()". However, this just for the unit test, in the real application, users don't
  11. * need to delay something.
  12. *
  13. * NOTES:
  14. * `Simulator`: Currently the event simulator depend on the touch sensor driver and play some "hack" in some register so
  15. * as to raise a FAKE interrupt. It means that Touch Element lib test case must be burned on dev-kit and keep
  16. * the touch channel as clean as possible, ESP32-S2-Saola is good test board. //TODO: Remove the dependent of touch sensor driver.
  17. ------------------------------------------------------------------------------------------------------------------ */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <time.h>
  22. #include "freertos/FreeRTOS.h"
  23. #include "freertos/task.h"
  24. #include "freertos/queue.h"
  25. #include "freertos/semphr.h"
  26. #include "unity.h"
  27. #include "touch_element/touch_button.h"
  28. #include "touch_element/touch_slider.h"
  29. #include "touch_element/touch_matrix.h"
  30. typedef struct {
  31. QueueHandle_t valid_msg_handle;
  32. SemaphoreHandle_t response_sig_handle;
  33. } test_monitor_t;
  34. /* ------------------------------------------------------------------------------------------------------------------ */
  35. extern void test_button_event_simulator(touch_button_handle_t button_handle, touch_button_event_t button_event);
  36. extern void test_button_handler(touch_button_handle_t handle, touch_button_message_t *message, void *arg);
  37. extern void test_button_event_check(touch_elem_message_t *valid_message, touch_elem_message_t *current_message);
  38. extern void test_button_event_trigger_and_check(touch_button_handle_t handle, touch_button_event_t button_event);
  39. extern void test_button_callback_trigger_and_check(touch_button_handle_t handle, touch_button_event_t button_event, bool should_trigger, test_monitor_t *monitor);
  40. extern void test_slider_event_simulator(touch_slider_handle_t slider_handle, touch_slider_event_t slider_event, uint32_t random);
  41. extern void test_slider_event_check(touch_elem_message_t *valid_message, touch_elem_message_t *current_message);
  42. extern void test_matrix_event_simulator(touch_matrix_handle_t matrix_handle, touch_matrix_event_t matrix_event, uint32_t pos_index);
  43. extern void test_matrix_event_check(touch_elem_message_t *valid_message, touch_elem_message_t *current_message);
  44. /* ------------------------------------------------------------------------------------------------------------------ */
  45. static void test_waterproof_event_simulator(touch_pad_t guard_channel, touch_button_event_t guard_state);
  46. static void test_system_waterproof_guard(void);
  47. static void test_integrat_btn_sld_mat(void);
  48. static void test_integration_monitor_task(void *arg);
  49. /* ------------------------------------------------------------------------------------------------------------------ */
  50. TEST_CASE("Touch element integration test", "[touch_element]")
  51. {
  52. touch_elem_global_config_t global_config = TOUCH_ELEM_GLOBAL_DEFAULT_CONFIG();
  53. TEST_ESP_OK(touch_element_install(&global_config));
  54. test_integrat_btn_sld_mat();
  55. touch_element_uninstall();
  56. }
  57. TEST_CASE("Touch element waterproof test", "[touch_element]")
  58. {
  59. touch_elem_global_config_t global_config = TOUCH_ELEM_GLOBAL_DEFAULT_CONFIG();
  60. TEST_ESP_OK(touch_element_install(&global_config));
  61. test_system_waterproof_guard(); //TODO: add waterproof work with slider and matrix
  62. touch_element_uninstall();
  63. }
  64. static void test_system_waterproof_guard(void)
  65. {
  66. static const touch_pad_t button_channel_array[12] = {
  67. TOUCH_PAD_NUM1,
  68. TOUCH_PAD_NUM2,
  69. TOUCH_PAD_NUM3,
  70. TOUCH_PAD_NUM4,
  71. TOUCH_PAD_NUM5,
  72. TOUCH_PAD_NUM6,
  73. TOUCH_PAD_NUM7,
  74. TOUCH_PAD_NUM8,
  75. TOUCH_PAD_NUM9,
  76. TOUCH_PAD_NUM10,
  77. TOUCH_PAD_NUM11,
  78. TOUCH_PAD_NUM12
  79. };
  80. const uint8_t BUTTON_CHANNEL_NUM = sizeof(button_channel_array) / sizeof(touch_pad_t);
  81. test_monitor_t monitor;
  82. touch_button_handle_t button_handle[BUTTON_CHANNEL_NUM];
  83. monitor.valid_msg_handle = xQueueCreate(10, sizeof(touch_elem_message_t));
  84. monitor.response_sig_handle = xSemaphoreCreateBinary();
  85. TEST_ASSERT(monitor.valid_msg_handle != NULL || monitor.response_sig_handle != NULL);
  86. touch_button_global_config_t global_config = TOUCH_BUTTON_GLOBAL_DEFAULT_CONFIG();
  87. TEST_ESP_OK(touch_button_install(&global_config));
  88. for (int i = 0; i < BUTTON_CHANNEL_NUM; i++) {
  89. touch_button_config_t button_config = {
  90. .channel_num = button_channel_array[i],
  91. .channel_sens = 0.1F
  92. };
  93. TEST_ESP_OK(touch_button_create(&button_config, &button_handle[i]));
  94. TEST_ESP_OK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE, (void *)&monitor));
  95. TEST_ESP_OK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_CALLBACK));
  96. TEST_ESP_OK(touch_button_set_callback(button_handle[i], test_button_handler));
  97. }
  98. printf("Touch Element waterproof guard sensor test start\n");
  99. srandom((unsigned int)time(NULL));
  100. {//No use waterproof guard sensor
  101. touch_elem_waterproof_config_t waterproof_config = {
  102. .guard_channel = TOUCH_WATERPROOF_GUARD_NOUSE,
  103. .guard_sensitivity = 0.0F
  104. };
  105. TEST_ESP_OK(touch_element_waterproof_install(&waterproof_config));
  106. TEST_ESP_OK(touch_element_start());
  107. vTaskDelay(pdMS_TO_TICKS(500)); //Mention in README, code-block-1
  108. for (int i = 0; i < 10; i++) { //Start state test
  109. printf("Touch Element waterproof no-use guard sensor test... (%d/10)\n", i + 1);
  110. touch_button_handle_t current_handle = button_handle[random() % 12];
  111. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_PRESS, true, &monitor);
  112. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_RELEASE, true, &monitor);
  113. }
  114. TEST_ESP_OK(touch_element_stop());
  115. touch_element_waterproof_uninstall();
  116. }
  117. {//Use waterproof guard sensor(Add all handles)
  118. touch_elem_waterproof_config_t waterproof_config = {
  119. .guard_channel = TOUCH_PAD_NUM13,
  120. .guard_sensitivity = 0.1F
  121. };
  122. TEST_ESP_OK(touch_element_waterproof_install(&waterproof_config));
  123. for (int i = 0; i < BUTTON_CHANNEL_NUM; i++) {
  124. TEST_ESP_OK(touch_element_waterproof_add(button_handle[i]));
  125. }
  126. TEST_ESP_OK(touch_element_start());
  127. vTaskDelay(pdMS_TO_TICKS(500)); //Mention in README, code-block-1
  128. for (int i = 0; i < 10; i++) {
  129. printf("Touch Element waterproof use guard sensor random trigger test... (%d/10)\n", i + 1);
  130. bool should_trigger = random() % 2;
  131. if (should_trigger) {
  132. touch_button_handle_t current_handle = button_handle[random() % 12];
  133. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_PRESS, should_trigger, &monitor);
  134. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_RELEASE, should_trigger, &monitor);
  135. } else {
  136. test_waterproof_event_simulator(waterproof_config.guard_channel, TOUCH_BUTTON_EVT_ON_PRESS); //Waterproof guard sensor trigger
  137. touch_button_handle_t current_handle = button_handle[random() % 12];
  138. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_PRESS, should_trigger, &monitor);
  139. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_RELEASE, should_trigger, &monitor);
  140. test_waterproof_event_simulator(waterproof_config.guard_channel, TOUCH_BUTTON_EVT_ON_RELEASE); //Waterproof guard sensor release
  141. }
  142. }
  143. TEST_ESP_OK(touch_element_stop());
  144. touch_element_waterproof_uninstall();
  145. }
  146. {//Put half button handles into guard ring
  147. const uint8_t protect_handle_threshold = BUTTON_CHANNEL_NUM / 2;
  148. touch_elem_waterproof_config_t waterproof_config = {
  149. .guard_channel = TOUCH_PAD_NUM13,
  150. .guard_sensitivity = 0.1F
  151. };
  152. TEST_ESP_OK(touch_element_waterproof_install(&waterproof_config));
  153. for (int i = 0; i < protect_handle_threshold; i++) {
  154. TEST_ESP_OK(touch_element_waterproof_add(button_handle[i]));
  155. }
  156. TEST_ESP_OK(touch_element_start());
  157. vTaskDelay(pdMS_TO_TICKS(500)); //Mention in README, code-block-1
  158. for (int i = 0; i < 10; i++) {
  159. printf("Touch Element waterproof use guard sensor test(guard sensor is triggered will half button handles)... (%d/10)\n", i + 1);
  160. test_waterproof_event_simulator(waterproof_config.guard_channel, TOUCH_BUTTON_EVT_ON_PRESS); //Waterproof guard sensor trigger
  161. uint32_t handle_index = random() % 12;
  162. touch_button_handle_t current_handle = button_handle[handle_index];
  163. bool should_trigger = (handle_index < protect_handle_threshold) ? false : true;
  164. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_PRESS, should_trigger, &monitor);
  165. test_button_callback_trigger_and_check(current_handle, TOUCH_BUTTON_EVT_ON_RELEASE, should_trigger, &monitor);
  166. test_waterproof_event_simulator(waterproof_config.guard_channel, TOUCH_BUTTON_EVT_ON_RELEASE); //Waterproof guard sensor release
  167. }
  168. TEST_ESP_OK(touch_element_stop());
  169. touch_element_waterproof_uninstall();
  170. }
  171. for (int i = 0; i < BUTTON_CHANNEL_NUM; i++) {
  172. TEST_ESP_OK(touch_button_delete(button_handle[i]));
  173. }
  174. touch_button_uninstall();
  175. vQueueDelete(monitor.valid_msg_handle);
  176. vSemaphoreDelete(monitor.response_sig_handle);
  177. printf("Touch Element waterproof guard sensor test finish\n");
  178. }
  179. static void test_waterproof_event_simulator(touch_pad_t guard_channel, touch_button_event_t guard_state)
  180. {
  181. if (guard_state == TOUCH_BUTTON_EVT_ON_PRESS) {
  182. touch_pad_set_cnt_mode(guard_channel, TOUCH_PAD_SLOPE_3, TOUCH_PAD_TIE_OPT_DEFAULT);
  183. } else if (guard_state == TOUCH_BUTTON_EVT_ON_RELEASE) {
  184. touch_pad_set_cnt_mode(guard_channel, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_DEFAULT);
  185. } else {
  186. printf("guard sensor simulator doesn't support this operation\n");
  187. }
  188. /* Fixme: If the normal instance and guard sensor trigger at the same time, guard sensor will lock the state failed */
  189. vTaskDelay(pdMS_TO_TICKS(100));
  190. }
  191. static void test_integrat_btn_sld_mat(void)
  192. {
  193. static const touch_pad_t button_channel_array[3] = {
  194. TOUCH_PAD_NUM1,
  195. TOUCH_PAD_NUM2,
  196. TOUCH_PAD_NUM3
  197. };
  198. static const float button_sens_array[3] = {
  199. 0.1F,
  200. 0.1F,
  201. 0.1F
  202. };
  203. static const touch_pad_t slider_channel_array[5] = {
  204. TOUCH_PAD_NUM4,
  205. TOUCH_PAD_NUM5,
  206. TOUCH_PAD_NUM6,
  207. TOUCH_PAD_NUM7,
  208. TOUCH_PAD_NUM8
  209. };
  210. static const float slider_sens_array[5] = {
  211. 0.1F,
  212. 0.1F,
  213. 0.1F,
  214. 0.1F,
  215. 0.1F
  216. };
  217. static const touch_pad_t x_axis_channel[3] = {
  218. TOUCH_PAD_NUM9,
  219. TOUCH_PAD_NUM10,
  220. TOUCH_PAD_NUM11,
  221. };
  222. static const touch_pad_t y_axis_channel[3] = {
  223. TOUCH_PAD_NUM12,
  224. TOUCH_PAD_NUM13,
  225. TOUCH_PAD_NUM14,
  226. };
  227. static const float x_axis_channel_sens[3] = {
  228. 0.1F,
  229. 0.1F,
  230. 0.1F,
  231. };
  232. static const float y_axis_channel_sens[3] = {
  233. 0.1F,
  234. 0.1F,
  235. 0.1F,
  236. };
  237. const uint8_t BUTTON_CHANNEL_NUM = sizeof(button_channel_array) / sizeof(touch_pad_t);
  238. const uint8_t SLIDER_CHANNEL_NUM = sizeof(slider_channel_array) / sizeof(touch_pad_t);
  239. const uint8_t MATRIX_CHANNEL_NUM_X = sizeof(x_axis_channel) / sizeof(touch_pad_t);
  240. const uint8_t MATRIX_CHANNEL_NUM_Y = sizeof(y_axis_channel) / sizeof(touch_pad_t);
  241. printf("Integration test(button + slider + matrix) start\n");
  242. BaseType_t os_ret;
  243. touch_button_handle_t button_handle[BUTTON_CHANNEL_NUM];
  244. touch_slider_handle_t slider_handle;
  245. touch_matrix_handle_t matrix_handle;
  246. test_monitor_t monitor;
  247. TaskHandle_t task_handle = NULL;
  248. monitor.valid_msg_handle = xQueueCreate(10, sizeof(touch_elem_message_t));
  249. monitor.response_sig_handle = xSemaphoreCreateBinary();
  250. os_ret = xTaskCreate(&test_integration_monitor_task, "test_integration_monitor_task", 4096, (void *)&monitor, 5, &task_handle);
  251. TEST_ASSERT(monitor.valid_msg_handle != NULL && monitor.response_sig_handle != NULL && os_ret == pdPASS);
  252. touch_button_global_config_t button_global_config = TOUCH_BUTTON_GLOBAL_DEFAULT_CONFIG();
  253. touch_slider_global_config_t slider_global_config = TOUCH_SLIDER_GLOBAL_DEFAULT_CONFIG();
  254. touch_matrix_global_config_t matrix_global_config = TOUCH_MATRIX_GLOBAL_DEFAULT_CONFIG();
  255. TEST_ESP_OK(touch_button_install(&button_global_config));
  256. TEST_ESP_OK(touch_slider_install(&slider_global_config));
  257. TEST_ESP_OK(touch_matrix_install(&matrix_global_config));
  258. for (int i = 0; i < BUTTON_CHANNEL_NUM; i++) {
  259. touch_button_config_t button_config = {
  260. .channel_num = button_channel_array[i],
  261. .channel_sens = button_sens_array[i]
  262. };
  263. TEST_ESP_OK(touch_button_create(&button_config, &button_handle[i]));
  264. TEST_ESP_OK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE, NULL));
  265. TEST_ESP_OK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
  266. }
  267. touch_slider_config_t slider_config = {
  268. .channel_array = slider_channel_array,
  269. .sensitivity_array = slider_sens_array,
  270. .channel_num = SLIDER_CHANNEL_NUM,
  271. .position_range = 101
  272. };
  273. TEST_ESP_OK(touch_slider_create(&slider_config, &slider_handle));
  274. TEST_ESP_OK(touch_slider_subscribe_event(slider_handle, TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE, NULL));
  275. TEST_ESP_OK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
  276. touch_matrix_config_t matrix_config = {
  277. .x_channel_array = x_axis_channel,
  278. .y_channel_array = y_axis_channel,
  279. .x_sensitivity_array = x_axis_channel_sens,
  280. .y_sensitivity_array = y_axis_channel_sens,
  281. .x_channel_num = MATRIX_CHANNEL_NUM_X,
  282. .y_channel_num = MATRIX_CHANNEL_NUM_Y
  283. };
  284. TEST_ESP_OK(touch_matrix_create(&matrix_config, &matrix_handle));
  285. TEST_ESP_OK(touch_matrix_subscribe_event(matrix_handle, TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE, NULL));
  286. TEST_ESP_OK(touch_matrix_set_dispatch_method(matrix_handle, TOUCH_ELEM_DISP_EVENT));
  287. TEST_ESP_OK(touch_element_start());
  288. vTaskDelay(pdMS_TO_TICKS(500)); //Mention in README, code-block-1
  289. srandom((unsigned int)time(NULL));
  290. for (int i = 0; i < 30; i++) {
  291. printf("Integration test... (%d/30)\n", i + 1);
  292. touch_elem_message_t valid_message;
  293. valid_message.element_type = (random() % (TOUCH_ELEM_TYPE_MATRIX + 1));
  294. if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) {
  295. uint32_t button_index = random() % BUTTON_CHANNEL_NUM;
  296. valid_message.handle = button_handle[button_index];
  297. touch_button_message_t button_message = {
  298. .event = TOUCH_BUTTON_EVT_ON_PRESS
  299. };
  300. memcpy(valid_message.child_msg, &button_message, sizeof(button_message)); //Construct child message
  301. xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
  302. test_button_event_simulator(valid_message.handle, button_message.event);
  303. } else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) {
  304. valid_message.handle = slider_handle;
  305. touch_slider_message_t slider_message = {
  306. .event = TOUCH_SLIDER_EVT_ON_PRESS,
  307. .position = 0 //No check
  308. };
  309. memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message)); //Construct child message
  310. xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
  311. test_slider_event_simulator(valid_message.handle, slider_message.event, 1);
  312. } else if (valid_message.element_type == TOUCH_ELEM_TYPE_MATRIX) {
  313. uint32_t matrix_x_axis_index = random() % MATRIX_CHANNEL_NUM_X;
  314. uint32_t matrix_y_axis_index = random() % MATRIX_CHANNEL_NUM_Y;
  315. valid_message.handle = matrix_handle;
  316. touch_matrix_message_t matrix_message = {
  317. .event = TOUCH_MATRIX_EVT_ON_PRESS,
  318. .position.x_axis = matrix_x_axis_index,
  319. .position.y_axis = matrix_y_axis_index,
  320. .position.index = matrix_x_axis_index * MATRIX_CHANNEL_NUM_Y + matrix_y_axis_index
  321. };
  322. memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message)); //Construct child message
  323. xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
  324. test_matrix_event_simulator(valid_message.handle, matrix_message.event, matrix_message.position.index);
  325. }
  326. os_ret = xSemaphoreTake(monitor.response_sig_handle, pdMS_TO_TICKS(500));
  327. TEST_ASSERT_MESSAGE(os_ret == pdPASS, "response queue timeout (500ms)");
  328. if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) {
  329. touch_button_message_t button_message;
  330. button_message.event = TOUCH_BUTTON_EVT_ON_RELEASE;
  331. memcpy(valid_message.child_msg, &button_message, sizeof(button_message));
  332. xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
  333. test_button_event_simulator(valid_message.handle, button_message.event);
  334. } else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) {
  335. touch_slider_message_t slider_message;
  336. slider_message.event = TOUCH_SLIDER_EVT_ON_RELEASE;
  337. memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message));
  338. xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
  339. test_slider_event_simulator(valid_message.handle, slider_message.event, 1);
  340. } else if (valid_message.element_type == TOUCH_ELEM_TYPE_MATRIX) {
  341. touch_matrix_message_t matrix_message;
  342. matrix_message.event = TOUCH_MATRIX_EVT_ON_RELEASE;
  343. memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message));
  344. xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
  345. const touch_matrix_message_t *matrix_message_ptr = touch_matrix_get_message(&valid_message);
  346. test_matrix_event_simulator(valid_message.handle, matrix_message.event, matrix_message_ptr->position.index);
  347. }
  348. os_ret = xSemaphoreTake(monitor.response_sig_handle, pdMS_TO_TICKS(500));
  349. TEST_ASSERT_MESSAGE(os_ret == pdPASS, "response queue timeout (500ms)");
  350. }
  351. TEST_ESP_OK(touch_element_stop());
  352. for (int i = 0; i < BUTTON_CHANNEL_NUM; i++) {
  353. TEST_ESP_OK(touch_button_delete(button_handle[i]));
  354. }
  355. TEST_ESP_OK(touch_slider_delete(slider_handle));
  356. TEST_ESP_OK(touch_matrix_delete(matrix_handle));
  357. touch_button_uninstall();
  358. touch_slider_uninstall();
  359. touch_matrix_uninstall();
  360. while (eTaskGetState(task_handle) == eRunning) {
  361. vTaskDelay(pdTICKS_TO_MS(1));
  362. }
  363. vTaskDelete(task_handle);
  364. vQueueDelete(monitor.valid_msg_handle);
  365. vSemaphoreDelete(monitor.response_sig_handle);
  366. printf("Integration test(button + slider + matrix) finish\n");
  367. }
  368. static void test_integration_monitor_task(void *arg)
  369. {
  370. test_monitor_t *monitor = (test_monitor_t *)arg;
  371. BaseType_t os_ret;
  372. touch_elem_message_t current_message, valid_message;
  373. while (1) {
  374. touch_element_message_receive(&current_message, portMAX_DELAY);
  375. os_ret = xQueueReceive(monitor->valid_msg_handle, &valid_message, pdMS_TO_TICKS(500)); //Get the valid message for the verification, 500ms timeout
  376. TEST_ASSERT_MESSAGE(os_ret == pdPASS, "trigger queue timeout (500ms)");
  377. if (current_message.element_type == TOUCH_ELEM_TYPE_BUTTON) {
  378. test_button_event_check(&valid_message, &current_message);
  379. } else if (current_message.element_type == TOUCH_ELEM_TYPE_SLIDER) {
  380. test_slider_event_check(&valid_message, &current_message);
  381. } else if (current_message.element_type == TOUCH_ELEM_TYPE_MATRIX) {
  382. test_matrix_event_check(&valid_message, &current_message);
  383. }
  384. xSemaphoreGive(monitor->response_sig_handle);
  385. }
  386. }