select files to execute

This commit is contained in:
schneider 2011-07-17 01:45:00 +02:00
parent 5d67cfbd1a
commit 6c3fdd3d5d
3 changed files with 96 additions and 0 deletions

View File

@ -10,6 +10,7 @@ OBJS += iobase.o
OBJS += mmc.o OBJS += mmc.o
OBJS += at45db041d.o OBJS += at45db041d.o
OBJS += util.o OBJS += util.o
OBJS += select.o
LIBNAME=fat LIBNAME=fat

View File

@ -0,0 +1,85 @@
#include <string.h>
#include "lcd/lcd.h"
#include "lcd/allfonts.h"
#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 ctr;
int pos = 0;
res = f_opendir(&dir, "0:");
if(res){
//lcdPrint("OpenDir:"); lcdPrintln(f_get_rc_string(res)); lcdRefresh();
return 0;
};
for(ctr=0;pos<count;ctr++) {
res = f_readdir(&dir, &Finfo);
if ((res != FR_OK) || !Finfo.fname[0]) break;
if( ctr < skip )
continue;
int len=strlen(Finfo.fname);
int extlen = strlen(ext);
if( strcmp(Finfo.fname+len-extlen, ext) != 0)
continue;
if (Finfo.fattrib & AM_DIR)
continue;
strcpy(files[pos++],Finfo.fname);
}
return pos;
}
int selectFile(char *filename, char *extension)
{
int skip = 0;
char key;
int selected = 0;
font=&Font_7x8;
while(1){
char files[7][FLEN];
int count = getFiles(files, 7, skip, extension);
redraw:
if( count )
lcdClear();
lcdPrintln("Select file:");
for(int i=0; i<count; i++){
if( selected == i )
lcdPrint(">");
lcdPrintln(files[i]);
}
lcdRefresh();
key=getInputWait();
delayms(20);
if( key==BTN_DOWN ){
if( selected < 6 ){
selected++;
goto redraw;
}else{
skip++;
}
}else if( key==BTN_UP ){
if( selected > 0 ){
selected--;
goto redraw;
}else{
if( skip > 0 ){
skip--;
}
}
}else if( key==BTN_LEFT ){
return 1;
}else if( key==BTN_RIGHT ){
strcpy(filename, files[selected]);
return 0;
}
}
}

View File

@ -0,0 +1,10 @@
#ifndef _SELECT_H_
#define _SELECT_H_
#include <stdint.h>
#define FLEN 13
int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext);
int selectFile(char *filename, char *extension);
#endif