Better keylock and button handling, with visual feedback
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1465 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b3d0b6ea2a
commit
2b934027d8
1 changed files with 138 additions and 25 deletions
147
apps/wps.c
147
apps/wps.c
|
@ -41,6 +41,12 @@
|
||||||
#define PLAY_DISPLAY_FILENAME_SCROLL 1
|
#define PLAY_DISPLAY_FILENAME_SCROLL 1
|
||||||
#define PLAY_DISPLAY_TRACK_TITLE 2
|
#define PLAY_DISPLAY_TRACK_TITLE 2
|
||||||
|
|
||||||
|
#ifdef HAVE_RECORDER_KEYPAD
|
||||||
|
#define RELEASE_MASK (BUTTON_F1 | BUTTON_DOWN)
|
||||||
|
#else
|
||||||
|
#define RELEASE_MASK (BUTTON_MENU | BUTTON_STOP)
|
||||||
|
#endif
|
||||||
|
|
||||||
static void draw_screen(struct mp3entry* id3)
|
static void draw_screen(struct mp3entry* id3)
|
||||||
{
|
{
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
|
@ -132,18 +138,51 @@ static void draw_screen(struct mp3entry* id3)
|
||||||
lcd_update();
|
lcd_update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_keylock_text(bool locked)
|
||||||
|
{
|
||||||
|
lcd_clear_display();
|
||||||
|
|
||||||
|
#ifdef HAVE_LCD_CHARCELLS
|
||||||
|
if(locked)
|
||||||
|
lcd_puts(0, 0, "Keylock ON");
|
||||||
|
else
|
||||||
|
lcd_puts(0, 0, "Keylock OFF");
|
||||||
|
#else
|
||||||
|
if(locked)
|
||||||
|
{
|
||||||
|
lcd_puts(2, 3, "Key lock is ON");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lcd_puts(2, 3, "Key lock is OFF");
|
||||||
|
}
|
||||||
|
lcd_update();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sleep(HZ);
|
||||||
|
}
|
||||||
|
|
||||||
/* demonstrates showing different formats from playtune */
|
/* demonstrates showing different formats from playtune */
|
||||||
int wps_show(void)
|
int wps_show(void)
|
||||||
{
|
{
|
||||||
static bool playing = true;
|
struct mp3entry* id3 = NULL;
|
||||||
struct mp3entry* id3 = mpeg_current_track();
|
|
||||||
bool keys_locked = false;
|
bool keys_locked = false;
|
||||||
bool dont_go_to_menu = false;
|
bool dont_go_to_menu = false;
|
||||||
|
bool menu_button_is_down = false;
|
||||||
|
bool pending_keylock = true; /* Keylock will go ON next time */
|
||||||
|
int old_release_mask;
|
||||||
|
int x = 0;
|
||||||
|
|
||||||
lcd_clear_display();
|
old_release_mask = button_set_release(RELEASE_MASK);
|
||||||
|
|
||||||
|
if(mpeg_is_playing())
|
||||||
|
{
|
||||||
|
id3 = mpeg_current_track();
|
||||||
draw_screen(id3);
|
draw_screen(id3);
|
||||||
|
}
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 )
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
|
|
||||||
|
@ -154,7 +193,7 @@ int wps_show(void)
|
||||||
draw_screen(id3);
|
draw_screen(id3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playing && id3)
|
if (mpeg_is_playing() && id3)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
snprintf(buffer,sizeof(buffer), "Time: %d:%02d / %d:%02d",
|
snprintf(buffer,sizeof(buffer), "Time: %d:%02d / %d:%02d",
|
||||||
|
@ -166,7 +205,8 @@ int wps_show(void)
|
||||||
lcd_puts(0, 6, buffer);
|
lcd_puts(0, 6, buffer);
|
||||||
lcd_update();
|
lcd_update();
|
||||||
#else
|
#else
|
||||||
// Display time with the filename scroll only because the screen has room.
|
/* Display time with the filename scroll only because
|
||||||
|
the screen has room. */
|
||||||
if (global_settings.wps_display == PLAY_DISPLAY_FILENAME_SCROLL)
|
if (global_settings.wps_display == PLAY_DISPLAY_FILENAME_SCROLL)
|
||||||
{
|
{
|
||||||
snprintf(buffer,sizeof(buffer), "Time: %d:%02d / %d:%02d",
|
snprintf(buffer,sizeof(buffer), "Time: %d:%02d / %d:%02d",
|
||||||
|
@ -190,13 +230,32 @@ int wps_show(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for ( i=0;i<5;i++ ) {
|
for ( i=0;i<5;i++ ) {
|
||||||
switch ( button_get(false) ) {
|
int button = button_get(false);
|
||||||
|
|
||||||
|
if(button == BUTTON_NONE)
|
||||||
|
x++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(x)
|
||||||
|
debugf("%d BUTTON_NONE\n", x);
|
||||||
|
debugf("Btn: %04x - lock: %d\n", button, keys_locked);
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( button )
|
||||||
|
{
|
||||||
case BUTTON_ON:
|
case BUTTON_ON:
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LCD_CHARCELLS
|
#ifdef HAVE_LCD_CHARCELLS
|
||||||
lcd_icon(ICON_RECORD, false);
|
lcd_icon(ICON_RECORD, false);
|
||||||
#endif
|
#endif
|
||||||
|
button_set_release(old_release_mask);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef HAVE_RECORDER_KEYPAD
|
#ifdef HAVE_RECORDER_KEYPAD
|
||||||
|
@ -205,9 +264,13 @@ int wps_show(void)
|
||||||
case BUTTON_UP:
|
case BUTTON_UP:
|
||||||
#endif
|
#endif
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( playing )
|
if ( mpeg_is_playing() )
|
||||||
{
|
{
|
||||||
mpeg_pause();
|
mpeg_pause();
|
||||||
status_set_playmode(STATUS_PAUSE);
|
status_set_playmode(STATUS_PAUSE);
|
||||||
|
@ -217,14 +280,17 @@ int wps_show(void)
|
||||||
mpeg_resume();
|
mpeg_resume();
|
||||||
status_set_playmode(STATUS_PLAY);
|
status_set_playmode(STATUS_PLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
playing = !playing;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef HAVE_RECORDER_KEYPAD
|
#ifdef HAVE_RECORDER_KEYPAD
|
||||||
case BUTTON_UP:
|
case BUTTON_UP:
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
global_settings.volume++;
|
global_settings.volume++;
|
||||||
if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME))
|
if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME))
|
||||||
global_settings.volume = mpeg_sound_max(SOUND_VOLUME);
|
global_settings.volume = mpeg_sound_max(SOUND_VOLUME);
|
||||||
|
@ -233,7 +299,12 @@ int wps_show(void)
|
||||||
|
|
||||||
case BUTTON_DOWN:
|
case BUTTON_DOWN:
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
global_settings.volume--;
|
global_settings.volume--;
|
||||||
if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME))
|
if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME))
|
||||||
global_settings.volume = mpeg_sound_min(SOUND_VOLUME);
|
global_settings.volume = mpeg_sound_min(SOUND_VOLUME);
|
||||||
|
@ -243,13 +314,22 @@ int wps_show(void)
|
||||||
|
|
||||||
case BUTTON_LEFT:
|
case BUTTON_LEFT:
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
mpeg_prev();
|
mpeg_prev();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUTTON_RIGHT:
|
case BUTTON_RIGHT:
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
mpeg_next();
|
mpeg_next();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -272,6 +352,28 @@ int wps_show(void)
|
||||||
|
|
||||||
case BUTTON_MENU:
|
case BUTTON_MENU:
|
||||||
lcd_icon(ICON_PARAM, true);
|
lcd_icon(ICON_PARAM, true);
|
||||||
|
menu_button_is_down = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON_STOP | BUTTON_REL:
|
||||||
|
/* The STOP key has been release while the MENU key
|
||||||
|
was held */
|
||||||
|
if(menu_button_is_down)
|
||||||
|
pending_keylock = !pending_keylock;
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
case BUTTON_F1:
|
||||||
|
menu_button_is_down = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON_DOWN | BUTTON_REL:
|
||||||
|
/* The DOWN key has been release while the F1 key
|
||||||
|
was held */
|
||||||
|
if(menu_button_is_down)
|
||||||
|
{
|
||||||
|
pending_keylock = !pending_keylock;
|
||||||
|
debugf("pending: %d\n", pending_keylock);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -280,14 +382,20 @@ int wps_show(void)
|
||||||
#else
|
#else
|
||||||
case BUTTON_MENU | BUTTON_STOP:
|
case BUTTON_MENU | BUTTON_STOP:
|
||||||
#endif
|
#endif
|
||||||
keys_locked = !keys_locked;
|
if(keys_locked != pending_keylock)
|
||||||
|
{
|
||||||
|
keys_locked = pending_keylock;
|
||||||
|
|
||||||
#ifdef HAVE_LCD_CHARCELLS
|
#ifdef HAVE_LCD_CHARCELLS
|
||||||
lcd_icon(ICON_PARAM, false);
|
|
||||||
if(keys_locked)
|
if(keys_locked)
|
||||||
lcd_icon(ICON_RECORD, true);
|
lcd_icon(ICON_RECORD, true);
|
||||||
else
|
else
|
||||||
lcd_icon(ICON_RECORD, false);
|
lcd_icon(ICON_RECORD, false);
|
||||||
#endif
|
#endif
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
|
}
|
||||||
|
|
||||||
dont_go_to_menu = true;
|
dont_go_to_menu = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -299,16 +407,15 @@ int wps_show(void)
|
||||||
#ifdef HAVE_LCD_CHARCELLS
|
#ifdef HAVE_LCD_CHARCELLS
|
||||||
lcd_icon(ICON_PARAM, false);
|
lcd_icon(ICON_PARAM, false);
|
||||||
#endif
|
#endif
|
||||||
|
menu_button_is_down = false;
|
||||||
if(!keys_locked && !dont_go_to_menu)
|
if(!keys_locked && !dont_go_to_menu)
|
||||||
{
|
{
|
||||||
lcd_stop_scroll();
|
lcd_stop_scroll();
|
||||||
|
button_set_release(old_release_mask);
|
||||||
main_menu();
|
main_menu();
|
||||||
|
old_release_mask = button_set_release(RELEASE_MASK);
|
||||||
id3 = mpeg_current_track();
|
id3 = mpeg_current_track();
|
||||||
draw_screen(id3);
|
draw_screen(id3);
|
||||||
/* Prevent any stray BUTTON_REL events from going
|
|
||||||
back to the main menu until we get a new
|
|
||||||
BUTTON_MENU event */
|
|
||||||
dont_go_to_menu = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -319,12 +426,18 @@ int wps_show(void)
|
||||||
#ifdef HAVE_RECORDER_KEYPAD
|
#ifdef HAVE_RECORDER_KEYPAD
|
||||||
case BUTTON_OFF:
|
case BUTTON_OFF:
|
||||||
#else
|
#else
|
||||||
case BUTTON_DOWN:
|
case BUTTON_STOP:
|
||||||
#endif
|
#endif
|
||||||
if (keys_locked)
|
if (keys_locked)
|
||||||
|
{
|
||||||
|
display_keylock_text(keys_locked);
|
||||||
|
draw_screen(id3);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
mpeg_stop();
|
mpeg_stop();
|
||||||
status_set_playmode(STATUS_STOP);
|
status_set_playmode(STATUS_STOP);
|
||||||
|
button_set_release(old_release_mask);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifndef SIMULATOR
|
#ifndef SIMULATOR
|
||||||
|
|
Loading…
Reference in a new issue