linux c语言 电子相册,getmotion.c

#include "getmotion.h"

//该c文件是用于获取LCD屏幕的手势(上下左右),返回给主函数进行图片浏览的操作。

//获取屏幕左划右划操作

enum motion get_motion(void)

{

// 1,打开触摸屏文件

int tp = open("/dev/input/event0", O_RDONLY);

// 2,读取触摸屏信息 input_event结构体在linux/input.h库中

struct input_event buf;

// int falg = 0; //标记第一次按下的状态获取第一组x值

//int falgy = 0; //标记第一次按下的状态获取第一组y值

//int touch = 0; //标记用户屏幕无动作标志位

int x1 = 0 , x2 = 0; //x1为按下屏幕x的起始值 ,x2为松开屏幕x的结束值

int y1 = 0 , y2 = 0; //y1为按下屏幕x的起始值 ,y2为松开屏幕x的结束值

int xdone = 0 ;

int ydone = 0 ;

while(1)

{

bzero(&buf, sizeof(buf));

read(tp, &buf, sizeof(buf)); // 读取触摸屏数据,放到 buf 中

// 读到按键事件(包括键盘、触摸屏的按压、鼠标的左右键……)

if(buf.type == EV_KEY)

{

// 读到触摸屏的按压事件

if(buf.code == BTN_TOUCH)

{

// 读到按下触摸屏

if(buf.value > 0)

xdone = 0;

ydone = 0;

// 读到松开触摸屏

if(buf.value == 0)

break;

}

}

// 读到触摸屏的坐标事件

if(buf.type == EV_ABS)

{

if(xdone == 0 || ydone == 0)

{

if(buf.code == ABS_X )

{

x1 = buf.value;//起始

xdone = 1;

}

if(buf.code == ABS_Y)

{

y1 = buf.value;//起始

ydone = 1;

}

}

if(xdone == 1 || ydone == 1)

{

if(buf.code == ABS_X )

x2 = buf.value;//结束

if(buf.code == ABS_Y)

y2 = buf.value; //结束

}

}

}

printf("起始x1 = %d 结束x2 = %d\n",x1,x2);

printf("起始y1 = %d 结束y2 = %d\n",y1,y2);

int dif_x = x1 - x2 > 0 ? x1 - x2 : x2 - x1;

int dif_y = y1 - y2 > 0 ? y1 - y2 : y2 - y1;

if(x1 == 0 || x2 == 0)

{

return -1;

}

if (x1 > x2 && dif_x > dif_y)

{

printf("向左滑动\n");

return left;

}

else if(x1 < x2 && dif_x > dif_y)

{

printf("向右滑动\n");

return right;

}

else if(y1 > y2 && dif_y > dif_x)

{

printf("向上滑动\n");

return up;

}

else if(y1 < y2 && dif_y > dif_x)

{

printf("向下滑动\n");

return down;

}

else

{

return -1;

}

// 3,释放资源

close(tp);

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值