ARM6818开发板输入设备(触摸屏)操作(开发五子棋游戏) |
您所在的位置:网站首页 › 触摸屏输入法显示屏幕怎么关闭 › ARM6818开发板输入设备(触摸屏)操作(开发五子棋游戏) |
目录 6818输入设备 输入设备 输入设备在头文件中定义的结构体 练习:获取手指触摸的指标,并且触摸后切换图片 操作一个触摸屏 五子棋游戏开发 实现功能 实现代码 main.c pm.h pm.c ev.h ev.c 6818输入设备 输入设备 输入设备在头文件中定义的结构体键盘、鼠标、触摸屏、麦克风..... Linux下面这些输入设备也是一个文件,都包含一个头文件 #include 在头文件中定义了一个结构体 struct input_event { struct timeval time;//输入时间产生的时间 __u16 type;//输入事件的类型 #define EV_SYN 0x00 同步事件,用来同步数据 #define EV_KEY 0x01 按键事件,如键盘,触摸屏的接触与离开 #define EV_REL 0x02 相对事件,如鼠标的移动 #define EV_ABS 0x03 绝对事件,如触摸屏的坐标 __u16 code;//编码,为了区分同一事件类型下,不同的输入事件 #define BTN_TOUCH 0x14a(330) 接触触摸屏或者离开触摸屏 #define ABS_X 0x00 触摸屏坐标的X轴 #define ABS_Y 0x01 触摸屏的Y轴 #define ABS_PRESSURE 0x18 触摸屏的压力值事件 __s32 value;//值,根据type,code的不同,有不同的含义 如:type = 按键类型 code = BTN_TOUCH value = 按键的状态 type = EV_ABS code = ABS_X value = x坐标 } 练习:获取手指触摸的指标,并且触摸后切换图片 /* 获取触摸点的位置 判断触摸动作(点击,右滑等) */ int Get_ev(int *x,int *y) { int fd = open("/dev/input/event0",O_RDONLY); if(-1 == fd) { perror("open error"); return -1; } struct input_event ev; int x1,y1; while(1) { read(fd,&ev,sizeof(ev)); printf("ev_type = %d code = %d value = %d\n",ev.type,ev.code,ev.value); if(ev.type == EV_ABS) //输入事件的类型为绝对事件,如触摸屏的坐标 { if(ev.code == 0) //触摸屏坐标的X轴 { x1 = ev.value;//6818开发板如果是黑底,x1 = ev.value * 800 / 1024。我这里是蓝底的 } else //触摸屏坐标的X轴 { y1 = ev.value ;//6818开发板如果是黑底y1 = ev.value * 480 / 600 } } if(ev.type == EV_KEY && ev.code == 330 && ev.value == 1)//保存初始坐标 { *x = x1; *y = y1; } if(ev.type == EV_KEY && ev.code == 330 && ev.value == 0) { if(*x == x1 && *y == y1) //点击 { printf("dianji\n"); } if(x1 >= *x) //右滑 { printf("zouhua\n"); } break; } } } //写入BMP格式的图片 int Dis_pic(char *pic) { int fd = open(pic,O_RDONLY); if(-1 == fd) { perror("open error"); return -1; } int width,heigh; short depth; lseek(fd,0x12,SEEK_SET); read(fd,&width,4); read(fd,&heigh,4); lseek(fd,0x1c,SEEK_SET); read(fd,&depth,2); printf(" %d %d %d\n",width,heigh,depth); int laizi =(4 - (width * depth / 8) % 4) % 4;//要加的点 unsigned char color_buf[heigh * (width * depth / 8 + laizi)];//32 24 char color_a = 0,color_r,color_g,color_b; //颜色分量 unsigned int color;//像素点的颜色 unsigned char *p = color_buf; lseek(fd,0x36,SEEK_SET); for(int i = heigh - 1;i >= 0;i--) { for(int j = 0;j < width;j++) { color_b = *p++;//b颜色 color_g = *p++; color_r = *p++; if(32 == depth) { color_a = *p++; } // 0000 0000 0000 0000 0000 0000 1111 1111 // 0000 0000 0000 0000 1111 1111 0000 0000 //color 1111 1111 1111 1111 1111 1111 1111 1111 color = color_a |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |