-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2dcafc2
Showing
11 changed files
with
936 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"/usr/include/**", | ||
"/opt/st/stm32mp1/3.1-snapshot/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi/usr/include/**" | ||
], | ||
"defines": [], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "gnu17", | ||
"cppStandard": "c++98", | ||
"intelliSenseMode": "linux-gcc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <unistd.h> | ||
#include <signal.h> | ||
#include <sys/time.h> | ||
#include "touch.h" | ||
|
||
void touch_handle(touch_struct *touch_data) | ||
{ | ||
uint16_t m_event = touch_data->type; | ||
|
||
/*单击*/ | ||
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_PRESS)) | ||
{ | ||
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 handle() | ||
{ | ||
printf("test\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
while(1) | ||
{ | ||
touch_process(touch_handle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/*************************************************************************** | ||
文件名 : 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(); | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <pthread.h> | ||
#include <signal.h> | ||
#include <time.h> | ||
|
||
#define TIMER_INTERVAL 1 | ||
#define TIMER_COUNT 5 | ||
|
||
pthread_key_t timer_key; // 线程特定数据键 | ||
|
||
void timer_handler(int sig) { | ||
int *count = pthread_getspecific(timer_key); // 获取定时器信息 | ||
printf("Timer %ld count: %d\n", pthread_self(), ++(*count)); | ||
} | ||
|
||
void *thread_func(void *arg) { | ||
int count = 0; | ||
struct sigevent sev; | ||
timer_t timer; | ||
|
||
// 创建定时器 | ||
sev.sigev_notify = SIGEV_SIGNAL; | ||
sev.sigev_signo = SIGALRM; | ||
sev.sigev_value.sival_ptr = &timer; | ||
if (timer_create(CLOCK_REALTIME, &sev, &timer) == -1) { | ||
perror("timer_create"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
// 设置定时器 | ||
struct itimerspec its; | ||
its.it_interval.tv_sec = TIMER_INTERVAL; | ||
its.it_interval.tv_nsec = 0; | ||
its.it_value.tv_sec = TIMER_INTERVAL; | ||
its.it_value.tv_nsec = 0; | ||
if (timer_settime(timer, 0, &its, NULL) == -1) { | ||
perror("timer_settime"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
// 分配线程特定数据 | ||
pthread_setspecific(timer_key, &count); | ||
|
||
// 等待定时器结束 | ||
while (count < TIMER_COUNT) { | ||
sleep(1); | ||
} | ||
|
||
// 销毁定时器 | ||
timer_delete(timer); | ||
|
||
pthread_exit(NULL); | ||
} | ||
|
||
int main() { | ||
pthread_t thread1, thread2; | ||
|
||
// 创建线程特定数据键 | ||
if (pthread_key_create(&timer_key, NULL) != 0) { | ||
perror("pthread_key_create"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
// 创建线程1 | ||
if (pthread_create(&thread1, NULL, thread_func, NULL) != 0) { | ||
perror("pthread_create"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
// 创建线程2 | ||
if (pthread_create(&thread2, NULL, thread_func, NULL) != 0) { | ||
perror("pthread_create"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
// 等待线程结束 | ||
pthread_join(thread1, NULL); | ||
pthread_join(thread2, NULL); | ||
|
||
// 销毁线程特定数据键 | ||
pthread_key_delete(timer_key); | ||
|
||
return 0; | ||
} |
Binary file not shown.
Oops, something went wrong.