#include <stdio.h>
#include <errno.h> // 全局变量: errno
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include"jpg.h"
#include"ts.h"
char ** getphoto(char const *dirname);
void showphoto(char **buf);
char *buf[20];
int main(void)
{
TS_Init();
open_lcd();
getphoto("./photo");
showphoto(buf);
close_lcd();
TS_UnInit();
return 0;
}
char ** getphoto(char const *dirname) // ./directory dir/
{
// 1,打开目录:
DIR *dp = opendir(dirname);
if(dp == NULL)
{
perror("打开目录失败");
exit(0);
}
// 2,不断读取目录里面的目录项
struct dirent *ep=NULL;
struct stat info;
bzero(&info, sizeof(info));
int k=0;
while(1)
{
ep = readdir(dp);
if(ep == NULL && errno == 0)
{
break;
//showphoto(dirname);
}
else if(ep == NULL)
{
perror("读取目录项失败");
break;
}
else
{
if(ep->d_name[0] == '.'||(ep->d_name[0] == '.'&&ep->d_name[1] == '.'))
continue;
else
{
buf[k]=ep->d_name;
printf("%s\n",buf[k]);
}
}
k++;
}
closedir(dp);
return buf;
}
void showphoto(char **buf)
{
display(buf[5],0,0,1);
printf("%s\n",buf[3]);
struct xy s;
int k=0;
while(1)
{
memset(&s,0,sizeof(struct xy));
s=get_pos();
printf("%d,%d\n",s.x1,s.y1);
printf("%d,%d\n",s.x2,s.y2);
if( (s.x1>s.x2) && (k<sizeof(buf)/sizeof(buf[0])))
{
display(buf[++k],0,0,1);
}
if( (s.x1<s.x2) && (k>0) )
{
display(buf[--k],0,0,1);
}
}
}
#include <errno.h> // 全局变量: errno
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include"jpg.h"
#include"ts.h"
char ** getphoto(char const *dirname);
void showphoto(char **buf);
char *buf[20];
int main(void)
{
TS_Init();
open_lcd();
getphoto("./photo");
showphoto(buf);
close_lcd();
TS_UnInit();
return 0;
}
char ** getphoto(char const *dirname) // ./directory dir/
{
// 1,打开目录:
DIR *dp = opendir(dirname);
if(dp == NULL)
{
perror("打开目录失败");
exit(0);
}
// 2,不断读取目录里面的目录项
struct dirent *ep=NULL;
struct stat info;
bzero(&info, sizeof(info));
int k=0;
while(1)
{
ep = readdir(dp);
if(ep == NULL && errno == 0)
{
break;
//showphoto(dirname);
}
else if(ep == NULL)
{
perror("读取目录项失败");
break;
}
else
{
if(ep->d_name[0] == '.'||(ep->d_name[0] == '.'&&ep->d_name[1] == '.'))
continue;
else
{
buf[k]=ep->d_name;
printf("%s\n",buf[k]);
}
}
k++;
}
closedir(dp);
return buf;
}
void showphoto(char **buf)
{
display(buf[5],0,0,1);
printf("%s\n",buf[3]);
struct xy s;
int k=0;
while(1)
{
memset(&s,0,sizeof(struct xy));
s=get_pos();
printf("%d,%d\n",s.x1,s.y1);
printf("%d,%d\n",s.x2,s.y2);
if( (s.x1>s.x2) && (k<sizeof(buf)/sizeof(buf[0])))
{
display(buf[++k],0,0,1);
}
if( (s.x1<s.x2) && (k>0) )
{
display(buf[--k],0,0,1);
}
}
}