test_touch_element.c 21 KB

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