赞
踩
1.打印触摸屏坐标数据
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> #include <strings.h> #include <linux/input.h> void main() { struct input_event myevent; //type:事件类型;code:事件代码;value:事件的值 int x,y; //打开触摸屏设备文件 int ts_fd; ts_fd = open("/dev/input/event0",O_RDONLY); //读取触摸屏数据 while(1) { read(ts_fd,&myevent,sizeof(myevent)); if(myevent.type==EV_ABS) { if(myevent.code==ABS_X) { x=myevent.value; } if(myevent.code==ABS_Y) { y=myevent.value; } } if(myevent.type==EV_KEY&&myevent.code==BTN_TOUCH&&myevent.value==0) { printf("%d %d\n",x,y); } } //打印触摸屏数据 //printf("type=%d,code=%d,value=%d\n",myevent.type,myevent.code,myevent.value); close(ts_fd); }
2.相册(触摸换图)
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <strings.h> #include <sys/mman.h> #include <linux/input.h> int show(const char* path);//bmp图片显示函数原型 int main() { int x,y,k=0;; char photo[][30]={"1.bmp","2.bmp","3.bmp","4.bmp"}; struct input_event myevent;//定义数据缓冲区 //打开触摸屏设备文件 int ts_fd = open("/dev/input/event0",O_RDONLY); while(1) { //读取数据并输出 read(ts_fd,&myevent,sizeof(myevent)); //阻塞,等待输入 if(myevent.type==EV_ABS) { if(myevent.code==ABS_X) { x=myevent.value; } if(myevent.code==ABS_Y) { y=myevent.value; } } if(myevent.type == EV_KEY && myevent.code == BTN_TOUCH && myevent.value == 0) { if(x<400) { k++; if(k==4) { k=0; } show(photo[k]); } if(x>400) { k--; if(k<0) { k=3; } show(photo[k]); } } } //关闭触摸屏 close(ts_fd); return 0; } //bmp图片显示函数实现 int show(const char* path) { int x,y; int lcd_fd,bmp_fd; char bmp_buf[800*480*3]; bzero(bmp_buf,sizeof(bmp_buf)); int lcd_buf[800*480]; bzero(lcd_buf,sizeof(lcd_buf)); int show_buf[800*480]; bzero(show_buf,sizeof(show_buf)); //打开LCD设备文件 lcd_fd = open("/dev/fb0",O_RDWR); //打开图片 bmp_fd = open(PATH,O_RDONLY); //定位光标 lseek(bmp_fd,54,SEEK_SET); //读图片像素 read(bmp_fd,bmp_buf,sizeof(bmp_buf)); for(int i=0;i<800*480; i++) { lcd_buf[i] = bmp_buf[i*3]<<0 | bmp_buf[i*3+1]<<8 | bmp_buf[i*3+2]<<16; } //解决图片颠倒问题 for(y=0; y<480; y++) { for(x=0; x<800; x++) { show_buf[(479-y)*800+x] = lcd_buf[800*y+x]; } } //内存映射 int *fd_mmap = mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_fd,0); //显示 for(int i=0;i<800*480;i++) { *(fd_mmap+i)=show_buf[i]; } close(lcd_fd);//关闭LCD close(bmp_fd);//关闭图片文件 munmap(fd_mmap,800*480*4);//解除内存映射 }
3.相册翻页添加特效
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> #include <strings.h> #include <linux/input.h> #include "show_bmp.h" int show(const char picturenum); void main() { struct input_event myevent; //type,code,value int x,y; int k=0; //char picture[][30]={"1.bmp","2.bmp","3.bmp","4.bmp"}; //打开触摸屏设备文件 int ts_fd; ts_fd = open("/dev/input/event0",O_RDONLY); //读取触摸屏数据 while(1) { read(ts_fd,&myevent,sizeof(myevent)); if(myevent.type==EV_ABS) { if(myevent.code==ABS_X) { x=myevent.value; } if(myevent.code==ABS_Y) { y=myevent.value; } } if(myevent.type==EV_KEY&&myevent.code==BTN_TOUCH&&myevent.value==0) { if(x>400) { k++; if(k>3){k=0;} show(k); } if(x<400) { k--; if(k<0){k=3;} show(k); } } } //打印触摸屏数据 //printf("type=%d,code=%d,value=%d\n",myevent.type,myevent.code,myevent.value); close(ts_fd); } int show(const char picturenum) { int p_fd; p_fd = open("/dev/fb0",O_RDWR); int *pfd_mmap = mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED,p_fd,0); //char picture[][30]={"1.bmp","2.bmp","3.bmp","4.bmp"}; if(picturenum==0) { pic_circular_spread("./1.bmp",pfd_mmap); } if(picturenum==1) { pic_down("./2.bmp",pfd_mmap); } if(picturenum==2) { pic_circular_shrink("./3.bmp",pfd_mmap); } if(picturenum==3) { pic_left("./4.bmp",pfd_mmap); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。