使用双链表实现GEC6818开发板图片切换

//main.c 文件

#include "bmptool.h"
int main(int argc,char *argv[])
{
    dlist mylist=list_init();
    show_search_bmp(argv[1],mylist);
    dlist p=mylist;
    show_bmp(mylist->msg.path);
    
    while(1)
    {
    hand_touch(p);
    if(p->location.x<=800&&p->location.x>400)
    {
        p=p->next;
    }
    else
    {
        p=p->prev;
    }
    show_bmp(p->msg.path);
    
    }
}

//dlist_and_bmp.c文件
#include "bmptool.h"


int show_search_bmp(const char *dir,struct doublelist *list)
{
	DIR *fd=opendir(dir);
	char buf[1024]={0};
	bzero(buf,1024);
	if(fd==NULL)
	{
		perror("open is fail\n");
		return -1;
	}
	struct dirent *mydirent;
	while((mydirent=readdir(fd))!=NULL)
	{
		if(strcmp(mydirent->d_name,".")==0||strcmp(mydirent->d_name,"..")==0)
			continue;
			
		if(mydirent->d_type==DT_DIR)
		{
			bzero(buf,100);
			sprintf(buf,"%s/%s",dir,mydirent->d_name);
			show_search_bmp(buf,list);
		}
		else if(strstr(mydirent->d_name,".bmp"))
		{
			bzero(buf,100);
			sprintf(buf,"%s/%s",dir,mydirent->d_name);
			struct stat l;
		    stat(buf, &l);
			list_add_tail1(buf,l.st_size,list);
			
		}
	
	}
	
	return 0;

}

int hand_touch(struct doublelist *list)
{
	int touchfd;
	struct input_event myevent;
	int x;
	int y;
	int flag=0;
	int hlag=0;
	touchfd=open("/dev/input/event0",O_RDWR);
	if(touchfd==-1)
	{
		perror("打开触摸屏失败\n");
		return -1;
	}
	while(1)
	{
		read(touchfd,&myevent,sizeof(myevent));
		//判断事件类型--》触摸事件
		if(myevent.type==EV_ABS) //是触摸事件
		{
			//进一步判断读取是x坐标,还是y坐标
			if(myevent.code==ABS_X) //是x坐标
				{
					printf("读取的x坐标是: %d\n",myevent.value);
					flag=1;
					x=myevent.value;
					 printf("坐标y=%d\n",x);
				}
			if(myevent.code==ABS_Y) //是y坐标
				{
					hlag=1;
					y=myevent.value;
			        printf("坐标y=%d\n",y);
				}
			if(flag==1&&hlag==1)
			{
				hlag=0;
				flag=0;
				break;
			}	
		}

	}
	list->location.x=x;
	list->location.y=y;
	close(touchfd);
	return 0;
}
//链表的初始化
struct doublelist *list_init()
{
	dlist list=malloc(sizeof(struct doublelist));
    strcpy(list->msg.path,"1");
    list->msg.size=-1;
	list->location.x=0;
    list->location.y=1;
	list->next=list;
    list->prev=list;
	return list;
}


int show_bmp(char *argv)
{
	int i,j;
	char bmpbuf[800*480*3];
	int tembuf[800*480];
	int lcdbuf[800*480];
	
	int lcdfd=open("/dev/fb0",O_RDWR);
	if(lcdfd==-1)
	{
		perror("open lcd error");
		return -1;
		
	}
	printf("%s\n",argv);
	int bmpfd=open(argv,O_RDWR);
	if(bmpfd==-1)
	{
		perror("open bmp error");
		return -1;
	}
	
	read(bmpfd,bmpbuf,800*480*3);
	for(i=0,j=0;i<800*480;i++,j+=3)
	{
		tembuf[i]=0x00<<24|bmpbuf[j]|bmpbuf[j+1]<<8|bmpbuf[j+2]<<16;
	
	}
	
	for(j=0;j<480;j++)
	{
		for(i=0;i<800;i++)
		{
			lcdbuf[800*j+i]=tembuf[800*(479-j)+i];
		}
	}
	write(lcdfd,lcdbuf,800*480*4);
	close(lcdfd);
	close(bmpfd);
	
}


//尾插法
int list_add_tail1(char *path,int size,struct doublelist *list)
{
    
	node newnode=malloc(sizeof(struct doublelist));
    strcpy(newnode->msg.path,path);
    newnode->msg.size=size;
    dlist p=list;

    if(strcmp(list->msg.path,"1")==0&&list->msg.size==-1)
    {
        strcpy(list->msg.path,path); 
        list->msg.size=size;
        return 0;
    }
    while(p->next!=list)
    {
        p=p->next;
    }
    list->prev=newnode;
	newnode->next=list;
    newnode->prev=p;
	p->next=newnode;
    
	return 0;
}

int list_show(struct doublelist *list)
{
    struct doublelist *p=list;
    //顺打印
    if(list==NULL)
    {
        printf("这是空表\n");
        return 0;
    }
    while(p->next!=list)
    {
        printf("文件所在的绝对地址:%s\n",p->msg.path);
        printf("文件大小:%d\n",p->msg.size);
        p=p->next;
    }
    printf("文件所在的绝对地址:%s\n",p->msg.path);
    printf("文件大小:%d\n",p->msg.size);
	printf("\n");
    //逆打印
	  while(p!=list)
    {
        printf("文件所在的绝对地址:%s\n",p->msg.path);
        printf("文件大小:%d\n",p->msg.size);
        p=p->prev;
    }
    printf("文件所在的绝对地址:%s\n",p->msg.path);
    printf("文件大小:%d\n",p->msg.size);
    return 0;
}

//头文件
#ifndef _BMPTOOL_H
#define _BMPTOOL_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
 #include <errno.h>
#include <stdlib.h>
#include <dirent.h>
#include <linux/input.h> //跟输入子系统模型有关
#include <malloc.h>
#define LEFT 1
#define RIGHT
typedef struct 
{
    int x;
    int y;
}xy;


struct filemsg
{
    char path[1024];  //文件路径名
    int size;       //文件大小
};

typedef struct doublelist
{
	struct filemsg    msg;
    xy  location;
	struct doublelist *next;
    struct doublelist *prev;
}*dlist,*node;


int hand_touch(struct doublelist *list);
int show_search_bmp(const char *dir,struct doublelist *list);
int show_bmp(char *argv);


struct doublelist *list_init();
int list_show(struct doublelist *list);
int list_add_tail1(char *path,int size,struct doublelist *list);
#endif

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值