参考网上代码,现在FatFs做的电子书可以实现下翻,怎么实现上翻啊?
电子书源码:/**************************************************************
文本阅读函数
**************************************************************/
void Ebook_Reader(const TCHAR *Ebook)
{
int i=0,j;
int x=0,y=0;//横、纵坐标
FIL File;
UINT br;
char res;
#define pages 20
static U8 buf;
static U8 Save_buf;
U8 dat;
U8 Space={0x20};
U8 Cnt;
U8 Key=0;
U8 page=0;
static FIL File_Dptr;
int Save_i;
res = f_open(&File,Ebook,FA_OPEN_EXISTING | FA_READ);
if(res != FR_OK)
{
Uart_Printf("\n\nOpen File Error!\n");
}
while(1)
{
res = f_read(&File,buf,1024,&br);//读取1024个数据
for(j=0;j<2048;j++)
{
Save_buf=buf;
}
if(res != FR_OK)
{
Uart_Printf("\n\nRead File Error!\n");
}
if((res || br) == 0) break;
Back:
Next:
/*if(page > pages)
{
for(j=0;j<pages;j++)
{
File_Dptr=File_Dptr;
}
File_Dptr = File;
Save_i = i;
}
else
{
File_Dptr= File;
Save_i= i;
page+=1;
}*/
while(i<br)
{
if((x>=0)&&(x<=16)&&(y>=0)&&(y<=16))
Save_i=i;
if(buf>=128)//中文显示
{
if(i>=1023)//出现半字节
{
DrawSingle16ASCII(x,y,USER_WHITE,USER_BLACK,(const U8 *)Space);
dat = buf;
res = f_read(&File,&buf,1,&br);
if(res != FR_OK)
{
Uart_Printf("\n\nRead File Error!\n");
}
dat = buf;
}
else
{
dat = buf;
dat = buf;
}
DrawSingle16Hz(x,y,USER_WHITE,USER_BLACK,(const U8 *)dat);
x+=16;
if(x>225)//控制横坐标范围,225+16=241>240
{
x=0;
y+=16;
}
i+=2;
}
else
{
if((buf==0x0a)||(buf==0x0d)||(buf==0x0a)||(buf==0x0d))
{
DrawSingle16ASCII(x,y,USER_WHITE,USER_BLACK,(const U8 *)Space);
x=0;
if(Cnt<2)
{
y+=16;
Cnt++;
}
}
else
{
Cnt=0;
dat=buf;
dat=buf;
DrawSingle16ASCII(x,y,USER_WHITE,USER_BLACK,(const U8 *)dat);
x+=8;
}
if(x>233)//控制横坐标范围,233+8=241>240
{
x=0;
y+=16;
}
i++;
}
if((x>224)&&(buf>=128)&&(x!=240))
{
DrawSingle16ASCII(x,y,USER_WHITE,USER_BLACK,(const U8 *)Space);
x=0;
y+=16;
}
while(y>305)
{
Key = Uart_Getch();
/*if(Key == 0x61)//上一页
{
Key=0;
x=0;
y=0;
//i=Save_i;
//dat=Save_dat;
//dat=Save_dat;
//File=Save_File;
Lcd_ClearScr(USER_BLACK);
goto Back;
}*/
if(Key == 0x61)
{
Key=0;
x=0;
y=0;
for(j=0;j<2048;j++)
{
buf=Save_buf;
}
i = Save_i;
//Memset(buf,2048,0);
Uart_Printf("\n\nHere!\n");
Lcd_ClearScr(USER_BLACK);
goto Back;
}
if(Key == 0x64)//下一页
{
Key=0;
x=0;
y=0;
Lcd_ClearScr(USER_BLACK);
goto Next;
}
if(Key == 0x1b)//退出
{
Key=0;
goto Exit;
}
}
}
i=0;
}
Uart_Printf("\n\nbr = %d, res = %d, \n\nEnd!\n\n",br,res);
Exit:
f_close(&File);
} 求指点!
页:
[1]