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(1,1, " Rockbox!");
while(1) {
key = button_get();
if(!key) {
sleep(1);
continue;
}
}
browse_root();
}

View file

@ -86,7 +86,7 @@ void move_cursor_down(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)
{
lcd_puts(0, cursor*menu_line_height, " ", 0);
lcd_putsxy(0, cursor*menu_line_height, " ",0);
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 */
@ -110,8 +110,8 @@ void execute_menu_item(void)
void add_menu_item(int location, char *string)
{
lcd_puts(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location,
string, MENU_ITEM_FONT);
lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string,
MENU_ITEM_FONT);
if (location < menu_top)
menu_top = location;
if (location > menu_bottom)
@ -130,7 +130,7 @@ void menu_init(void)
for (i = i; i < Last_Id; i++)
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();
}

View file

@ -26,6 +26,7 @@
#include <button.h>
#include "kernel.h"
#include "tree.h"
#include "debug.h"
#include "id3.h"
@ -33,8 +34,7 @@
#include "x11/mpegplay.h"
#endif
#define LINE_Y 8 /* initial line */
#define LINE_HEIGTH 8 /* line height in pixels */
#define LINE_Y 1 /* initial line */
void playtune(char *dir, char *file)
{
@ -46,31 +46,39 @@ void playtune(char *dir, char *file)
sprintf(buffer, "%s/%s", dir, file);
if(mp3info(&mp3, buffer)) {
debugf("id3 failure!");
DEBUGF("id3 failure!");
good=0;
}
#ifdef HAVE_LCD_BITMAP
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(0,0);
lcd_setfont(0);
#endif
if(!good) {
lcd_puts(0, 0, "[no id3 info]", 0);
lcd_puts(0, 0, "[no id3 info]");
}
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);
#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*LINE_HEIGTH, buffer, 0);
lcd_puts(0, LINE_Y+3, buffer);
sprintf(buffer, "%d kbits", mp3.bitrate);
lcd_puts(0, LINE_Y+4*LINE_HEIGTH, buffer, 0);
lcd_puts(0, LINE_Y+4, buffer);
sprintf(buffer, "%d Hz", mp3.frequency);
lcd_puts(0, LINE_Y+5*LINE_HEIGTH, buffer, 0);
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();
#endif
#ifdef MPEG_PLAY
sprintf(buffer, "%s/%s", dir, file);

View file

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

View file

@ -310,14 +310,14 @@ void game_loop(void)
sleep(10);
}
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,
TETRIS_TITLE_XLOC+(w*sizeof(TETRIS_TITLE)),
TETRIS_TITLE_YLOC-h);
lcd_puts(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC,
"You lose!", TETRIS_TITLE_FONT);
lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, "You lose!",
TETRIS_TITLE_FONT);
lcd_update();
sleep(2);
return;
@ -349,8 +349,8 @@ void tetris(void)
init_tetris();
draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y);
lcd_puts(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC,
TETRIS_TITLE, TETRIS_TITLE_FONT);
lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, TETRIS_TITLE,
TETRIS_TITLE_FONT);
lcd_update();
next_b = t_rand(blocks);

View file

@ -32,13 +32,8 @@
#include "play.h"
#define TREE_MAX_FILENAMELEN 64
#define TREE_MAX_ON_SCREEN 7
#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */
void browse_root(void) {
dirbrowse("/");
}
#define TREE_MAX_FILENAMELEN 128
struct entry {
int file; /* TRUE if file, FALSE if dir */
@ -46,15 +41,35 @@ struct entry {
int namelen;
};
#define LINE_Y 8 /* Y position the entry-list starts at */
#define LINE_X 12 /* X position the entry-list starts at */
#define LINE_HEIGTH 8 /* pixels for each text line */
void browse_root(void)
{
dirbrowse("/");
}
#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 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 scrollpos, int* at_end)
{
@ -89,16 +104,21 @@ int static showdir(char *path, struct entry *buffer, int start,
buffer[i].file = !(entry->attribute&ATTR_DIRECTORY);
buffer[i].file?(icon_type=File):(icon_type=Folder);
lcd_bitmap(bitmap_icons_6x8[icon_type], 6, LINE_Y+i*LINE_HEIGTH, 6,
#ifdef HAVE_LCD_BITMAP
if ( buffer[i].file )
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)
lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0);
lcd_puts(LINE_X, LINE_Y+i, buffer[i].name);
else {
char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY];
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;
}
@ -113,15 +133,13 @@ int static showdir(char *path, struct entry *buffer, int start,
}
j = i ;
while (j++ < TREE_MAX_ON_SCREEN) {
lcd_puts(LINE_X, LINE_Y+j*LINE_HEIGTH," ", 0);
lcd_puts(LINE_X, LINE_Y+j," ");
}
closedir(dir);
return i;
}
#endif
bool dirbrowse(char *root)
{
struct entry buffer[TREE_MAX_ON_SCREEN];
@ -133,18 +151,21 @@ bool dirbrowse(char *root)
int start=0;
int at_end=0;
#ifdef HAVE_LCD_BITMAP
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
#ifdef HAVE_LCD_BITMAP
lcd_putsxy(0,0, "[Browse]",0);
lcd_setmargins(0,MARGIN_Y);
lcd_setfont(0);
#endif
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);
if (numentries == -1)
return -1; /* root is not a directory */
lcd_puts(0, dircursor, "-");
lcd_update();
while(1) {
@ -163,21 +184,29 @@ bool dirbrowse(char *root)
i=strlen(currdir);
if (i==1) {
return FALSE;
} else {
while (currdir[i-1]!='/') i--;
}
else {
while (currdir[i-1]!='/')
i--;
strcpy(buf,&currdir[i]);
if (i==1) currdir[i]=0;
else currdir[i-1]=0;
if (i==1)
currdir[i]=0;
else
currdir[i-1]=0;
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
#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*LINE_HEIGTH, "-", 0);
(strcmp(buffer[dircursor].name,buf)!=0))
dircursor++;
if (dircursor==TREE_MAX_ON_SCREEN)
dircursor=0;
lcd_puts(0, LINE_Y+dircursor, "-");
lcd_update();
}
@ -197,53 +226,65 @@ bool dirbrowse(char *root)
start=0;
} else {
playtune(currdir, buffer[dircursor].name);
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(0, MARGIN_Y);
lcd_setfont(0);
#endif
}
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);
#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*LINE_HEIGTH, " ", 0);
lcd_puts(0, LINE_Y+dircursor, " ");
dircursor--;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_puts(0, LINE_Y+dircursor, "-");
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);
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*LINE_HEIGTH, " ", 0);
lcd_puts(0, LINE_Y+dircursor, " ");
dircursor++;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
lcd_puts(0, LINE_Y+dircursor, "-");
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);
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;
}
}
#endif
return FALSE;
}

View file

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

View file

@ -120,6 +120,7 @@ void lcd_puts(int x, int y, char *string)
strncpy(buffer, string, 11);
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