2011-07-16 23:45:00 +00:00
|
|
|
#include <string.h>
|
2011-07-18 16:19:22 +00:00
|
|
|
#include "sysdefs.h"
|
2011-07-16 23:45:00 +00:00
|
|
|
#include "lcd/lcd.h"
|
2011-07-18 16:19:22 +00:00
|
|
|
#include "lcd/fonts/smallfonts.h"
|
2011-07-16 23:45:00 +00:00
|
|
|
#include "lcd/print.h"
|
|
|
|
#include "filesystem/ff.h"
|
|
|
|
#include "basic/basic.h"
|
|
|
|
|
|
|
|
#define FLEN 13
|
|
|
|
|
|
|
|
int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
|
|
|
|
{
|
|
|
|
DIR dir; /* Directory object */
|
|
|
|
FILINFO Finfo;
|
|
|
|
FRESULT res;
|
|
|
|
int pos = 0;
|
2011-08-01 21:51:08 +00:00
|
|
|
int extlen = strlen(ext);
|
2011-07-16 23:45:00 +00:00
|
|
|
res = f_opendir(&dir, "0:");
|
|
|
|
if(res){
|
|
|
|
//lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh();
|
|
|
|
return 0;
|
|
|
|
};
|
2011-08-01 21:51:08 +00:00
|
|
|
while(f_readdir(&dir, &Finfo) == FR_OK && Finfo.fname[0]){
|
2011-07-16 23:45:00 +00:00
|
|
|
int len=strlen(Finfo.fname);
|
2011-08-01 21:51:08 +00:00
|
|
|
|
|
|
|
if(len<extlen)
|
|
|
|
continue;
|
2011-07-16 23:45:00 +00:00
|
|
|
|
|
|
|
if( strcmp(Finfo.fname+len-extlen, ext) != 0)
|
|
|
|
continue;
|
2011-08-01 21:51:08 +00:00
|
|
|
|
2011-07-16 23:45:00 +00:00
|
|
|
if (Finfo.fattrib & AM_DIR)
|
|
|
|
continue;
|
|
|
|
|
2011-08-01 21:51:08 +00:00
|
|
|
if( skip>0 ){
|
|
|
|
skip--;
|
2011-07-24 22:32:36 +00:00
|
|
|
continue;
|
2011-08-01 21:51:08 +00:00
|
|
|
};
|
|
|
|
|
2011-07-16 23:45:00 +00:00
|
|
|
strcpy(files[pos++],Finfo.fname);
|
2011-07-24 22:32:36 +00:00
|
|
|
if( pos == count )
|
|
|
|
break;
|
2011-07-16 23:45:00 +00:00
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2011-08-01 21:51:08 +00:00
|
|
|
#define PERPAGE 7
|
2011-07-16 23:45:00 +00:00
|
|
|
int selectFile(char *filename, char *extension)
|
|
|
|
{
|
|
|
|
int skip = 0;
|
|
|
|
char key;
|
|
|
|
int selected = 0;
|
|
|
|
font=&Font_7x8;
|
|
|
|
while(1){
|
2011-08-01 21:51:08 +00:00
|
|
|
char files[PERPAGE][FLEN];
|
|
|
|
int count = getFiles(files, PERPAGE, skip, extension);
|
|
|
|
if(!count){
|
|
|
|
lcdPrintln("No Files?");
|
|
|
|
lcdRefresh();
|
|
|
|
getInputWait();
|
|
|
|
getInputWaitRelease();
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
if(count<PERPAGE && selected==count){
|
|
|
|
skip--;
|
|
|
|
continue;
|
|
|
|
};
|
2011-07-16 23:45:00 +00:00
|
|
|
|
|
|
|
redraw:
|
2011-08-01 21:51:08 +00:00
|
|
|
lcdClear();
|
2011-08-01 21:53:09 +00:00
|
|
|
lcdPrintln("Select file:");
|
2011-07-16 23:45:00 +00:00
|
|
|
for(int i=0; i<count; i++){
|
|
|
|
if( selected == i )
|
2011-07-24 22:32:36 +00:00
|
|
|
lcdPrint("*");
|
|
|
|
else
|
|
|
|
lcdPrint(" ");
|
2011-08-04 11:52:36 +00:00
|
|
|
lcdSetCrsrX(14);
|
|
|
|
int dot=-1;
|
|
|
|
for(int j=0;files[j];j++)
|
|
|
|
if(files[i][j]=='.'){
|
|
|
|
files[i][j]=0;
|
|
|
|
dot=j;
|
|
|
|
break;
|
|
|
|
};
|
2011-07-16 23:45:00 +00:00
|
|
|
lcdPrintln(files[i]);
|
2011-08-04 11:52:36 +00:00
|
|
|
if(dot>0)
|
|
|
|
files[i][dot]='.';
|
2011-07-16 23:45:00 +00:00
|
|
|
}
|
|
|
|
lcdRefresh();
|
|
|
|
key=getInputWait();
|
2011-08-01 00:18:36 +00:00
|
|
|
getInputWaitRelease();
|
2011-08-01 21:51:08 +00:00
|
|
|
switch(key){
|
|
|
|
case BTN_DOWN:
|
|
|
|
if( selected < count-1 ){
|
|
|
|
selected++;
|
|
|
|
goto redraw;
|
|
|
|
}else{
|
|
|
|
skip++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BTN_UP:
|
|
|
|
if( selected > 0 ){
|
|
|
|
selected--;
|
|
|
|
goto redraw;
|
|
|
|
}else{
|
|
|
|
if( skip > 0 ){
|
|
|
|
skip--;
|
|
|
|
}
|
2011-07-16 23:45:00 +00:00
|
|
|
}
|
2011-08-01 21:51:08 +00:00
|
|
|
break;
|
|
|
|
case BTN_LEFT:
|
|
|
|
return -1;
|
|
|
|
case BTN_ENTER:
|
|
|
|
case BTN_RIGHT:
|
|
|
|
strcpy(filename, files[selected]);
|
|
|
|
return 0;
|
2011-07-16 23:45:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|