This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappSlide.ino
99 lines (93 loc) · 2.46 KB
/
appSlide.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#define abssub(__a,__b) ( (__a>__b) ? (__a-__b) : (__b-__a) )
void appSlide()
{
// FIL file; DIR dir;
if(!fileDialog(file,dir)) return;
unsigned char *pixbuf = new unsigned char[480];//one line
unsigned short int ii,jj,y1,y2;
unsigned short int scrollData=320;
unsigned int n,upPos=0,maxPos=f_size(&file)-153600; //needed to figure out when to not scroll down
LCD_ResetWindow();
LCD_SetCursor(0,0);
LCD_WriteIndex(0x22);
for(ii=0;ii<320;ii++)//fill the screen first
{
f_read(&file,pixbuf,480,&n);
if(n<480){
ii=400; //check if file isn't too small
break;
}
for(jj=0;jj<480;jj+=2)
{
LCD_WriteData((pixbuf[jj]<<8)|pixbuf[jj|1]);
}
}
while(1)
{
if(!returnButtonState) break;
if(touchPressed)
{
if(!touchReadData()) continue;
y1=touchGetY();
delay(20);
if( !(touchPressed && touchReadData()))
{
delay(100);
continue;
}
y2=touchGetY();
if(abssub(y1,y2)<5)continue;
if(y1>y2 && upPos<maxPos)//go down
{
LCD_SetCursor(0,scrollData);
if(upPos+(y1-y2)*480>maxPos) y1=y2+(maxPos-upPos)/480;
f_lseek(&file,upPos+153600);
scrollData=(scrollData+(y1-y2))%320;
if(scrollData==0)scrollData=320;
LCD_HardwareScroll(scrollData);
LCD_WriteIndex(0x22);
for(ii=0;ii<(y1-y2);ii++)//fill some lines
{
f_read(&file,pixbuf,480,&n);
for(jj=0;jj<480;jj+=2)
{
LCD_LOFF;
LCD_BUS = pixbuf[jj|1]; //higher byte first
LCD_LON;
LCD_BUS = pixbuf[jj];
LCD_WR_LO;
LCD_WR_HI;
}
}
upPos+=(y1-y2)*480;
}
else if (y1<y2 && upPos>0)//go up
{
if((y2-y1)*480>upPos) y2=y1+upPos/480;
upPos-=(y2-y1)*480;
f_lseek(&file,upPos);
scrollData=(320+scrollData-(y2-y1))%320;
LCD_SetCursor(0,scrollData);
if(scrollData==0)scrollData=320;
LCD_HardwareScroll(scrollData);
LCD_WriteIndex(0x22);
for(ii=0;ii<(y2-y1);ii++)//fill some lines
{
f_read(&file,pixbuf,480,&n);
for(jj=0;jj<480;jj+=2)
{
LCD_LOFF;
LCD_BUS = pixbuf[jj|1]; //higher byte first
LCD_LON;
LCD_BUS = pixbuf[jj];
LCD_WR_LO;
LCD_WR_HI;
}
}
}
}
}
f_close(&file);
LCD_HardwareScroll(0);
delete [] pixbuf;
}