-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_tslib.c
103 lines (94 loc) · 2.67 KB
/
main_tslib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
文件名 : main_tslib.c
作者 : Octopus
博客 : https://blog.csdn.net/Octopus1633?
描述 : 识别用户在触摸屏上的操作,如:单击、双击、长按、移动、放大、缩小
交叉编译示例 : $ {CC} touch_tslib.c main_tslib.c -o touch_tslib -lts
程序运行示例 : $ ./voice touch_tslib
***************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include "touch_tslib.h"
void touch_event_handler(touch_struct *touch_data)
{
uint16_t m_event = touch_data->event;
/*单击*/
if(0 != (m_event & TOUCH_CLICK))
{
printf("操作:单击,坐标:(%d,%d)\n",
touch_data->one_clickData.x,
touch_data->one_clickData.y);
}
/*双击*/
else if(0 != (m_event & TOUCH_DOUBLECLICK))
{
printf("操作:双击,坐标:(%d,%d)\n",
touch_data->one_clickData.x,
touch_data->one_clickData.y);
}
/*长按*/
else if(0 != (m_event & TOUCH_LONGPRESS))
{
printf("操作:长按,坐标:(%d,%d)\n",
touch_data->one_clickData.x,
touch_data->one_clickData.y);
}
/*长按松开*/
else if(0 != (m_event & TOUCH_LOOSE))
{
printf("操作:长按松开,坐标:(%d,%d)\n",
touch_data->one_clickData.x,
touch_data->one_clickData.y);
}
/*移动*/
else if(0 != (m_event & TOUCH_MOVE))
{
printf("操作:移动,坐标:(%d,%d),坐标偏移:(%d,%d)\n",
touch_data->one_clickData.x,
touch_data->one_clickData.y,
touch_data->one_clickData.offset_x,
touch_data->one_clickData.offset_y);
}
/*放大*/
else if(0 != (m_event & TOUCH_MAGNIFY))
{
printf("操作:放大,中心坐标:(%d,%d),距离偏移:%d\n",
touch_data->more_clickData.centre_x,
touch_data->more_clickData.centre_y,
touch_data->more_clickData.offset_distance);
}
/*缩小*/
else if(0 != (m_event & TOUCH_SHRINK))
{
printf("操作:缩小,中心坐标:(%d,%d),距离偏移:%d\n",
touch_data->more_clickData.centre_x,
touch_data->more_clickData.centre_y,
touch_data->more_clickData.offset_distance);
}
}
void *touch_thread(void *arg)
{
while(1)
{
touch_process(touch_event_handler);
}
}
int main()
{
pthread_t pid;
/*创建屏幕数据处理线程*/
pthread_create(&pid,NULL,touch_thread,NULL);
/*分离线程*/
pthread_detach(pid);
/*初始化*/
touch_init();
while(1)
{
sleep(1);
}
/*释放*/
touch_free();
}