正点原子—触摸屏
编写一个正点原子的7寸1024*600触摸屏的应用程序
/*********************************************************************************
*
*
* 设计获取触摸屏的坐标信息
* author:jindouliu2024@163.com
* date:2025.4.24
*
*
* Copyright (c) 2024-2025 jindouliu2024@163.com All right Reserved
* ********************************************************************************/
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include<sys/ioctl.h>
#include <unistd.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include <sys/mman.h>
#include <linux/input.h>
int main()
{
int x,y,cnt = 0;
// 打开触摸屏
int ts_fd = open("/dev/input/event1",O_RDWR);
if(ts_fd == -1){
printf("open touch screen is failed\n");
}
struct input_event ts_event;
while(1){
//读取数据
read(ts_fd,&ts_event,sizeof(ts_event));
//判断数据
if(ts_event.type == EV_ABS){
//获取x轴坐标
if(ts_event.code ==ABS_MT_POSITION_X ){
x = ts_event.value;
cnt++;
}
////获取y轴坐标
if(ts_event.code ==ABS_MT_POSITION_Y ){
y = ts_event.value;
cnt++;
}
if(cnt >= 2){
printf("x = %d y = %d\n",x,y);
cnt = 0;
}
}
}
//关闭触摸屏
close(ts_fd);
return 0;
}