1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #include "backlight.h"
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
33 #include "mp3_playback.h"
42 #include "powermgmt.h"
53 #include "statusbar.h"
54 #include "screen_access.h"
55 #include "quickscreen.h"
60 #ifdef HAVE_LCD_BITMAP
61 #include <bitmaps/usblogo.h>
64 #ifdef HAVE_REMOTE_LCD
65 #include <bitmaps/remote_usblogo.h>
71 #if CONFIG_CODEC == SWCODEC
75 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
83 /* only used in set_time screen */
84 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
85 static int clamp_value_wrap(int value
, int max
, int min
)
101 bool statusbar
= global_settings
.statusbar
; /* force the statusbar */
102 global_settings
.statusbar
= true;
104 show_main_backdrop();
106 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
107 show_remote_main_backdrop();
111 screens
[i
].backlight_on();
112 screens
[i
].clear_display();
114 if (i
== SCREEN_REMOTE
)
116 screens
[i
].bitmap(remote_usblogo
,
117 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
118 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
119 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
124 #ifdef HAVE_LCD_BITMAP
125 screens
[i
].transparent_bitmap(usblogo
,
126 (LCD_WIDTH
-BMPWIDTH_usblogo
),
127 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
128 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
130 screens
[i
].double_height(false);
131 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
132 status_set_param(false);
133 status_set_audio(false);
134 status_set_usb(true);
135 #endif /* HAVE_LCD_BITMAP */
142 gui_syncstatusbar_draw(&statusbars
, true);
144 while (button_get(true) & BUTTON_REL
);
146 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
147 while(usb_wait_for_disconnect_w_tmo(&button_queue
, HZ
)) {
149 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
150 led(mmc_usb_active(HZ
));
151 #endif /* HAVE_MMC */
152 gui_syncstatusbar_draw(&statusbars
, false);
155 #endif /* SIMULATOR */
156 #ifdef HAVE_LCD_CHARCELLS
157 status_set_usb(false);
158 #endif /* HAVE_LCD_CHARCELLS */
160 screens
[i
].backlight_on();
161 global_settings
.statusbar
= statusbar
;
162 #endif /* USB_NONE */
166 int mmc_remove_request(void)
168 struct queue_event ev
;
171 screens
[i
].clear_display();
172 gui_syncsplash(1, str(LANG_REMOVE_MMC
));
173 if (global_settings
.talk_menu
)
174 talk_id(LANG_REMOVE_MMC
, false);
178 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
181 case SYS_HOTSWAP_EXTRACTED
:
182 return SYS_HOTSWAP_EXTRACTED
;
184 case SYS_USB_DISCONNECTED
:
185 return SYS_USB_DISCONNECTED
;
191 /* the charging screen is only used for archos targets */
192 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
194 #ifdef HAVE_LCD_BITMAP
195 static void charging_display_info(bool animate
)
197 unsigned char charging_logo
[36];
198 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
199 const int pox_y
= 32;
200 static unsigned phase
= 3;
205 #ifdef NEED_ATA_POWER_BATT_MEASURE
206 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
209 int battv
= battery_voltage();
210 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
211 (battv
% 1000) / 10, battery_level());
215 #if CONFIG_CHARGING == CHARGING_CONTROL
217 snprintf(buf
, 32, "Charge mode:");
220 if (charge_state
== CHARGING
)
221 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
222 else if (charge_state
== TOPOFF
)
223 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
224 else if (charge_state
== TRICKLE
)
225 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
227 snprintf(buf
, 32, "not charging");
230 if (!charger_enabled
)
232 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
236 memset(charging_logo
+3, 0x00, 32);
237 charging_logo
[0] = 0x3C;
238 charging_logo
[1] = 0x24;
239 charging_logo
[2] = charging_logo
[35] = 0xFF;
242 { /* draw the outline */
244 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
245 lcd_set_drawmode(DRMODE_FG
);
247 charging_logo
[0] = charging_logo
[1] = 0x00;
248 memset(charging_logo
+2, 0x80, 34);
249 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
251 memset(charging_logo
+2, 0x01, 34);
252 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16, sizeof(charging_logo
), 8);
253 lcd_set_drawmode(DRMODE_SOLID
);
256 { /* animate the middle part */
257 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
259 if ((i
-phase
) % 8 == 0)
260 { /* draw a "bubble" here */
262 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
264 bitpos
= 14 - bitpos
;
265 charging_logo
[i
] = 0x01 << bitpos
;
268 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8, sizeof(charging_logo
), 8);
273 #else /* not HAVE_LCD_BITMAP */
275 static unsigned long logo_chars
[4];
276 static const unsigned char logo_pattern
[] = {
277 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
278 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
279 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
280 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
283 static void logo_lock_patterns(bool on
)
289 for (i
= 0; i
< 4; i
++)
290 logo_chars
[i
] = lcd_get_locked_pattern();
294 for (i
= 0; i
< 4; i
++)
295 lcd_unlock_pattern(logo_chars
[i
]);
299 static void charging_display_info(bool animate
)
303 static unsigned phase
= 3;
306 battv
= battery_voltage();
307 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
310 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
312 if (!animate
) /* build the screen */
314 lcd_double_height(false);
315 lcd_puts(0, 0, "[Charging]");
316 for (i
= 0; i
< 4; i
++)
317 lcd_putc(i
, 1, logo_chars
[i
]);
319 else /* animate the logo */
321 for (i
= 3; i
< MIN(19, phase
); i
++)
323 if ((i
- phase
) % 5 == 0)
324 { /* draw a "bubble" here */
325 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
328 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10 >> (i
%5);
334 for (i
= 0; i
< 4; i
++)
335 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
339 #endif /* (not) HAVE_LCD_BITMAP */
341 /* blocks while charging, returns on event:
342 1 if charger cable was removed
343 2 if Off/Stop key was pressed
344 3 if On key was pressed
345 4 if USB was connected */
347 int charging_screen(void)
352 ide_power_enable(false); /* power down the disk, else would be spinning */
355 backlight_set_timeout(global_settings
.backlight_timeout
);
356 #ifdef HAVE_REMOTE_LCD
357 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
359 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
360 gui_syncstatusbar_draw(&statusbars
, true);
362 #ifdef HAVE_LCD_CHARCELLS
363 logo_lock_patterns(true);
365 charging_display_info(false);
369 gui_syncstatusbar_draw(&statusbars
, false);
370 charging_display_info(true);
371 button
= get_action(CONTEXT_STD
,HZ
/3);
372 if (button
== ACTION_STD_OK
)
374 else if (usb_detect())
376 else if (!charger_inserted())
380 #ifdef HAVE_LCD_CHARCELLS
381 logo_lock_patterns(false);
385 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
387 #ifdef HAVE_PITCHSCREEN
389 #define PITCH_MAX 2000
390 #define PITCH_MIN 500
391 #define PITCH_SMALL_DELTA 1
392 #define PITCH_BIG_DELTA 10
393 #define PITCH_NUDGE_DELTA 20
395 #define PITCH_MODE_ABSOLUTE 1
396 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
398 static int pitch_mode
= PITCH_MODE_ABSOLUTE
; /* 1 - absolute, -1 - semitone */
401 0 if no key was pressed
402 1 if USB was connected */
404 static void pitch_screen_draw(struct screen
*display
, int pitch
, int pitch_mode
)
407 unsigned char buf
[32];
410 display
->clear_display();
412 if (display
->nb_lines
< 4) /* very small screen, just show the pitch value */
414 w
= snprintf((char *)buf
, sizeof(buf
), "%s: %d.%d%%",str(LANG_PITCH
),
415 pitch
/ 10, pitch
% 10 );
416 display
->putsxy((display
->width
-(w
*display
->char_width
))/2,
417 display
->nb_lines
/2,buf
);
419 else /* bigger screen, show everything... */
423 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
424 ptr
= str(LANG_PITCH_UP
);
426 ptr
= str(LANG_PITCH_UP_SEMITONE
);
428 display
->getstringsize(ptr
,&w
,&h
);
429 display
->putsxy((display
->width
-w
)/2, 0, ptr
);
430 display
->mono_bitmap(bitmap_icons_7x8
[Icon_UpArrow
],
431 display
->width
/2 - 3, h
, 7, 8);
433 /* DOWN: Pitch Down */
434 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
435 ptr
= str(LANG_PITCH_DOWN
);
437 ptr
= str(LANG_PITCH_DOWN_SEMITONE
);
439 display
->getstringsize(ptr
,&w
,&h
);
440 display
->putsxy((display
->width
-w
)/2, display
->height
- h
, ptr
);
441 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
],
442 display
->width
/2 - 3, display
->height
- h
*2, 7, 8);
446 display
->getstringsize(ptr
,&w
,&h
);
447 display
->putsxy(display
->width
-w
, (display
->height
-h
)/2, ptr
);
448 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
449 display
->width
-w
-8, (display
->height
-h
)/2, 7, 8);
453 display
->getstringsize(ptr
,&w
,&h
);
454 display
->putsxy(0, (display
->height
-h
)/2, ptr
);
455 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
],
456 w
+1, (display
->height
-h
)/2, 7, 8);
459 snprintf((char *)buf
, sizeof(buf
), str(LANG_PITCH
));
460 display
->getstringsize(buf
,&w
,&h
);
461 display
->putsxy((display
->width
-w
)/2, (display
->height
/2)-h
, buf
);
463 snprintf((char *)buf
, sizeof(buf
), "%d.%d%%",
464 pitch
/ 10, pitch
% 10 );
465 display
->getstringsize(buf
,&w
,&h
);
466 display
->putsxy((display
->width
-w
)/2, display
->height
/2, buf
);
472 static int pitch_increase(int pitch
, int delta
, bool allow_cutoff
)
477 if (pitch
+ delta
>= PITCH_MIN
) {
478 new_pitch
= pitch
+ delta
;
483 new_pitch
= PITCH_MIN
;
485 } else if (delta
> 0) {
486 if (pitch
+ delta
<= PITCH_MAX
) {
487 new_pitch
= pitch
+ delta
;
492 new_pitch
= PITCH_MAX
;
495 /* delta == 0 -> no real change */
498 sound_set_pitch(new_pitch
);
503 /* Factor for changing the pitch one half tone up.
504 The exact value is 2^(1/12) = 1.05946309436
505 But we use only integer arithmetics, so take
506 rounded factor multiplied by 10^5=100,000. This is
507 enough to get the same promille values as if we
508 had used floating point (checked with a spread
511 #define PITCH_SEMITONE_FACTOR 105946L
513 /* Some helpful constants. K is the scaling factor for SEMITONE.
514 N is for more accurate rounding
517 #define PITCH_K_FCT 100000UL
518 #define PITCH_N_FCT 10
519 #define PITCH_KN_FCT 1000000UL
521 static int pitch_increase_semitone(int pitch
, bool up
)
524 uint32_t round_fct
; /* How much to scale down at the end */
527 tmp
= tmp
* PITCH_SEMITONE_FACTOR
;
528 round_fct
= PITCH_K_FCT
;
530 tmp
= (tmp
* PITCH_KN_FCT
) / PITCH_SEMITONE_FACTOR
;
531 round_fct
= PITCH_N_FCT
;
533 /* Scaling down with rounding */
534 tmp
= (tmp
+ round_fct
/ 2) / round_fct
;
535 return pitch_increase(pitch
, tmp
- pitch
, false);
538 bool pitch_screen(void)
541 int pitch
= sound_get_pitch();
542 int new_pitch
, delta
= 0;
547 #if CONFIG_CODEC == SWCODEC
548 pcmbuf_set_low_latency(true);
554 pitch_screen_draw(&screens
[i
], pitch
, pitch_mode
);
556 button
= get_action(CONTEXT_PITCHSCREEN
,TIMEOUT_BLOCK
);
558 case ACTION_PS_INC_SMALL
:
559 delta
= PITCH_SMALL_DELTA
;
562 case ACTION_PS_INC_BIG
:
563 delta
= PITCH_BIG_DELTA
;
566 case ACTION_PS_DEC_SMALL
:
567 delta
= -PITCH_SMALL_DELTA
;
570 case ACTION_PS_DEC_BIG
:
571 delta
= -PITCH_BIG_DELTA
;
574 case ACTION_PS_NUDGE_RIGHT
:
575 new_pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false);
576 nudged
= (new_pitch
!= pitch
);
580 case ACTION_PS_NUDGE_RIGHTOFF
:
582 pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false);
587 case ACTION_PS_NUDGE_LEFT
:
588 new_pitch
= pitch_increase(pitch
, -PITCH_NUDGE_DELTA
, false);
589 nudged
= (new_pitch
!= pitch
);
593 case ACTION_PS_NUDGE_LEFTOFF
:
595 pitch
= pitch_increase(pitch
, PITCH_NUDGE_DELTA
, false);
600 case ACTION_PS_RESET
:
602 sound_set_pitch( pitch
);
605 case ACTION_PS_TOGGLE_MODE
:
606 pitch_mode
= -pitch_mode
;
614 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
621 if (pitch_mode
== PITCH_MODE_ABSOLUTE
) {
622 pitch
= pitch_increase(pitch
, delta
, true);
624 pitch
= pitch_increase_semitone(pitch
, delta
> 0 ? true:false);
631 #if CONFIG_CODEC == SWCODEC
632 pcmbuf_set_low_latency(false);
634 lcd_setfont(FONT_UI
);
637 #endif /* HAVE_PITCHSCREEN */
639 #ifdef HAVE_QUICKSCREEN
641 #define bool_to_int(b)\
643 #define int_to_bool(i)\
646 static void quick_screen_quick_apply(struct gui_quickscreen
*qs
)
648 global_settings
.playlist_shuffle
=int_to_bool(qs
->left_option
->option
);
649 global_settings
.dirfilter
=qs
->bottom_option
->option
;
650 global_settings
.repeat_mode
=qs
->right_option
->option
;
653 bool quick_screen_quick(int button_enter
)
655 bool res
, oldshuffle
;
656 struct option_select left_option
;
657 struct option_select bottom_option
;
658 struct option_select right_option
;
659 int oldrepeat
, old_x_margin
, old_y_margin
;
661 static const struct opt_items left_items
[] = {
662 [0]={ STR(LANG_SYSFONT_OFF
) },
663 [1]={ STR(LANG_SYSFONT_ON
) }
665 static const struct opt_items bottom_items
[] = {
666 [SHOW_ALL
]={ STR(LANG_SYSFONT_ALL
) },
667 [SHOW_SUPPORTED
]={ STR(LANG_SYSFONT_FILTER_SUPPORTED
) },
668 [SHOW_MUSIC
]={ STR(LANG_SYSFONT_FILTER_MUSIC
) },
669 [SHOW_PLAYLIST
]={ STR(LANG_SYSFONT_FILTER_PLAYLIST
) },
671 static const struct opt_items right_items
[] = {
672 [REPEAT_OFF
]={ STR(LANG_SYSFONT_OFF
) },
673 [REPEAT_ALL
]={ STR(LANG_SYSFONT_ALL
) },
674 [REPEAT_ONE
]={ STR(LANG_SYSFONT_REPEAT_ONE
) },
675 [REPEAT_SHUFFLE
]={ STR(LANG_SYSFONT_SHUFFLE
) },
676 #ifdef AB_REPEAT_ENABLE
677 [REPEAT_AB
]={ STR(LANG_SYSFONT_REPEAT_AB
) }
680 struct gui_quickscreen qs
;
682 old_x_margin
= lcd_getxmargin();
683 old_y_margin
= lcd_getymargin();
684 lcd_setmargins(0, 0);
686 option_select_init_items(&left_option
,
687 (char *)str(LANG_SYSFONT_SHUFFLE
),
688 bool_to_int(global_settings
.playlist_shuffle
),
691 option_select_init_items(&bottom_option
,
692 (char *)str(LANG_SYSFONT_FILTER
),
693 global_settings
.dirfilter
,
695 sizeof(bottom_items
)/sizeof(struct opt_items
));
696 option_select_init_items(&right_option
,
697 (char *)str(LANG_SYSFONT_REPEAT
),
698 global_settings
.repeat_mode
,
700 sizeof(right_items
)/sizeof(struct opt_items
));
702 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
703 &quick_screen_quick_apply
);
704 oldrepeat
=global_settings
.repeat_mode
;
705 oldshuffle
=global_settings
.playlist_shuffle
;
706 res
=gui_syncquickscreen_run(&qs
, button_enter
);
709 if ( oldrepeat
!= global_settings
.repeat_mode
&&
710 (audio_status() & AUDIO_STATUS_PLAY
) )
711 audio_flush_and_reload_tracks();
712 if(oldshuffle
!= global_settings
.playlist_shuffle
713 && audio_status() & AUDIO_STATUS_PLAY
)
715 #if CONFIG_CODEC == SWCODEC
716 dsp_set_replaygain();
718 if (global_settings
.playlist_shuffle
)
719 playlist_randomise(NULL
, current_tick
, true);
721 playlist_sort(NULL
, true);
725 lcd_setmargins(old_x_margin
, old_y_margin
);
730 static void quick_screen_f3_apply(struct gui_quickscreen
*qs
)
732 global_settings
.scrollbar
=int_to_bool(qs
->left_option
->option
);
734 global_settings
.flip_display
=int_to_bool(qs
->bottom_option
->option
);
735 button_set_flip(global_settings
.flip_display
);
736 lcd_set_flip(global_settings
.flip_display
);
738 global_settings
.statusbar
=int_to_bool(qs
->right_option
->option
);
739 gui_syncstatusbar_draw(&statusbars
, true);
742 bool quick_screen_f3(int button_enter
)
745 struct option_select left_option
;
746 struct option_select bottom_option
;
747 struct option_select right_option
;
748 int old_x_margin
, old_y_margin
;
750 static const struct opt_items onoff_items
[] = {
751 [0]={ STR(LANG_SYSFONT_OFF
) },
752 [1]={ STR(LANG_SYSFONT_ON
) }
754 static const struct opt_items yesno_items
[] = {
755 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO
) },
756 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES
) }
759 struct gui_quickscreen qs
;
761 old_x_margin
= lcd_getxmargin();
762 old_y_margin
= lcd_getymargin();
763 lcd_setmargins(0, 0);
765 option_select_init_items(&left_option
,
766 str(LANG_SYSFONT_SCROLL_BAR
),
767 bool_to_int(global_settings
.scrollbar
),
770 option_select_init_items(&bottom_option
,
771 str(LANG_SYSFONT_FLIP_DISPLAY
),
772 bool_to_int(global_settings
.flip_display
),
775 option_select_init_items(&right_option
,
776 str(LANG_SYSFONT_STATUS_BAR
),
777 bool_to_int(global_settings
.statusbar
),
780 gui_quickscreen_init(&qs
, &left_option
, &bottom_option
, &right_option
,
781 &quick_screen_f3_apply
);
782 res
=gui_syncquickscreen_run(&qs
, button_enter
);
785 lcd_setmargins(old_x_margin
, old_y_margin
);
788 #endif /* BUTTON_F3 */
789 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
792 void charging_splash(void)
794 gui_syncsplash(2*HZ
, (unsigned char *)str(LANG_BATTERY_CHARGE
));
795 button_clear_queue();
800 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
802 /* little helper function for voice output */
803 static void say_time(int cursorpos
, const struct tm
*tm
)
808 if (!global_settings
.talk_menu
)
826 value
= tm
->tm_year
+ 1900;
833 if (cursorpos
== 4) /* month */
834 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
836 talk_value(value
, unit
, false);
843 #define SEPARATOR ":"
844 bool set_time_screen(const char* title
, struct tm
*tm
)
848 unsigned int i
, j
, s
;
850 unsigned int julianday
;
851 unsigned int realyear
;
853 unsigned int min
, max
;
854 unsigned int statusbar_height
= 0;
855 unsigned int separator_width
, weekday_width
;
856 unsigned int prev_line_height
;
857 int daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
858 unsigned char buffer
[20];
860 /* 6 possible cursor possitions, 2 values stored for each: x, y */
861 unsigned int cursor
[6][2];
864 unsigned char *ptr
[6];
866 if(global_settings
.statusbar
)
867 statusbar_height
= STATUSBAR_HEIGHT
;
869 /* speak selection when screen is entered */
870 say_time(cursorpos
, tm
);
873 /* for easy acess in the drawing loop */
874 ptr
[0] = buffer
; /* hours */
875 ptr
[1] = buffer
+ 3; /* minutes */
876 ptr
[2] = buffer
+ 6; /* seconds */
877 ptr
[3] = buffer
+ 9; /* year */
878 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
879 ptr
[5] = buffer
+ 14; /* day of month */
881 /* calculate the number of days in febuary */
882 realyear
= tm
->tm_year
+ 1900;
883 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
888 /* fix day if month or year changed */
889 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
890 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
892 /* calculate day of week */
893 julianday
= tm
->tm_mday
;
894 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
895 julianday
+= daysinmonth
[i
];
898 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
899 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
901 /* put all the numbers we want from the tm struct into
902 an easily printable buffer */
903 snprintf(buffer
, sizeof(buffer
),
904 "%02d " "%02d " "%02d " "%04d " "%02d",
905 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
906 tm
->tm_year
+1900, tm
->tm_mday
);
908 /* convert spaces in the buffer to '\0' to make it possible to work
909 directly on the buffer */
910 for(i
=0; i
< sizeof(buffer
); i
++)
918 /* minimum lines needed is 2 + title line */
919 gui_textarea_update_nblines(&screens
[s
]);
920 if (screens
[s
].nb_lines
< 4)
922 screens
[s
].setfont(FONT_SYSFIXED
);
923 gui_textarea_update_nblines(&screens
[s
]);
926 /* recalculate the positions and offsets */
927 if (screens
[s
].nb_lines
>= 3)
928 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
930 prev_line_height
= 0;
932 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
935 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
), &weekday_width
, NULL
);
936 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
938 for(i
=0, j
=0; i
< 6; i
++)
940 if(i
==3) /* second row */
942 j
= weekday_width
+ separator_width
;;
943 prev_line_height
*= 2;
945 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
946 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
947 cursor
[i
][INDEX_X
] = j
;
948 j
+= width
+ separator_width
;
951 /* draw the screen */
952 screens
[s
].set_drawmode(DRMODE_SOLID
);
953 gui_textarea_clear(&screens
[s
]);
954 /* display the screen title */
955 screens
[s
].puts_scroll(0, 0, title
);
957 /* these are not selectable, so we draw them outside the loop */
958 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
], str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
)); /* name of the week day */
960 /* draw the selected item with drawmode set to
961 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
962 items with drawmode DRMODE_SOLID */
965 if (cursorpos
== (int)i
)
966 screens
[s
].set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
968 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
969 cursor
[i
][INDEX_Y
], ptr
[i
]);
971 screens
[s
].set_drawmode(DRMODE_SOLID
);
973 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
974 cursor
[0][INDEX_Y
], SEPARATOR
);
977 /* print help text */
978 if (screens
[s
].nb_lines
> 4)
979 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
980 if (screens
[s
].nb_lines
> 5)
981 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
984 gui_syncstatusbar_draw(&statusbars
, true);
986 /* set the most common numbers */
989 /* calculate the minimum and maximum for the number under cursor */
993 valptr
= &tm
->tm_hour
;
996 valptr
= &tm
->tm_min
;
999 valptr
= &tm
->tm_sec
;
1004 valptr
= &tm
->tm_year
;
1008 valptr
= &tm
->tm_mon
;
1012 max
= daysinmonth
[tm
->tm_mon
];
1013 valptr
= &tm
->tm_mday
;
1017 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
1019 case ACTION_STD_PREV
:
1020 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
1021 say_time(cursorpos
, tm
);
1023 case ACTION_STD_NEXT
:
1024 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
1025 say_time(cursorpos
, tm
);
1027 case ACTION_SETTINGS_INC
:
1028 case ACTION_SETTINGS_INCREPEAT
:
1029 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
1030 say_time(cursorpos
, tm
);
1032 case ACTION_SETTINGS_DEC
:
1033 case ACTION_SETTINGS_DECREPEAT
:
1034 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
1035 say_time(cursorpos
, tm
);
1042 case ACTION_STD_CANCEL
:
1048 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
1055 screens
[i
].setfont(FONT_UI
);
1056 gui_textarea_update_nblines(&screens
[i
]);
1060 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1062 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1063 bool shutdown_screen(void)
1067 long time_entered
= current_tick
;
1071 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN
));
1073 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
1075 button
= get_action(CONTEXT_STD
,HZ
);
1078 case ACTION_STD_CANCEL
:
1082 /* do nothing here, because ACTION_NONE might be caused
1083 * by timeout or button release. In case of timeout the loop
1084 * is terminated by TIME_BEFORE */
1089 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1099 static const int id3_headers
[]=
1104 LANG_ID3_ALBUMARTIST
,
1115 #if CONFIG_CODEC == SWCODEC
1116 LANG_ID3_TRACK_GAIN
,
1117 LANG_ID3_ALBUM_GAIN
,
1122 static char * id3_get_info(int selected_item
, void* data
, char *buffer
)
1124 struct mp3entry
* id3
=(struct mp3entry
*)data
;
1125 int info_no
=selected_item
/2;
1126 if(!(selected_item
%2))
1128 return( str(id3_headers
[info_no
]));
1136 case 0:/*LANG_ID3_TITLE*/
1139 case 1:/*LANG_ID3_ARTIST*/
1142 case 2:/*LANG_ID3_ALBUM*/
1145 case 3:/*LANG_ID3_ALBUMARTIST*/
1146 info
=id3
->albumartist
;
1148 case 4:/*LANG_ID3_GROUPING*/
1151 case 5:/*LANG_ID3_DISCNUM*/
1152 if (id3
->disc_string
)
1153 info
= id3
->disc_string
;
1154 else if (id3
->discnum
)
1156 snprintf(buffer
, MAX_PATH
, "%d", id3
->discnum
);
1160 case 6:/*LANG_ID3_TRACKNUM*/
1161 if (id3
->track_string
)
1162 info
= id3
->track_string
;
1163 else if (id3
->tracknum
)
1165 snprintf(buffer
, MAX_PATH
, "%d", id3
->tracknum
);
1169 case 7:/*LANG_ID3_COMMENT*/
1172 case 8:/*LANG_ID3_GENRE*/
1173 info
= id3
->genre_string
;
1175 case 9:/*LANG_ID3_YEAR*/
1176 if (id3
->year_string
)
1177 info
= id3
->year_string
;
1180 snprintf(buffer
, MAX_PATH
, "%d", id3
->year
);
1184 case 10:/*LANG_ID3_LENGTH*/
1185 format_time(buffer
, MAX_PATH
, id3
->length
);
1188 case 11:/*LANG_ID3_PLAYLIST*/
1189 snprintf(buffer
, MAX_PATH
, "%d/%d", playlist_get_display_index(),
1193 case 12:/*LANG_ID3_BITRATE*/
1194 snprintf(buffer
, MAX_PATH
, "%d kbps%s", id3
->bitrate
,
1195 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
1198 case 13:/*LANG_ID3_FREQUENCY*/
1199 snprintf(buffer
, MAX_PATH
, "%ld Hz", id3
->frequency
);
1202 #if CONFIG_CODEC == SWCODEC
1203 case 14:/*LANG_ID3_TRACK_GAIN*/
1204 info
=id3
->track_gain_string
;
1206 case 15:/*LANG_ID3_ALBUM_GAIN*/
1207 info
=id3
->album_gain_string
;
1209 case 16:/*LANG_ID3_PATH*/
1211 case 14:/*LANG_ID3_PATH*/
1216 return info
&& *info
? info
: (char*) str(LANG_ID3_NO_INFO
);
1220 bool browse_id3(void)
1222 struct gui_synclist id3_lists
;
1223 struct mp3entry
* id3
= audio_current_track();
1226 gui_synclist_init(&id3_lists
, &id3_get_info
, id3
, true, 2);
1227 gui_synclist_set_nb_items(&id3_lists
,
1228 sizeof(id3_headers
)/sizeof(id3_headers
[0])*2);
1229 gui_synclist_draw(&id3_lists
);
1230 gui_syncstatusbar_draw(&statusbars
, true);
1232 gui_syncstatusbar_draw(&statusbars
, false);
1233 key
= get_action(CONTEXT_LIST
,HZ
/2);
1234 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
1235 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
1237 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
1242 static char* runtime_get_data(int selected_item
, void* data
, char* buffer
)
1245 unsigned char *headers
[] = {str(LANG_RUNNING_TIME
), str(LANG_TOP_TIME
) };
1247 if(!(selected_item
%2))
1248 return headers
[selected_item
/2];
1250 if(selected_item
/2) t
= global_status
.topruntime
;
1251 else t
= global_status
.runtime
;
1253 snprintf(buffer
, 16, "%dh %dm %ds",
1254 t
/ 3600, (t
% 3600) / 60, t
% 60);
1259 static int runtime_speak_data(int selected_item
, void* data
)
1262 long title_ids
[] = {LANG_RUNNING_TIME
, LANG_TOP_TIME
};
1264 title_ids
[selected_item
/2],
1265 TALK_ID((selected_item
== 0) ? global_status
.runtime
1266 : global_status
.topruntime
, UNIT_TIME
));
1271 bool view_runtime(void)
1273 unsigned char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
1274 struct text_message message
={(char **)lines
, 1};
1276 struct gui_synclist lists
;
1278 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2);
1279 #if !defined(HAVE_LCD_CHARCELLS)
1280 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1282 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1284 if(global_settings
.talk_menu
)
1285 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
1286 gui_synclist_set_icon_callback(&lists
, NULL
);
1287 gui_synclist_set_nb_items(&lists
, 4);
1288 gui_synclist_speak_item(&lists
);
1292 if (charger_inserted()
1293 #ifdef HAVE_USB_POWER
1298 global_status
.runtime
= 0;
1303 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1305 lasttime
= current_tick
;
1306 gui_synclist_draw(&lists
);
1307 gui_syncstatusbar_draw(&statusbars
, true);
1308 list_do_action(CONTEXT_STD
, HZ
,
1309 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1310 if(action
== ACTION_STD_CANCEL
)
1312 if(action
== ACTION_STD_OK
) {
1313 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1315 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1316 global_status
.runtime
= 0;
1318 global_status
.topruntime
= 0;
1319 gui_synclist_speak_item(&lists
);
1322 if(default_event_handler(action
) == SYS_USB_CONNECTED
)