1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2023-05-26     Chushicheng  the first version
9  */
10 /*
11  * Program listing: This is a touch device usage routine
12  * The routine exports touch_sample commands to the control terminal
13  * Command invocation format: touch_sample
14  * Program function: The terminal prints the coordinates of the touch point
15 */
16 #include <rtdevice.h>
17 #include "drv_gt911.h"
18 
touch_sample(void)19 static int touch_sample(void)
20 {
21     gt911_input_t ctp_input;
22 
23     rt_device_t dev = rt_device_find("capt");
24 
25     RT_ASSERT(dev != RT_NULL);
26 
27     capt_t *capt = (capt_t*)dev->user_data;
28     while(1)
29     {
30         gt911_ctp_read(&capt->gt911, &ctp_input);
31 
32         for (rt_uint8_t  i = 0; i < ctp_input.num_pos; i++)
33         {
34             /* Found track ID #0 */
35             if (ctp_input.pos[i].id == 0)
36             {
37                 rt_kprintf("x:%d, y:%d\r\n", capt->gt911.pos_y_max - ctp_input.pos[i].pos_y, ctp_input.pos[i].pos_x);
38             }
39         }
40 
41         rt_thread_mdelay(16);
42     }
43 
44     return RT_EOK;
45 }
46 
47 MSH_CMD_EXPORT(touch_sample, the capt touch test);
48