GEC6818开发板触摸屏---点击屏幕获取触摸屏坐标

(/usr/include/linux/input.h)
触摸屏文件数据被封装在input.h文件中的input_event这个结构体中

#include "get_xy.h"
int getxy()
{
    //1.打开触摸屏文件
    int fd = open(TS_PATH, O_RDWR);
    if (fd == -1)
    {
        perror("open failed!");
        return -1;
    }
    //2.读取触摸屏文件数据
    struct input_event xy;
	int x, y;	//存放点击屏幕的横纵坐标
	int flag = 0; //记录当前获取坐标的信息
    while (1)
    {
        read(fd, &xy, sizeof(xy));
        if(xy.type == EV_ABS && xy.code == ABS_X)
        {
            x = xy.value*800/1024;//获取点击的时候X轴坐标的值 (0~1024)--> (0~800)
			flag = 1;
        }
		if(xy.type == EV_ABS && xy.code == ABS_Y)
        {
            y = xy.value*480/600;	//获取点击的时候Y轴坐标的值 (0~600)-->(0~480)
			flag = 2;
        }
        //设置条件:每读取一次完整的坐标,就打印一次坐标
		if(flag == 2)
		{
			printf("(%d,%d)\n", x, y);
			flag = 0;
			break;//获取一次坐标就跳出循环
        }
    }
    //3.关闭触摸屏文件
	close(fd);
    return 0;
}

get_xy.h

#ifndef _GET_XY_H
#define _GET_XY_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>	//输入子系统的头文件

#define TS_PATH "/dev/input/event0"
int getxy();

#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邢饱饱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值