当前位置:   article > 正文

使用双链表实现GEC6818开发板图片切换_开发板点击触摸屏切换图片

开发板点击触摸屏切换图片
  1. //main.c 文件
  2. #include "bmptool.h"
  3. int main(int argc,char *argv[])
  4. {
  5. dlist mylist=list_init();
  6. show_search_bmp(argv[1],mylist);
  7. dlist p=mylist;
  8. show_bmp(mylist->msg.path);
  9. while(1)
  10. {
  11. hand_touch(p);
  12. if(p->location.x<=800&&p->location.x>400)
  13. {
  14. p=p->next;
  15. }
  16. else
  17. {
  18. p=p->prev;
  19. }
  20. show_bmp(p->msg.path);
  21. }
  22. }
  23. //dlist_and_bmp.c文件
  24. #include "bmptool.h"
  25. int show_search_bmp(const char *dir,struct doublelist *list)
  26. {
  27. DIR *fd=opendir(dir);
  28. char buf[1024]={0};
  29. bzero(buf,1024);
  30. if(fd==NULL)
  31. {
  32. perror("open is fail\n");
  33. return -1;
  34. }
  35. struct dirent *mydirent;
  36. while((mydirent=readdir(fd))!=NULL)
  37. {
  38. if(strcmp(mydirent->d_name,".")==0||strcmp(mydirent->d_name,"..")==0)
  39. continue;
  40. if(mydirent->d_type==DT_DIR)
  41. {
  42. bzero(buf,100);
  43. sprintf(buf,"%s/%s",dir,mydirent->d_name);
  44. show_search_bmp(buf,list);
  45. }
  46. else if(strstr(mydirent->d_name,".bmp"))
  47. {
  48. bzero(buf,100);
  49. sprintf(buf,"%s/%s",dir,mydirent->d_name);
  50. struct stat l;
  51. stat(buf, &l);
  52. list_add_tail1(buf,l.st_size,list);
  53. }
  54. }
  55. return 0;
  56. }
  57. int hand_touch(struct doublelist *list)
  58. {
  59. int touchfd;
  60. struct input_event myevent;
  61. int x;
  62. int y;
  63. int flag=0;
  64. int hlag=0;
  65. touchfd=open("/dev/input/event0",O_RDWR);
  66. if(touchfd==-1)
  67. {
  68. perror("打开触摸屏失败\n");
  69. return -1;
  70. }
  71. while(1)
  72. {
  73. read(touchfd,&myevent,sizeof(myevent));
  74. //判断事件类型--》触摸事件
  75. if(myevent.type==EV_ABS) //是触摸事件
  76. {
  77. //进一步判断读取是x坐标,还是y坐标
  78. if(myevent.code==ABS_X) //是x坐标
  79. {
  80. printf("读取的x坐标是: %d\n",myevent.value);
  81. flag=1;
  82. x=myevent.value;
  83. printf("坐标y=%d\n",x);
  84. }
  85. if(myevent.code==ABS_Y) //是y坐标
  86. {
  87. hlag=1;
  88. y=myevent.value;
  89. printf("坐标y=%d\n",y);
  90. }
  91. if(flag==1&&hlag==1)
  92. {
  93. hlag=0;
  94. flag=0;
  95. break;
  96. }
  97. }
  98. }
  99. list->location.x=x;
  100. list->location.y=y;
  101. close(touchfd);
  102. return 0;
  103. }
  104. //链表的初始化
  105. struct doublelist *list_init()
  106. {
  107. dlist list=malloc(sizeof(struct doublelist));
  108. strcpy(list->msg.path,"1");
  109. list->msg.size=-1;
  110. list->location.x=0;
  111. list->location.y=1;
  112. list->next=list;
  113. list->prev=list;
  114. return list;
  115. }
  116. int show_bmp(char *argv)
  117. {
  118. int i,j;
  119. char bmpbuf[800*480*3];
  120. int tembuf[800*480];
  121. int lcdbuf[800*480];
  122. int lcdfd=open("/dev/fb0",O_RDWR);
  123. if(lcdfd==-1)
  124. {
  125. perror("open lcd error");
  126. return -1;
  127. }
  128. printf("%s\n",argv);
  129. int bmpfd=open(argv,O_RDWR);
  130. if(bmpfd==-1)
  131. {
  132. perror("open bmp error");
  133. return -1;
  134. }
  135. read(bmpfd,bmpbuf,800*480*3);
  136. for(i=0,j=0;i<800*480;i++,j+=3)
  137. {
  138. tembuf[i]=0x00<<24|bmpbuf[j]|bmpbuf[j+1]<<8|bmpbuf[j+2]<<16;
  139. }
  140. for(j=0;j<480;j++)
  141. {
  142. for(i=0;i<800;i++)
  143. {
  144. lcdbuf[800*j+i]=tembuf[800*(479-j)+i];
  145. }
  146. }
  147. write(lcdfd,lcdbuf,800*480*4);
  148. close(lcdfd);
  149. close(bmpfd);
  150. }
  151. //尾插法
  152. int list_add_tail1(char *path,int size,struct doublelist *list)
  153. {
  154. node newnode=malloc(sizeof(struct doublelist));
  155. strcpy(newnode->msg.path,path);
  156. newnode->msg.size=size;
  157. dlist p=list;
  158. if(strcmp(list->msg.path,"1")==0&&list->msg.size==-1)
  159. {
  160. strcpy(list->msg.path,path);
  161. list->msg.size=size;
  162. return 0;
  163. }
  164. while(p->next!=list)
  165. {
  166. p=p->next;
  167. }
  168. list->prev=newnode;
  169. newnode->next=list;
  170. newnode->prev=p;
  171. p->next=newnode;
  172. return 0;
  173. }
  174. int list_show(struct doublelist *list)
  175. {
  176. struct doublelist *p=list;
  177. //顺打印
  178. if(list==NULL)
  179. {
  180. printf("这是空表\n");
  181. return 0;
  182. }
  183. while(p->next!=list)
  184. {
  185. printf("文件所在的绝对地址:%s\n",p->msg.path);
  186. printf("文件大小:%d\n",p->msg.size);
  187. p=p->next;
  188. }
  189. printf("文件所在的绝对地址:%s\n",p->msg.path);
  190. printf("文件大小:%d\n",p->msg.size);
  191. printf("\n");
  192. //逆打印
  193. while(p!=list)
  194. {
  195. printf("文件所在的绝对地址:%s\n",p->msg.path);
  196. printf("文件大小:%d\n",p->msg.size);
  197. p=p->prev;
  198. }
  199. printf("文件所在的绝对地址:%s\n",p->msg.path);
  200. printf("文件大小:%d\n",p->msg.size);
  201. return 0;
  202. }
  203. //头文件
  204. #ifndef _BMPTOOL_H
  205. #define _BMPTOOL_H
  206. #include <stdio.h>
  207. #include <sys/types.h>
  208. #include <sys/stat.h>
  209. #include <fcntl.h>
  210. #include <unistd.h>
  211. #include <string.h>
  212. #include <errno.h>
  213. #include <stdlib.h>
  214. #include <dirent.h>
  215. #include <linux/input.h> //跟输入子系统模型有关
  216. #include <malloc.h>
  217. #define LEFT 1
  218. #define RIGHT
  219. typedef struct
  220. {
  221. int x;
  222. int y;
  223. }xy;
  224. struct filemsg
  225. {
  226. char path[1024]; //文件路径名
  227. int size; //文件大小
  228. };
  229. typedef struct doublelist
  230. {
  231. struct filemsg msg;
  232. xy location;
  233. struct doublelist *next;
  234. struct doublelist *prev;
  235. }*dlist,*node;
  236. int hand_touch(struct doublelist *list);
  237. int show_search_bmp(const char *dir,struct doublelist *list);
  238. int show_bmp(char *argv);
  239. struct doublelist *list_init();
  240. int list_show(struct doublelist *list);
  241. int list_add_tail1(char *path,int size,struct doublelist *list);
  242. #endif

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/47738
推荐阅读
相关标签
  

闽ICP备14008679号