Evrowser Application

The following code has been contributed by Luka Ivanovsky and allows browsing through files that are stored either in Ev3 flash memory or in the MicroSD. It also allows launching any application that is executable through a system call. The source code is available below and the compiled program can be downloaded from the following link.


vmthread MAIN
{
UI_DRAW(SELECT_FONT,SMALL_FONT)

DATA32 timer
DATA32 status

DATAS curdir 100
DATAS subdir 20
DATAS exec 100
DATA8 nfolders
DATA8 pressed
DATA8 line
DATA16 lnheight
MOVE16_16(10,lnheight)
DATA16 indent
MOVE16_16(15,indent)
DATA16 height
DATA16 len

FILENAME(GET_FOLDERNAME,100,curdir)

UPD_DIRS:
UI_DRAW(FILLWINDOW,BG_COLOR,0,0)
UI_DRAW(TEXT,FG_COLOR,0,0,curdir)

FILE(GET_FOLDERS,curdir,nfolders)
MOVE8_8(0,line)
MOVE16_16(0,height)
JR_FALSE(nfolders, CONTROLS)

PRINT_DIRS:
ADD16(height,lnheight,height)
ADD8(line,1,line)
FILE(GET_SUBFOLDER_NAME,curdir,line,20,subdir)
UI_DRAW(TEXT,FG_COLOR,indent,height,subdir)
JR_LT8(line,nfolders,PRINT_DIRS)

MOVE8_8(1,line)
MOVE16_16(lnheight, height)
UI_DRAW(TEXT,FG_COLOR,0,height,'>')

CONTROLS:
UI_DRAW(UPDATE)
UI_BUTTON(WAIT_FOR_PRESS)
TIMER_WAIT(100,timer)
TIMER_READY(timer)

UI_BUTTON(SHORTPRESS,UP_BUTTON,pressed)
JR_TRUE(pressed,PREV_DIR)

UI_BUTTON(SHORTPRESS,DOWN_BUTTON,pressed)
JR_TRUE(pressed,NEXT_DIR)

UI_BUTTON(SHORTPRESS,LEFT_BUTTON,pressed)
JR_TRUE(pressed,PARENT_DIR)

UI_BUTTON(SHORTPRESS,RIGHT_BUTTON,pressed)
JR_TRUE(pressed,ENTER_DIR)

UI_BUTTON(SHORTPRESS,ENTER_BUTTON,pressed)
JR_TRUE(pressed,EXEC_DIR)

UI_BUTTON(SHORTPRESS,BACK_BUTTON,pressed)
JR_TRUE(pressed,EXIT)

PREV_DIR:
JR_EQ8(line,0,CONTROLS)
JR_EQ8(line,1,CONTROLS)
UI_DRAW(TEXT,FG_COLOR,0,height,' ')
SUB8(line,1,line)
SUB16(height,lnheight,height)
UI_DRAW(TEXT,FG_COLOR,0,height,'>')
JR(CONTROLS)

NEXT_DIR:
JR_EQ8(line,nfolders,CONTROLS)
UI_DRAW(TEXT,FG_COLOR,0,height,' ')
ADD8(line,1,line)
ADD16(height,lnheight,height)
UI_DRAW(TEXT,FG_COLOR,0,height,'>')
JR(CONTROLS)

PARENT_DIR:
FILENAME(SPLIT,curdir,100,curdir,subdir,subdir)
STRINGS(GET_SIZE,curdir,len)
SUB16(len,1,len)
WRITE8(0,len,curdir)
JR(UPD_DIRS)

ENTER_DIR:
JR_FALSE(line,CONTROLS)
FILE(GET_SUBFOLDER_NAME,curdir,line,20,subdir)
STRINGS(ADD,curdir,'/',curdir)
STRINGS(ADD,curdir,subdir,curdir)
JR(UPD_DIRS)

EXEC_DIR:
FILE(GET_SUBFOLDER_NAME,curdir,line,20,subdir)
STRINGS(ADD,curdir,'/',exec)
STRINGS(ADD,exec,subdir,exec)
SYSTEM(exec,status)
UI_DRAW(TEXT,FG_COLOR,0,0,'@')
UI_DRAW(UPDATE)
UI_DRAW(TEXT,FG_COLOR,0,0,curdir)
JR(CONTROLS)

EXIT:
}