1
0
Fork 0
forked from len0rd/rockbox

Adapted to changes in the lcd API.

Added player support to the dir browser.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@541 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2002-05-10 14:56:52 +00:00
parent 71cda11e65
commit c492d24cce
8 changed files with 296 additions and 254 deletions

View file

@ -97,15 +97,7 @@ void app_main(void)
lcd_puts(0,0, "Mooo!"); lcd_puts(0,0, "Mooo!");
lcd_puts(1,1, " Rockbox!"); lcd_puts(1,1, " Rockbox!");
while(1) { browse_root();
key = button_get();
if(!key) {
sleep(1);
continue;
}
}
} }

View file

@ -86,7 +86,7 @@ void move_cursor_down(void)
void redraw_cursor(void) void redraw_cursor(void)
{ {
lcd_puts(0, cursor*menu_line_height, "-", 0); lcd_putsxy(0, cursor*menu_line_height, "-", 0);
} }
/* /*
@ -96,9 +96,9 @@ void redraw_cursor(void)
*/ */
void put_cursor(int target) void put_cursor(int target)
{ {
lcd_puts(0, cursor*menu_line_height, " ", 0); lcd_putsxy(0, cursor*menu_line_height, " ",0);
cursor = target; cursor = target;
lcd_puts(0, cursor*menu_line_height, "-", 0); lcd_putsxy(0, cursor*menu_line_height, "-",0);
} }
/* We call the function pointer related to the current cursor position */ /* We call the function pointer related to the current cursor position */
@ -110,8 +110,8 @@ void execute_menu_item(void)
void add_menu_item(int location, char *string) void add_menu_item(int location, char *string)
{ {
lcd_puts(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string,
string, MENU_ITEM_FONT); MENU_ITEM_FONT);
if (location < menu_top) if (location < menu_top)
menu_top = location; menu_top = location;
if (location > menu_bottom) if (location > menu_bottom)
@ -130,7 +130,7 @@ void menu_init(void)
for (i = i; i < Last_Id; i++) for (i = i; i < Last_Id; i++)
add_menu_item(items[i].menu_id, (char *) items[i].menu_desc); add_menu_item(items[i].menu_id, (char *) items[i].menu_desc);
lcd_puts(8, 38, "Rockbox!", 2); lcd_putsxy(8, 38, "Rockbox!",2);
redraw_cursor(); redraw_cursor();
} }

View file

@ -26,6 +26,7 @@
#include <button.h> #include <button.h>
#include "kernel.h" #include "kernel.h"
#include "tree.h" #include "tree.h"
#include "debug.h"
#include "id3.h" #include "id3.h"
@ -33,63 +34,70 @@
#include "x11/mpegplay.h" #include "x11/mpegplay.h"
#endif #endif
#define LINE_Y 8 /* initial line */ #define LINE_Y 1 /* initial line */
#define LINE_HEIGTH 8 /* line height in pixels */
void playtune(char *dir, char *file) void playtune(char *dir, char *file)
{ {
char buffer[256]; char buffer[256];
int fd; int fd;
mp3entry mp3; mp3entry mp3;
bool good=1; bool good=1;
sprintf(buffer, "%s/%s", dir, file); sprintf(buffer, "%s/%s", dir, file);
if(mp3info(&mp3, buffer)) { if(mp3info(&mp3, buffer)) {
debugf("id3 failure!"); DEBUGF("id3 failure!");
good=0; good=0;
} }
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
lcd_clear_display(); lcd_setmargins(0,0);
if(!good) { lcd_setfont(0);
lcd_puts(0, 0, "[no id3 info]", 0);
}
else {
lcd_puts(0, 0, "[id3 info]", 0);
lcd_puts(0, LINE_Y, mp3.title?mp3.title:"", 0);
lcd_puts(0, LINE_Y+1*LINE_HEIGTH, mp3.album?mp3.album:"", 0);
lcd_puts(0, LINE_Y+2*LINE_HEIGTH, mp3.artist?mp3.artist:"", 0);
sprintf(buffer, "%d ms", mp3.length);
lcd_puts(0, LINE_Y+3*LINE_HEIGTH, buffer, 0);
sprintf(buffer, "%d kbits", mp3.bitrate);
lcd_puts(0, LINE_Y+4*LINE_HEIGTH, buffer, 0);
sprintf(buffer, "%d Hz", mp3.frequency);
lcd_puts(0, LINE_Y+5*LINE_HEIGTH, buffer, 0);
}
lcd_update();
#endif #endif
if(!good) {
lcd_puts(0, 0, "[no id3 info]");
}
else {
#ifdef HAVE_LCD_BITMAP
lcd_puts(0, 0, "[id3 info]");
lcd_puts(0, LINE_Y, mp3.title?mp3.title:"");
lcd_puts(0, LINE_Y+1, mp3.album?mp3.album:"");
lcd_puts(0, LINE_Y+2, mp3.artist?mp3.artist:"");
sprintf(buffer, "%d ms", mp3.length);
lcd_puts(0, LINE_Y+3, buffer);
sprintf(buffer, "%d kbits", mp3.bitrate);
lcd_puts(0, LINE_Y+4, buffer);
sprintf(buffer, "%d Hz", mp3.frequency);
lcd_puts(0, LINE_Y+5, buffer);
#else
lcd_puts(0, 0, mp3.artist?mp3.artist:"<no artist>");
lcd_puts(0, 1, mp3.title?mp3.title:"<no title>");
#endif
}
lcd_update();
#ifdef MPEG_PLAY #ifdef MPEG_PLAY
sprintf(buffer, "%s/%s", dir, file); sprintf(buffer, "%s/%s", dir, file);
mpeg_play(buffer); mpeg_play(buffer);
return; return;
#endif #endif
while(1) { while(1) {
int key = button_get(); int key = button_get();
if(!key) { if(!key) {
sleep(30); sleep(30);
continue; continue;
}
switch(key) {
case BUTTON_OFF:
case BUTTON_LEFT:
return;
break;
}
} }
switch(key) {
case BUTTON_OFF:
case BUTTON_LEFT:
return;
break;
}
}
} }

View file

@ -84,11 +84,11 @@ void ss_loop(void)
void screensaver(void) void screensaver(void)
{ {
char w, h; int w, h;
char *off = "[Off] to stop"; char *off = "[Off] to stop";
int len = strlen(SS_TITLE); int len = strlen(SS_TITLE);
lcd_fontsize(SS_TITLE_FONT, &w, &h); lcd_getfontsize(SS_TITLE_FONT, &w, &h);
/* Get horizontel centering for text */ /* Get horizontel centering for text */
len *= w; len *= w;
@ -103,10 +103,10 @@ void screensaver(void)
h /= 2; h /= 2;
lcd_clear_display(); lcd_clear_display();
lcd_puts(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SS_TITLE, SS_TITLE_FONT); lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SS_TITLE, SS_TITLE_FONT);
len = strlen(off); len = strlen(off);
lcd_fontsize(0, &w, &h); lcd_getfontsize(0, &w, &h);
/* Get horizontel centering for text */ /* Get horizontel centering for text */
len *= w; len *= w;
@ -120,7 +120,7 @@ void screensaver(void)
else else
h /= 2; h /= 2;
lcd_puts(LCD_WIDTH/2-len, LCD_HEIGHT-(2*h), off, 0); lcd_putsxy(LCD_WIDTH/2-len, LCD_HEIGHT-(2*h), off,0);
lcd_update(); lcd_update();
sleep(150); sleep(150);

View file

@ -310,14 +310,14 @@ void game_loop(void)
sleep(10); sleep(10);
} }
if(gameover()) { if(gameover()) {
char w, h; int w, h;
lcd_fontsize(TETRIS_TITLE_FONT, &w, &h); lcd_getfontsize(TETRIS_TITLE_FONT, &w, &h);
lcd_clearrect(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, lcd_clearrect(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC,
TETRIS_TITLE_XLOC+(w*sizeof(TETRIS_TITLE)), TETRIS_TITLE_XLOC+(w*sizeof(TETRIS_TITLE)),
TETRIS_TITLE_YLOC-h); TETRIS_TITLE_YLOC-h);
lcd_puts(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, "You lose!",
"You lose!", TETRIS_TITLE_FONT); TETRIS_TITLE_FONT);
lcd_update(); lcd_update();
sleep(2); sleep(2);
return; return;
@ -349,8 +349,8 @@ void tetris(void)
init_tetris(); init_tetris();
draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y); draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y);
lcd_puts(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, TETRIS_TITLE,
TETRIS_TITLE, TETRIS_TITLE_FONT); TETRIS_TITLE_FONT);
lcd_update(); lcd_update();
next_b = t_rand(blocks); next_b = t_rand(blocks);

View file

@ -32,13 +32,8 @@
#include "play.h" #include "play.h"
#define TREE_MAX_FILENAMELEN 64
#define TREE_MAX_ON_SCREEN 7 #define TREE_MAX_FILENAMELEN 128
#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */
void browse_root(void) {
dirbrowse("/");
}
struct entry { struct entry {
int file; /* TRUE if file, FALSE if dir */ int file; /* TRUE if file, FALSE if dir */
@ -46,204 +41,250 @@ struct entry {
int namelen; int namelen;
}; };
#define LINE_Y 8 /* Y position the entry-list starts at */ void browse_root(void)
#define LINE_X 12 /* X position the entry-list starts at */ {
#define LINE_HEIGTH 8 /* pixels for each text line */ dirbrowse("/");
}
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
#define TREE_MAX_ON_SCREEN 7
#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */
#define MARGIN_Y 8 /* Y pixel margin */
#define MARGIN_X 12 /* X pixel margin */
#define LINE_Y 0 /* Y position the entry-list starts at */
#define LINE_X 2 /* X position the entry-list starts at */
#define LINE_HEIGTH 8 /* pixels for each text line */
extern unsigned char bitmap_icons_6x8[LastIcon][6]; extern unsigned char bitmap_icons_6x8[LastIcon][6];
extern icons_6x8; extern icons_6x8;
#else /* HAVE_LCD_BITMAP */
#define TREE_MAX_ON_SCREEN 2
#define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */
#define LINE_Y 0 /* Y position the entry-list starts at */
#define LINE_X 1 /* X position the entry-list starts at */
#endif /* HAVE_LCD_BITMAP */
int static showdir(char *path, struct entry *buffer, int start, int static showdir(char *path, struct entry *buffer, int start,
int scrollpos, int* at_end) int scrollpos, int* at_end)
{ {
int i; int i;
int j=0; int j=0;
int icon_type = 0; int icon_type = 0;
DIR *dir = opendir(path); DIR *dir = opendir(path);
struct dirent *entry; struct dirent *entry;
if(!dir) if(!dir)
return -1; /* not a directory */ return -1; /* not a directory */
i=start; i=start;
*at_end=0; /* Have we displayed the last directory entry? */ *at_end=0; /* Have we displayed the last directory entry? */
while((entry = readdir(dir))) { while((entry = readdir(dir))) {
int len; int len;
if(entry->d_name[0] == '.') if(entry->d_name[0] == '.')
/* skip names starting with a dot */ /* skip names starting with a dot */
continue; continue;
if(j++ < scrollpos) if(j++ < scrollpos)
continue ; continue ;
len = strlen(entry->d_name); len = strlen(entry->d_name);
if(len < TREE_MAX_FILENAMELEN) if(len < TREE_MAX_FILENAMELEN)
/* strncpy() is evil, we memcpy() instead, +1 includes the /* strncpy() is evil, we memcpy() instead, +1 includes the
trailing zero */ trailing zero */
memcpy(buffer[i].name, entry->d_name, len+1); memcpy(buffer[i].name, entry->d_name, len+1);
else else
memcpy(buffer[i].name, "too long", 9); memcpy(buffer[i].name, "too long", 9);
buffer[i].file = !(entry->attribute&ATTR_DIRECTORY); buffer[i].file = !(entry->attribute&ATTR_DIRECTORY);
buffer[i].file?(icon_type=File):(icon_type=Folder); #ifdef HAVE_LCD_BITMAP
lcd_bitmap(bitmap_icons_6x8[icon_type], 6, LINE_Y+i*LINE_HEIGTH, 6, if ( buffer[i].file )
8, TRUE); icon_type=File;
else
icon_type=Folder;
lcd_bitmap(bitmap_icons_6x8[icon_type], 6, MARGIN_Y+i*LINE_HEIGTH, 6,
8, TRUE);
#endif
if(len < TREE_MAX_LEN_DISPLAY) if(len < TREE_MAX_LEN_DISPLAY)
lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0); lcd_puts(LINE_X, LINE_Y+i, buffer[i].name);
else { else {
char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY]; char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY];
buffer[i].name[TREE_MAX_LEN_DISPLAY]=0; buffer[i].name[TREE_MAX_LEN_DISPLAY]=0;
lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0); lcd_puts(LINE_X, LINE_Y+i, buffer[i].name);
buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage; buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage;
}
if(++i >= TREE_MAX_ON_SCREEN)
break;
} }
if(++i >= TREE_MAX_ON_SCREEN) if (entry==0) {
break; *at_end=1;
} } else {
*at_end=(readdir(dir)==0);
}
j = i ;
while (j++ < TREE_MAX_ON_SCREEN) {
lcd_puts(LINE_X, LINE_Y+j," ");
}
closedir(dir);
if (entry==0) { return i;
*at_end=1;
} else {
*at_end=(readdir(dir)==0);
}
j = i ;
while (j++ < TREE_MAX_ON_SCREEN) {
lcd_puts(LINE_X, LINE_Y+j*LINE_HEIGTH," ", 0);
}
closedir(dir);
return i;
} }
#endif
bool dirbrowse(char *root) bool dirbrowse(char *root)
{ {
struct entry buffer[TREE_MAX_ON_SCREEN]; struct entry buffer[TREE_MAX_ON_SCREEN];
int numentries; int numentries;
char buf[255]; char buf[255];
char currdir[255]; char currdir[255];
int dircursor=0; int dircursor=0;
int i; int i;
int start=0; int start=0;
int at_end=0; int at_end=0;
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
lcd_clear_display(); lcd_putsxy(0,0, "[Browse]",0);
lcd_setmargins(0,MARGIN_Y);
lcd_puts(0,0, "[Browse]", 0); lcd_setfont(0);
memcpy(currdir,root,sizeof(currdir));
numentries = showdir(root, buffer, 0, start, &at_end);
if (numentries == -1) return -1; /* root is not a directory */
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
while(1) {
int key = button_get();
if(!key) {
sleep(1);
continue;
}
switch(key) {
case BUTTON_OFF:
return FALSE;
break;
case BUTTON_LEFT:
i=strlen(currdir);
if (i==1) {
return FALSE;
} else {
while (currdir[i-1]!='/') i--;
strcpy(buf,&currdir[i]);
if (i==1) currdir[i]=0;
else currdir[i-1]=0;
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
numentries = showdir(currdir, buffer, 0, 0, &at_end);
dircursor=0;
start=0;
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
(strcmp(buffer[dircursor].name,buf)!=0)) dircursor++;
if (dircursor==TREE_MAX_ON_SCREEN) dircursor=0;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
}
break;
case BUTTON_RIGHT:
case BUTTON_PLAY:
if ((currdir[0]=='/') && (currdir[1]==0)) {
sprintf(buf,"%s%s",currdir,buffer[dircursor].name);
} else {
sprintf(buf,"%s/%s",currdir,buffer[dircursor].name);
}
if (!buffer[dircursor].file) {
memcpy(currdir,buf,sizeof(currdir));
dircursor=0;
start=0;
} else {
playtune(currdir, buffer[dircursor].name);
}
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
numentries = showdir(currdir, buffer, 0, start, &at_end);
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
break;
case BUTTON_UP:
if(dircursor) {
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
dircursor--;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
} else
{
if (start) {
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
numentries = showdir(currdir, buffer, 0, --start, &at_end);
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
}
}
break;
case BUTTON_DOWN:
if(dircursor+1 < numentries) {
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
dircursor++;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
} else
{
if (!at_end) {
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
numentries = showdir(currdir, buffer, 0, ++start, &at_end);
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_update();
}
}
break;
}
}
#endif #endif
memcpy(currdir,root,sizeof(currdir));
return FALSE; numentries = showdir(root, buffer, 0, start, &at_end);
if (numentries == -1)
return -1; /* root is not a directory */
lcd_puts(0, dircursor, "-");
lcd_update();
while(1) {
int key = button_get();
if(!key) {
sleep(1);
continue;
}
switch(key) {
case BUTTON_OFF:
return FALSE;
break;
case BUTTON_LEFT:
i=strlen(currdir);
if (i==1) {
return FALSE;
}
else {
while (currdir[i-1]!='/')
i--;
strcpy(buf,&currdir[i]);
if (i==1)
currdir[i]=0;
else
currdir[i-1]=0;
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
lcd_putsxy(0,0, "[Browse]",0);
#endif
numentries = showdir(currdir, buffer, 0, 0, &at_end);
dircursor=0;
start=0;
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
(strcmp(buffer[dircursor].name,buf)!=0))
dircursor++;
if (dircursor==TREE_MAX_ON_SCREEN)
dircursor=0;
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
}
break;
case BUTTON_RIGHT:
case BUTTON_PLAY:
if ((currdir[0]=='/') && (currdir[1]==0)) {
sprintf(buf,"%s%s",currdir,buffer[dircursor].name);
} else {
sprintf(buf,"%s/%s",currdir,buffer[dircursor].name);
}
if (!buffer[dircursor].file) {
memcpy(currdir,buf,sizeof(currdir));
dircursor=0;
start=0;
} else {
playtune(currdir, buffer[dircursor].name);
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(0, MARGIN_Y);
lcd_setfont(0);
#endif
}
lcd_clear_display();
numentries = showdir(currdir, buffer, 0, start, &at_end);
#ifdef HAVE_LCD_BITMAP
lcd_putsxy(0,0, "[Browse]",0);
#endif
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
break;
case BUTTON_UP:
if(dircursor) {
lcd_puts(0, LINE_Y+dircursor, " ");
dircursor--;
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
} else
{
if (start) {
lcd_clear_display();
start--;
numentries = showdir(currdir, buffer, 0,
start, &at_end);
#ifdef HAVE_LCD_BITMAP
lcd_putsxy(0,0, "[Browse]",0);
#endif
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
}
}
break;
case BUTTON_DOWN:
if(dircursor+1 < numentries) {
lcd_puts(0, LINE_Y+dircursor, " ");
dircursor++;
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
} else
{
if (!at_end) {
lcd_clear_display();
start++;
numentries = showdir(currdir, buffer, 0,
start, &at_end);
#ifdef HAVE_LCD_BITMAP
lcd_putsxy(0,0, "[Browse]",0);
#endif
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
}
}
break;
}
}
return FALSE;
} }

View file

@ -28,8 +28,8 @@ CC = gcc
RM = rm -f RM = rm -f
DEBUG = -g DEBUG = -g
#DISPLAY = -DHAVE_LCD_CHARCELLS DISPLAY = -DHAVE_LCD_CHARCELLS
DISPLAY = -DHAVE_LCD_BITMAP #DISPLAY = -DHAVE_LCD_BITMAP
DEFINES = -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \ DEFINES = -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \
-DHAVE_RECORDER_KEYPAD $(DISPLAY) -DHAVE_RECORDER_KEYPAD $(DISPLAY)

View file

@ -120,6 +120,7 @@ void lcd_puts(int x, int y, char *string)
strncpy(buffer, string, 11); strncpy(buffer, string, 11);
buffer[11]=0; buffer[11]=0;
sim_lcd_puts(x*6, y*8, buffer, 0); debugf("lcd_puts(%d,%d,%s)\n",x,y,string);
sim_lcd_puts(x, y, buffer, 0);
} }
#endif #endif