1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
33 #include "lcd-remote.h"
36 #include "timefuncs.h"
41 #include "mp3_playback.h"
44 #include "ata_idle_notify.h"
47 #include "powermgmt.h"
48 #include "backlight.h"
53 #include "scrobbler.h"
62 #include "eeprom_settings.h"
63 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
64 #include "recording.h"
66 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
69 #endif /* End HAVE_LCD_BITMAP */
70 #include "gui/gwps-common.h"
77 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
83 /* Format a large-range value for output, using the appropriate unit so that
84 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
85 * units) if possible, and 3 significant digits are shown. If a buffer is
86 * given, the result is snprintf()'d into that buffer, otherwise the result is
88 char *output_dyn_value(char *buf
, int buf_size
, int value
,
89 const unsigned char **units
, bool bin_scale
)
91 int scale
= bin_scale
? 1024 : 1000;
96 while (value
>= scale
)
98 fraction
= value
% scale
;
103 fraction
= fraction
* 1000 / 1024;
105 if (value
>= 100 || !unit_no
)
107 else if (value
>= 10)
108 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
110 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
115 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
116 tbuf
, P2STR(units
[unit_no
]));
118 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
122 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
127 /* Create a filename with a number part in a way that the number is 1
128 * higher than the highest numbered file matching the same pattern.
129 * It is allowed that buffer and path point to the same memory location,
130 * saving a strcpy(). Path must always be given without trailing slash.
131 * "num" can point to an int specifying the number to use or NULL or a value
132 * less than zero to number automatically. The final number used will also
133 * be returned in *num. If *num is >= 0 then *num will be incremented by
135 char *create_numbered_filename(char *buffer
, const char *path
,
136 const char *prefix
, const char *suffix
,
137 int numberlen
IF_CNFN_NUM_(, int *num
))
140 struct dirent
*entry
;
143 int prefixlen
= strlen(prefix
);
147 strncpy(buffer
, path
, MAX_PATH
);
149 pathlen
= strlen(buffer
);
152 if (num
&& *num
>= 0)
154 /* number specified */
160 /* automatic numbering */
163 dir
= opendir(pathlen
? buffer
: "/");
167 while ((entry
= readdir(dir
)))
171 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
172 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
175 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
176 if (curr_num
> max_num
)
185 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
186 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
197 /* Format time into buf.
199 * buf - buffer to format to.
200 * buf_size - size of buffer.
201 * t - time to format, in milliseconds.
203 void format_time(char* buf
, int buf_size
, long t
)
207 snprintf(buf
, buf_size
, "%d:%02d",
208 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
212 snprintf(buf
, buf_size
, "%d:%02d:%02d",
213 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
214 (int) (t
% 60000 / 1000));
219 /* Create a filename with a date+time part.
220 It is allowed that buffer and path point to the same memory location,
221 saving a strcpy(). Path must always be given without trailing slash.
222 unique_time as true makes the function wait until the current time has
224 char *create_datetime_filename(char *buffer
, const char *path
,
225 const char *prefix
, const char *suffix
,
228 struct tm
*tm
= get_time();
229 static struct tm last_tm
;
232 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
238 strncpy(buffer
, path
, MAX_PATH
);
240 pathlen
= strlen(buffer
);
241 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
242 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
243 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
244 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
248 #endif /* CONFIG_RTC */
250 /* Ask the user if they really want to erase the current dynamic playlist
251 * returns true if the playlist should be replaced */
252 bool warn_on_pl_erase(void)
254 if (global_settings
.warnon_erase_dynplaylist
&&
255 !global_settings
.party_mode
&&
256 playlist_modified(NULL
))
258 static const char *lines
[] =
259 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
260 static const struct text_message message
={lines
, 1};
262 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
268 /* Read (up to) a line of text from fd into buffer and return number of bytes
269 * read (which may be larger than the number of bytes stored in buffer). If
270 * an error occurs, -1 is returned (and buffer contains whatever could be
271 * read). A line is terminated by a LF char. Neither LF nor CR chars are
274 int read_line(int fd
, char* buffer
, int buffer_size
)
281 while (count
< buffer_size
)
285 if (1 != read(fd
, &c
, 1))
299 buffer
[MIN(count
, buffer_size
- 1)] = 0;
301 return errno
? -1 : num_read
;
304 /* Performance optimized version of the previous function. */
305 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
306 int (*callback
)(int n
, const char *buf
, void *parameters
))
316 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
320 if ( (p
= strchr(buf
, '\r')) != NULL
)
328 if ( (p
= strchr(p
, '\n')) != NULL
)
334 rc
= callback(count
, buf
, parameters
);
341 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
342 memmove(buf
, next
, pos
);
351 #ifdef HAVE_LCD_BITMAP
354 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
355 #define BMP_NUMCOLORS 3
357 #define BMP_COMPRESSION 0 /* BI_RGB */
359 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
361 #define BMP_NUMCOLORS 0
367 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
370 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
373 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
374 #elif LCD_DEPTH <= 16
376 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
379 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
382 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
383 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
384 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
386 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
387 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
389 static const unsigned char bmpheader
[] =
391 0x42, 0x4d, /* 'BM' */
392 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
393 0x00, 0x00, 0x00, 0x00, /* Reserved */
394 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
396 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
397 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
398 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
399 0x01, 0x00, /* Number of planes (always 1) */
400 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
401 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
402 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
403 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
404 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
405 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
406 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
410 2, 2, 94, 0x00, /* Colour #0 */
411 3, 6, 241, 0x00 /* Colour #1 */
413 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
414 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
417 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
418 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
419 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
420 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
421 #elif LCD_DEPTH == 16
422 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
423 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
424 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
428 static void (*screen_dump_hook
)(int fh
) = NULL
;
430 void screen_dump(void)
433 char filename
[MAX_PATH
];
436 static unsigned char line_block
[8][BMP_LINESIZE
];
438 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
439 static unsigned char line_block
[BMP_LINESIZE
];
440 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
441 static unsigned char line_block
[4][BMP_LINESIZE
];
442 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
443 static unsigned char line_block
[8][BMP_LINESIZE
];
445 #elif LCD_DEPTH == 16
446 static unsigned short line_block
[BMP_LINESIZE
/2];
450 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
452 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
453 IF_CNFN_NUM_(, NULL
));
456 fh
= creat(filename
);
460 if (screen_dump_hook
)
462 screen_dump_hook(fh
);
466 write(fh
, bmpheader
, sizeof(bmpheader
));
468 /* BMP image goes bottom up */
470 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
472 unsigned char *src
= &lcd_framebuffer
[by
][0];
473 unsigned char *dst
= &line_block
[0][0];
475 memset(line_block
, 0, sizeof(line_block
));
476 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
478 unsigned dst_mask
= 0x80;
481 for (ix
= 8; ix
> 0; ix
--)
483 unsigned char *dst_blk
= dst
;
484 unsigned src_byte
= *src
++;
487 for (iy
= 8; iy
> 0; iy
--)
490 *dst_blk
|= dst_mask
;
492 dst_blk
+= BMP_LINESIZE
;
499 write(fh
, line_block
, sizeof(line_block
));
502 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
503 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
505 unsigned char *src
= &lcd_framebuffer
[by
][0];
506 unsigned char *dst
= line_block
;
508 memset(line_block
, 0, sizeof(line_block
));
509 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
511 unsigned src_byte
= *src
++;
513 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
514 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
517 write(fh
, line_block
, sizeof(line_block
));
519 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
520 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
522 unsigned char *src
= &lcd_framebuffer
[by
][0];
523 unsigned char *dst
= &line_block
[3][0];
525 memset(line_block
, 0, sizeof(line_block
));
526 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
528 unsigned char *dst_blk
= dst
++;
529 unsigned src_byte0
= *src
++ << 4;
530 unsigned src_byte1
= *src
++;
533 for (iy
= 4; iy
> 0; iy
--)
535 *dst_blk
= (src_byte0
& 0x30) | (src_byte1
& 0x03);
538 dst_blk
-= BMP_LINESIZE
;
542 write(fh
, line_block
, sizeof(line_block
));
544 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
545 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
547 const fb_data
*src
= &lcd_framebuffer
[by
][0];
548 unsigned char *dst
= &line_block
[7][0];
550 memset(line_block
, 0, sizeof(line_block
));
551 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
553 unsigned char *dst_blk
= dst
++;
554 unsigned src_data0
= *src
++ << 4;
555 unsigned src_data1
= *src
++;
558 for (iy
= 8; iy
> 0; iy
--)
560 *dst_blk
= (src_data0
& 0x10) | (src_data1
& 0x01)
561 | ((src_data0
& 0x1000) | (src_data1
& 0x0100)) >> 7;
564 dst_blk
-= BMP_LINESIZE
;
568 write(fh
, line_block
, sizeof(line_block
));
571 #elif LCD_DEPTH == 16
572 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
574 unsigned short *src
= &lcd_framebuffer
[by
][0];
575 unsigned short *dst
= line_block
;
577 memset(line_block
, 0, sizeof(line_block
));
578 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
580 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
581 /* iPod LCD data is big endian although the CPU is not */
582 *dst
++ = htobe16(*src
++);
584 *dst
++ = htole16(*src
++);
588 write(fh
, line_block
, sizeof(line_block
));
590 #endif /* LCD_DEPTH */
596 void screen_dump_set_hook(void (*hook
)(int fh
))
598 screen_dump_hook
= hook
;
601 #endif /* HAVE_LCD_BITMAP */
603 /* parse a line from a configuration file. the line format is:
607 Any whitespace before setting name or value (after ':') is ignored.
608 A # as first non-whitespace character discards the whole line.
609 Function sets pointers to null-terminated setting name and value.
610 Returns false if no valid config entry was found.
613 bool settings_parseline(char* line
, char** name
, char** value
)
617 while ( isspace(*line
) )
623 ptr
= strchr(line
, ':');
630 while (isspace(*ptr
))
636 static void system_flush(void)
639 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
642 static void system_restore(void)
647 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
652 bookmark_autobookmark();
653 call_ata_idle_notifys(true);
659 scrobbler_poweroff();
661 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
662 if(!charger_inserted())
665 bool batt_safe
= battery_level_safe();
666 int audio_stat
= audio_status();
669 screens
[i
].clear_display();
674 if (!tagcache_prepare_shutdown())
677 gui_syncsplash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
681 if (battery_level() > 10)
682 gui_syncsplash(0, str(LANG_SHUTTINGDOWN
));
685 msg_id
= LANG_WARNING_BATTERY_LOW
;
686 gui_syncsplash(0, "%s %s",
687 str(LANG_WARNING_BATTERY_LOW
),
688 str(LANG_SHUTTINGDOWN
));
693 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
694 gui_syncsplash(0, "%s %s",
695 str(LANG_WARNING_BATTERY_EMPTY
),
696 str(LANG_SHUTTINGDOWN
));
699 if (global_settings
.fade_on_stop
700 && (audio_stat
& AUDIO_STATUS_PLAY
))
705 if (batt_safe
) /* do not save on critical battery */
707 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
708 if (audio_stat
& AUDIO_STATUS_RECORD
)
710 rec_command(RECORDING_CMD_STOP
);
711 /* wait for stop to complete */
712 while (audio_status() & AUDIO_STATUS_RECORD
)
716 bookmark_autobookmark();
718 /* audio_stop_recording == audio_stop for HWCODEC */
721 if (callback
!= NULL
)
724 #if CONFIG_CODEC != SWCODEC
725 /* wait for audio_stop or audio_stop_recording to complete */
726 while (audio_status())
730 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
731 audio_close_recording();
734 if(global_settings
.talk_menu
)
736 bool enqueue
= false;
739 talk_id(msg_id
, enqueue
);
742 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
743 #if CONFIG_CODEC == SWCODEC
749 #ifdef HAVE_EEPROM_SETTINGS
750 if (firmware_settings
.initialized
)
752 firmware_settings
.disk_clean
= true;
753 firmware_settings
.bl_version
= 0;
754 eeprom_settings_store();
769 bool list_stop_handler(void)
773 /* Stop the music if it is playing */
776 if (!global_settings
.party_mode
)
778 if (global_settings
.fade_on_stop
)
780 bookmark_autobookmark();
782 ret
= true; /* bookmarking can make a refresh necessary */
786 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
789 if (charger_inserted())
792 shutdown_screen(); /* won't return if shutdown actually happens */
794 ret
= true; /* screen is dirty, caller needs to refresh */
797 #ifndef HAVE_POWEROFF_WHILE_CHARGING
799 static long last_off
= 0;
801 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
803 if (charger_inserted())
806 ret
= true; /* screen is dirty, caller needs to refresh */
809 last_off
= current_tick
;
812 #endif /* CONFIG_CHARGING */
817 static bool waiting_to_resume_play
= false;
818 static long play_resume_tick
;
820 static void car_adapter_mode_processing(bool inserted
)
822 if (global_settings
.car_adapter_mode
)
827 * Just got plugged in, delay & resume if we were playing
829 if (audio_status() & AUDIO_STATUS_PAUSE
)
831 /* delay resume a bit while the engine is cranking */
832 play_resume_tick
= current_tick
+ HZ
*5;
833 waiting_to_resume_play
= true;
839 * Just got unplugged, pause if playing
841 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
842 !(audio_status() & AUDIO_STATUS_PAUSE
))
844 if (global_settings
.fade_on_stop
)
849 waiting_to_resume_play
= false;
854 static void car_adapter_tick(void)
856 if (waiting_to_resume_play
)
858 if (TIME_AFTER(current_tick
, play_resume_tick
))
860 if (audio_status() & AUDIO_STATUS_PAUSE
)
862 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
864 waiting_to_resume_play
= false;
869 void car_adapter_mode_init(void)
871 tick_add_task(car_adapter_tick
);
875 #ifdef HAVE_HEADPHONE_DETECTION
876 static void unplug_change(bool inserted
)
878 static bool headphone_caused_pause
= false;
880 if (global_settings
.unplug_mode
)
882 int audio_stat
= audio_status();
885 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
886 headphone_caused_pause
&&
887 global_settings
.unplug_mode
> 1 )
890 headphone_caused_pause
= false;
892 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
893 !(audio_stat
& AUDIO_STATUS_PAUSE
))
895 headphone_caused_pause
= true;
898 if (global_settings
.unplug_rw
)
900 if (audio_current_track()->elapsed
>
901 (unsigned long)(global_settings
.unplug_rw
*1000))
902 audio_ff_rewind(audio_current_track()->elapsed
-
903 (global_settings
.unplug_rw
*1000));
913 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
917 case SYS_BATTERY_UPDATE
:
918 if(global_settings
.talk_battery_level
)
920 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
922 TALK_ID(battery_level(), UNIT_PERCENT
),
924 talk_force_enqueue_next();
927 case SYS_USB_CONNECTED
:
928 if (callback
!= NULL
)
931 if (!mmc_touched() ||
932 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
935 scrobbler_flush_cache();
938 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
939 check_bootfile(false); /* gets initial size */
944 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
945 check_bootfile(true);
950 return SYS_USB_CONNECTED
;
952 if (!clean_shutdown(callback
, parameter
))
956 case SYS_CHARGER_CONNECTED
:
957 car_adapter_mode_processing(true);
958 return SYS_CHARGER_CONNECTED
;
960 case SYS_CHARGER_DISCONNECTED
:
961 car_adapter_mode_processing(false);
962 return SYS_CHARGER_DISCONNECTED
;
964 case SYS_CAR_ADAPTER_RESUME
:
966 return SYS_CAR_ADAPTER_RESUME
;
968 #ifdef HAVE_HEADPHONE_DETECTION
969 case SYS_PHONE_PLUGGED
:
971 return SYS_PHONE_PLUGGED
;
973 case SYS_PHONE_UNPLUGGED
:
974 unplug_change(false);
975 return SYS_PHONE_UNPLUGGED
;
981 long default_event_handler(long event
)
983 return default_event_handler_ex(event
, NULL
, NULL
);
986 int show_logo( void )
988 #ifdef HAVE_LCD_BITMAP
992 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
995 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
996 lcd_setfont(FONT_SYSFIXED
);
997 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
998 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
999 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
1000 lcd_setfont(FONT_UI
);
1003 char *rockbox
= " ROCKbox!";
1005 lcd_clear_display();
1006 lcd_double_height(true);
1007 lcd_puts(0, 0, rockbox
);
1008 lcd_puts_scroll(0, 1, appsversion
);
1012 #ifdef HAVE_REMOTE_LCD
1013 lcd_remote_clear_display();
1014 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
1015 BMPHEIGHT_remote_rockboxlogo
);
1016 lcd_remote_setfont(FONT_SYSFIXED
);
1017 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
1018 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
1019 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
1020 lcd_remote_setfont(FONT_UI
);
1021 lcd_remote_update();
1027 #if CONFIG_CODEC == SWCODEC
1028 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
1032 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
1033 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1034 && global_settings
.playlist_shuffle
));
1036 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
1037 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
1044 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
1046 memorize/compare details about the BOOTFILE
1047 we don't use dircache because it may not be up to date after
1048 USB disconnect (scanning in the background)
1050 void check_bootfile(bool do_rolo
)
1052 static unsigned short wrtdate
= 0;
1053 static unsigned short wrttime
= 0;
1055 struct dirent
* entry
= NULL
;
1057 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
1058 dir
= opendir(BOOTDIR
);
1060 if(!dir
) return; /* do we want an error splash? */
1062 /* loop all files in BOOTDIR */
1063 while(0 != (entry
= readdir(dir
)))
1065 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
1067 /* found the bootfile */
1068 if(wrtdate
&& do_rolo
)
1070 if((entry
->wrtdate
!= wrtdate
) ||
1071 (entry
->wrttime
!= wrttime
))
1073 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
1074 ID2P(LANG_REBOOT_NOW
) };
1075 static const struct text_message message
={ lines
, 2 };
1076 button_clear_queue(); /* Empty the keyboard buffer */
1077 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1078 rolo_load(BOOTDIR
"/" BOOTFILE
);
1081 wrtdate
= entry
->wrtdate
;
1082 wrttime
= entry
->wrttime
;
1090 /* check range, set volume and save settings */
1093 const int min_vol
= sound_min(SOUND_VOLUME
);
1094 const int max_vol
= sound_max(SOUND_VOLUME
);
1095 if (global_settings
.volume
< min_vol
)
1096 global_settings
.volume
= min_vol
;
1097 if (global_settings
.volume
> max_vol
)
1098 global_settings
.volume
= max_vol
;
1099 sound_set_volume(global_settings
.volume
);
1103 char* strrsplt(char* str
, int c
)
1105 char* s
= strrchr(str
, c
);
1119 /* Test file existence, using dircache of possible */
1120 bool file_exists(const char *file
)
1124 if (!file
|| strlen(file
) <= 0)
1127 #ifdef HAVE_DIRCACHE
1128 if (dircache_is_enabled())
1129 return (dircache_get_entry_ptr(file
) != NULL
);
1132 fd
= open(file
, O_RDONLY
);
1139 bool dir_exists(const char *path
)
1141 DIR* d
= opendir(path
);
1149 * removes the extension of filename (if it doesn't start with a .)
1150 * puts the result in buffer
1152 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
1154 char *dot
= strrchr(filename
, '.');
1157 if (buffer_size
<= 0)
1162 buffer_size
--; /* Make room for end nil */
1164 if (dot
!= 0 && filename
[0] != '.')
1166 len
= dot
- filename
;
1167 len
= MIN(len
, buffer_size
);
1168 strncpy(buffer
, filename
, len
);
1173 strncpy(buffer
, filename
, buffer_size
);
1180 #endif /* !defined(__PCTOOL__) */
1182 #ifdef HAVE_LCD_COLOR
1184 * Helper function to convert a string of 6 hex digits to a native colour
1187 static int hex2dec(int c
)
1189 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1190 (toupper(c
)) - 'A' + 10);
1193 int hex_to_rgb(const char* hex
, int* color
)
1195 int red
, green
, blue
;
1198 while ((i
< 6) && (isxdigit(hex
[i
])))
1204 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1205 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1206 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1208 *color
= LCD_RGBPACK(red
,green
,blue
);
1212 #endif /* HAVE_LCD_COLOR */
1214 #ifdef HAVE_LCD_BITMAP
1215 /* A simplified scanf - used (at time of writing) by wps parsing functions.
1217 fmt - char array specifying the format of each list option. Valid values
1219 s - string (sets pointer to string, without copying)
1220 c - hex colour (RGB888 - e.g. ff00ff)
1221 g - greyscale "colour" (0-3)
1222 set_vals - if not NULL 1 is set in the bitplace if the item was read OK
1224 first item is LSB, (max 32 items! )
1225 Stops parseing if an item is invalid unless the item == '-'
1226 sep - list separator (e.g. ',' or '|')
1227 str - string to parse, must be terminated by 0 or sep
1228 ... - pointers to store the parsed values
1230 return value - pointer to char after parsed data, 0 if there was an error.
1234 /* '0'-'3' are ASCII 0x30 to 0x33 */
1235 #define is0123(x) (((x) & 0xfc) == 0x30)
1237 const char* parse_list(const char *fmt
, uint32_t *set_vals
,
1238 const char sep
, const char* str
, ...)
1241 const char* p
= str
, *f
= fmt
;
1252 /* Check for separator, if we're not at the start */
1262 case 's': /* string - return a pointer to it (not a copy) */
1263 s
= va_arg(ap
, const char **);
1266 while (*p
&& *p
!= sep
)
1268 set
= (s
[0][0]!='-') && (s
[0][1]!=sep
) ;
1272 d
= va_arg(ap
, int*);
1275 if (!set_vals
|| *p
!= '-')
1277 while (*p
&& *p
!= sep
)
1284 *d
= (*d
* 10) + (*p
++ - '0');
1290 #ifdef HAVE_LCD_COLOR
1291 case 'c': /* colour (rrggbb - e.g. f3c1a8) */
1292 d
= va_arg(ap
, int*);
1294 if (hex_to_rgb(p
, d
) < 0)
1296 if (!set_vals
|| *p
!= '-')
1298 while (*p
&& *p
!= sep
)
1310 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1311 case 'g': /* greyscale colour (0-3) */
1312 d
= va_arg(ap
, int*);
1319 else if (!set_vals
|| *p
!= '-')
1323 while (*p
&& *p
!= sep
)
1330 default: /* Unknown format type */
1334 if (set_vals
&& set
)
1335 *set_vals
|= (1<<i
);