1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Daniel 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 ****************************************************************************/
31 #include "lcd-remote.h"
34 #include "timefuncs.h"
39 #include "mp3_playback.h"
42 #include "ata_idle_notify.h"
45 #include "powermgmt.h"
46 #include "backlight.h"
51 #include "scrobbler.h"
60 #include "eeprom_settings.h"
61 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
62 #include "recording.h"
64 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
67 #endif /* End HAVE_LCD_BITMAP */
68 #include "gui/gwps-common.h"
75 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
82 /* Format a large-range value for output, using the appropriate unit so that
83 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
84 * units) if possible, and 3 significant digits are shown. If a buffer is
85 * given, the result is snprintf()'d into that buffer, otherwise the result is
87 char *output_dyn_value(char *buf
, int buf_size
, int value
,
88 const unsigned char **units
, bool bin_scale
)
90 int scale
= bin_scale
? 1024 : 1000;
95 while (value
>= scale
)
97 fraction
= value
% scale
;
102 fraction
= fraction
* 1000 / 1024;
104 if (value
>= 100 || !unit_no
)
106 else if (value
>= 10)
107 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
109 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
114 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
115 tbuf
, P2STR(units
[unit_no
]));
117 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
121 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
126 /* Create a filename with a number part in a way that the number is 1
127 * higher than the highest numbered file matching the same pattern.
128 * It is allowed that buffer and path point to the same memory location,
129 * saving a strcpy(). Path must always be given without trailing slash.
130 * "num" can point to an int specifying the number to use or NULL or a value
131 * less than zero to number automatically. The final number used will also
132 * be returned in *num. If *num is >= 0 then *num will be incremented by
134 char *create_numbered_filename(char *buffer
, const char *path
,
135 const char *prefix
, const char *suffix
,
136 int numberlen
IF_CNFN_NUM_(, int *num
))
139 struct dirent
*entry
;
142 int prefixlen
= strlen(prefix
);
146 strncpy(buffer
, path
, MAX_PATH
);
148 pathlen
= strlen(buffer
);
151 if (num
&& *num
>= 0)
153 /* number specified */
159 /* automatic numbering */
162 dir
= opendir(pathlen
? buffer
: "/");
166 while ((entry
= readdir(dir
)))
170 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
171 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
174 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
175 if (curr_num
> max_num
)
184 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
185 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
196 /* Format time into buf.
198 * buf - buffer to format to.
199 * buf_size - size of buffer.
200 * t - time to format, in milliseconds.
202 void format_time(char* buf
, int buf_size
, long t
)
206 snprintf(buf
, buf_size
, "%d:%02d",
207 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
211 snprintf(buf
, buf_size
, "%d:%02d:%02d",
212 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
213 (int) (t
% 60000 / 1000));
218 /* Create a filename with a date+time part.
219 It is allowed that buffer and path point to the same memory location,
220 saving a strcpy(). Path must always be given without trailing slash.
221 unique_time as true makes the function wait until the current time has
223 char *create_datetime_filename(char *buffer
, const char *path
,
224 const char *prefix
, const char *suffix
,
227 struct tm
*tm
= get_time();
228 static struct tm last_tm
;
231 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
237 strncpy(buffer
, path
, MAX_PATH
);
239 pathlen
= strlen(buffer
);
240 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
241 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
242 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
243 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
247 #endif /* CONFIG_RTC */
249 /* Ask the user if they really want to erase the current dynamic playlist
250 * returns true if the playlist should be replaced */
251 bool warn_on_pl_erase(void)
253 if (global_settings
.warnon_erase_dynplaylist
&&
254 !global_settings
.party_mode
&&
255 playlist_modified(NULL
))
257 static const char *lines
[] =
258 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
259 static const struct text_message message
={lines
, 1};
261 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
267 /* Read (up to) a line of text from fd into buffer and return number of bytes
268 * read (which may be larger than the number of bytes stored in buffer). If
269 * an error occurs, -1 is returned (and buffer contains whatever could be
270 * read). A line is terminated by a LF char. Neither LF nor CR chars are
273 int read_line(int fd
, char* buffer
, int buffer_size
)
280 while (count
< buffer_size
)
284 if (1 != read(fd
, &c
, 1))
298 buffer
[MIN(count
, buffer_size
- 1)] = 0;
300 return errno
? -1 : num_read
;
303 /* Performance optimized version of the previous function. */
304 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
305 int (*callback
)(int n
, const char *buf
, void *parameters
))
315 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
319 if ( (p
= strchr(buf
, '\r')) != NULL
)
327 if ( (p
= strchr(p
, '\n')) != NULL
)
333 rc
= callback(count
, buf
, parameters
);
340 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
341 memmove(buf
, next
, pos
);
350 #ifdef HAVE_LCD_BITMAP
353 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
354 #define BMP_NUMCOLORS 3
356 #define BMP_COMPRESSION 0 /* BI_RGB */
358 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
360 #define BMP_NUMCOLORS 0
366 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
369 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
372 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
373 #elif LCD_DEPTH <= 16
375 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
378 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
381 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
382 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
383 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
385 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
386 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
388 static const unsigned char bmpheader
[] =
390 0x42, 0x4d, /* 'BM' */
391 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
392 0x00, 0x00, 0x00, 0x00, /* Reserved */
393 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
395 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
396 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
397 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
398 0x01, 0x00, /* Number of planes (always 1) */
399 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
400 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
401 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
402 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
403 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
404 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
405 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
409 2, 2, 94, 0x00, /* Colour #0 */
410 3, 6, 241, 0x00 /* Colour #1 */
412 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
413 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
416 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
417 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
418 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
419 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
420 #elif LCD_DEPTH == 16
421 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
422 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
423 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
427 static void (*screen_dump_hook
)(int fh
) = NULL
;
429 void screen_dump(void)
432 char filename
[MAX_PATH
];
435 static unsigned char line_block
[8][BMP_LINESIZE
];
437 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
438 static unsigned char line_block
[BMP_LINESIZE
];
439 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
440 static unsigned char line_block
[4][BMP_LINESIZE
];
441 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
442 static unsigned char line_block
[8][BMP_LINESIZE
];
444 #elif LCD_DEPTH == 16
445 static unsigned short line_block
[BMP_LINESIZE
/2];
449 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
451 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
452 IF_CNFN_NUM_(, NULL
));
455 fh
= creat(filename
);
459 if (screen_dump_hook
)
461 screen_dump_hook(fh
);
465 write(fh
, bmpheader
, sizeof(bmpheader
));
467 /* BMP image goes bottom up */
469 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
471 unsigned char *src
= &lcd_framebuffer
[by
][0];
472 unsigned char *dst
= &line_block
[0][0];
474 memset(line_block
, 0, sizeof(line_block
));
475 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
477 unsigned dst_mask
= 0x80;
480 for (ix
= 8; ix
> 0; ix
--)
482 unsigned char *dst_blk
= dst
;
483 unsigned src_byte
= *src
++;
486 for (iy
= 8; iy
> 0; iy
--)
489 *dst_blk
|= dst_mask
;
491 dst_blk
+= BMP_LINESIZE
;
498 write(fh
, line_block
, sizeof(line_block
));
501 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
502 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
504 unsigned char *src
= &lcd_framebuffer
[by
][0];
505 unsigned char *dst
= line_block
;
507 memset(line_block
, 0, sizeof(line_block
));
508 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
510 unsigned src_byte
= *src
++;
512 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
513 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
516 write(fh
, line_block
, sizeof(line_block
));
518 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
519 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
521 unsigned char *src
= &lcd_framebuffer
[by
][0];
522 unsigned char *dst
= &line_block
[3][0];
524 memset(line_block
, 0, sizeof(line_block
));
525 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
527 unsigned char *dst_blk
= dst
++;
528 unsigned src_byte0
= *src
++ << 4;
529 unsigned src_byte1
= *src
++;
532 for (iy
= 4; iy
> 0; iy
--)
534 *dst_blk
= (src_byte0
& 0x30) | (src_byte1
& 0x03);
537 dst_blk
-= BMP_LINESIZE
;
541 write(fh
, line_block
, sizeof(line_block
));
543 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
544 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
546 const fb_data
*src
= &lcd_framebuffer
[by
][0];
547 unsigned char *dst
= &line_block
[7][0];
549 memset(line_block
, 0, sizeof(line_block
));
550 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
552 unsigned char *dst_blk
= dst
++;
553 unsigned src_data0
= *src
++ << 4;
554 unsigned src_data1
= *src
++;
557 for (iy
= 8; iy
> 0; iy
--)
559 *dst_blk
= (src_data0
& 0x10) | (src_data1
& 0x01)
560 | ((src_data0
& 0x1000) | (src_data1
& 0x0100)) >> 7;
563 dst_blk
-= BMP_LINESIZE
;
567 write(fh
, line_block
, sizeof(line_block
));
570 #elif LCD_DEPTH == 16
571 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
573 unsigned short *src
= &lcd_framebuffer
[by
][0];
574 unsigned short *dst
= line_block
;
576 memset(line_block
, 0, sizeof(line_block
));
577 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
579 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
580 /* iPod LCD data is big endian although the CPU is not */
581 *dst
++ = htobe16(*src
++);
583 *dst
++ = htole16(*src
++);
587 write(fh
, line_block
, sizeof(line_block
));
589 #endif /* LCD_DEPTH */
595 void screen_dump_set_hook(void (*hook
)(int fh
))
597 screen_dump_hook
= hook
;
600 #endif /* HAVE_LCD_BITMAP */
602 /* parse a line from a configuration file. the line format is:
606 Any whitespace before setting name or value (after ':') is ignored.
607 A # as first non-whitespace character discards the whole line.
608 Function sets pointers to null-terminated setting name and value.
609 Returns false if no valid config entry was found.
612 bool settings_parseline(char* line
, char** name
, char** value
)
616 while ( isspace(*line
) )
622 ptr
= strchr(line
, ':');
629 while (isspace(*ptr
))
635 static void system_flush(void)
638 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
641 static void system_restore(void)
646 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
651 bookmark_autobookmark();
652 call_ata_idle_notifys(true);
658 scrobbler_poweroff();
660 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
661 if(!charger_inserted())
664 bool batt_safe
= battery_level_safe();
665 int audio_stat
= audio_status();
668 screens
[i
].clear_display();
673 if (!tagcache_prepare_shutdown())
676 gui_syncsplash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
680 if (battery_level() > 10)
681 gui_syncsplash(0, str(LANG_SHUTTINGDOWN
));
684 msg_id
= LANG_WARNING_BATTERY_LOW
;
685 gui_syncsplash(0, "%s %s",
686 str(LANG_WARNING_BATTERY_LOW
),
687 str(LANG_SHUTTINGDOWN
));
692 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
693 gui_syncsplash(0, "%s %s",
694 str(LANG_WARNING_BATTERY_EMPTY
),
695 str(LANG_SHUTTINGDOWN
));
698 if (global_settings
.fade_on_stop
699 && (audio_stat
& AUDIO_STATUS_PLAY
))
704 if (batt_safe
) /* do not save on critical battery */
706 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
707 if (audio_stat
& AUDIO_STATUS_RECORD
)
709 rec_command(RECORDING_CMD_STOP
);
710 /* wait for stop to complete */
711 while (audio_status() & AUDIO_STATUS_RECORD
)
715 bookmark_autobookmark();
717 /* audio_stop_recording == audio_stop for HWCODEC */
720 if (callback
!= NULL
)
723 #if CONFIG_CODEC != SWCODEC
724 /* wait for audio_stop or audio_stop_recording to complete */
725 while (audio_status())
729 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
730 audio_close_recording();
733 if(global_settings
.talk_menu
)
735 bool enqueue
= false;
738 talk_id(msg_id
, enqueue
);
741 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
742 #if CONFIG_CODEC == SWCODEC
748 #ifdef HAVE_EEPROM_SETTINGS
749 if (firmware_settings
.initialized
)
751 firmware_settings
.disk_clean
= true;
752 firmware_settings
.bl_version
= 0;
753 eeprom_settings_store();
768 bool list_stop_handler(void)
772 /* Stop the music if it is playing */
775 if (!global_settings
.party_mode
)
777 if (global_settings
.fade_on_stop
)
779 bookmark_autobookmark();
781 ret
= true; /* bookmarking can make a refresh necessary */
785 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
788 if (charger_inserted())
791 shutdown_screen(); /* won't return if shutdown actually happens */
793 ret
= true; /* screen is dirty, caller needs to refresh */
796 #ifndef HAVE_POWEROFF_WHILE_CHARGING
798 static long last_off
= 0;
800 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
802 if (charger_inserted())
805 ret
= true; /* screen is dirty, caller needs to refresh */
808 last_off
= current_tick
;
811 #endif /* CONFIG_CHARGING */
816 static bool waiting_to_resume_play
= false;
817 static long play_resume_tick
;
819 static void car_adapter_mode_processing(bool inserted
)
821 if (global_settings
.car_adapter_mode
)
826 * Just got plugged in, delay & resume if we were playing
828 if (audio_status() & AUDIO_STATUS_PAUSE
)
830 /* delay resume a bit while the engine is cranking */
831 play_resume_tick
= current_tick
+ HZ
*5;
832 waiting_to_resume_play
= true;
838 * Just got unplugged, pause if playing
840 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
841 !(audio_status() & AUDIO_STATUS_PAUSE
))
843 if (global_settings
.fade_on_stop
)
848 waiting_to_resume_play
= false;
853 static void car_adapter_tick(void)
855 if (waiting_to_resume_play
)
857 if (TIME_AFTER(current_tick
, play_resume_tick
))
859 if (audio_status() & AUDIO_STATUS_PAUSE
)
861 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
863 waiting_to_resume_play
= false;
868 void car_adapter_mode_init(void)
870 tick_add_task(car_adapter_tick
);
874 #ifdef HAVE_HEADPHONE_DETECTION
875 static void unplug_change(bool inserted
)
877 static bool headphone_caused_pause
= false;
879 if (global_settings
.unplug_mode
)
881 int audio_stat
= audio_status();
884 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
885 headphone_caused_pause
&&
886 global_settings
.unplug_mode
> 1 )
889 headphone_caused_pause
= false;
891 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
892 !(audio_stat
& AUDIO_STATUS_PAUSE
))
894 headphone_caused_pause
= true;
897 if (global_settings
.unplug_rw
)
899 if (audio_current_track()->elapsed
>
900 (unsigned long)(global_settings
.unplug_rw
*1000))
901 audio_ff_rewind(audio_current_track()->elapsed
-
902 (global_settings
.unplug_rw
*1000));
912 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
916 case SYS_BATTERY_UPDATE
:
917 if(global_settings
.talk_battery_level
)
919 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
921 TALK_ID(battery_level(), UNIT_PERCENT
),
923 talk_force_enqueue_next();
926 case SYS_USB_CONNECTED
:
927 if (callback
!= NULL
)
930 if (!mmc_touched() ||
931 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
934 scrobbler_flush_cache();
937 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
938 check_bootfile(false); /* gets initial size */
943 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
944 check_bootfile(true);
949 return SYS_USB_CONNECTED
;
951 if (!clean_shutdown(callback
, parameter
))
955 case SYS_CHARGER_CONNECTED
:
956 car_adapter_mode_processing(true);
957 return SYS_CHARGER_CONNECTED
;
959 case SYS_CHARGER_DISCONNECTED
:
960 car_adapter_mode_processing(false);
961 return SYS_CHARGER_DISCONNECTED
;
963 case SYS_CAR_ADAPTER_RESUME
:
965 return SYS_CAR_ADAPTER_RESUME
;
967 #ifdef HAVE_HEADPHONE_DETECTION
968 case SYS_PHONE_PLUGGED
:
970 return SYS_PHONE_PLUGGED
;
972 case SYS_PHONE_UNPLUGGED
:
973 unplug_change(false);
974 return SYS_PHONE_UNPLUGGED
;
980 long default_event_handler(long event
)
982 return default_event_handler_ex(event
, NULL
, NULL
);
985 int show_logo( void )
987 #ifdef HAVE_LCD_BITMAP
991 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
994 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
995 lcd_setfont(FONT_SYSFIXED
);
996 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
997 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
998 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
999 lcd_setfont(FONT_UI
);
1002 char *rockbox
= " ROCKbox!";
1004 lcd_clear_display();
1005 lcd_double_height(true);
1006 lcd_puts(0, 0, rockbox
);
1007 lcd_puts_scroll(0, 1, appsversion
);
1011 #ifdef HAVE_REMOTE_LCD
1012 lcd_remote_clear_display();
1013 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
1014 BMPHEIGHT_remote_rockboxlogo
);
1015 lcd_remote_setfont(FONT_SYSFIXED
);
1016 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
1017 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
1018 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
1019 lcd_remote_setfont(FONT_UI
);
1020 lcd_remote_update();
1026 #if CONFIG_CODEC == SWCODEC
1027 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
1031 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
1032 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1033 && global_settings
.playlist_shuffle
));
1035 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
1036 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
1043 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
1045 memorize/compare details about the BOOTFILE
1046 we don't use dircache because it may not be up to date after
1047 USB disconnect (scanning in the background)
1049 void check_bootfile(bool do_rolo
)
1051 static unsigned short wrtdate
= 0;
1052 static unsigned short wrttime
= 0;
1054 struct dirent
* entry
= NULL
;
1056 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
1057 dir
= opendir(BOOTDIR
);
1059 if(!dir
) return; /* do we want an error splash? */
1061 /* loop all files in BOOTDIR */
1062 while(0 != (entry
= readdir(dir
)))
1064 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
1066 /* found the bootfile */
1067 if(wrtdate
&& do_rolo
)
1069 if((entry
->wrtdate
!= wrtdate
) ||
1070 (entry
->wrttime
!= wrttime
))
1072 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
1073 ID2P(LANG_REBOOT_NOW
) };
1074 static const struct text_message message
={ lines
, 2 };
1075 button_clear_queue(); /* Empty the keyboard buffer */
1076 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1077 rolo_load(BOOTDIR
"/" BOOTFILE
);
1080 wrtdate
= entry
->wrtdate
;
1081 wrttime
= entry
->wrttime
;
1089 /* check range, set volume and save settings */
1092 const int min_vol
= sound_min(SOUND_VOLUME
);
1093 const int max_vol
= sound_max(SOUND_VOLUME
);
1094 if (global_settings
.volume
< min_vol
)
1095 global_settings
.volume
= min_vol
;
1096 if (global_settings
.volume
> max_vol
)
1097 global_settings
.volume
= max_vol
;
1098 sound_set_volume(global_settings
.volume
);
1102 char* strrsplt(char* str
, int c
)
1104 char* s
= strrchr(str
, c
);
1118 /* Test file existence, using dircache of possible */
1119 bool file_exists(const char *file
)
1123 if (!file
|| strlen(file
) <= 0)
1126 #ifdef HAVE_DIRCACHE
1127 if (dircache_is_enabled())
1128 return (dircache_get_entry_ptr(file
) != NULL
);
1131 fd
= open(file
, O_RDONLY
);
1138 bool dir_exists(const char *path
)
1140 DIR* d
= opendir(path
);
1148 * removes the extension of filename (if it doesn't start with a .)
1149 * puts the result in buffer
1151 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
1153 char *dot
= strrchr(filename
, '.');
1156 if (buffer_size
<= 0)
1161 buffer_size
--; /* Make room for end nil */
1163 if (dot
!= 0 && filename
[0] != '.')
1165 len
= dot
- filename
;
1166 len
= MIN(len
, buffer_size
);
1167 strncpy(buffer
, filename
, len
);
1172 strncpy(buffer
, filename
, buffer_size
);
1179 #endif /* !defined(__PCTOOL__) */
1181 #ifdef HAVE_LCD_COLOR
1183 * Helper function to convert a string of 6 hex digits to a native colour
1186 static int hex2dec(int c
)
1188 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1189 (toupper(c
)) - 'A' + 10);
1192 int hex_to_rgb(const char* hex
, int* color
)
1194 int red
, green
, blue
;
1197 while ((i
< 6) && (isxdigit(hex
[i
])))
1203 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1204 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1205 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1207 *color
= LCD_RGBPACK(red
,green
,blue
);
1211 #endif /* HAVE_LCD_COLOR */
1213 #ifdef HAVE_LCD_BITMAP
1214 /* A simplified scanf - used (at time of writing) by wps parsing functions.
1216 fmt - char array specifying the format of each list option. Valid values
1218 s - string (sets pointer to string, without copying)
1219 c - hex colour (RGB888 - e.g. ff00ff)
1220 g - greyscale "colour" (0-3)
1222 sep - list separator (e.g. ',' or '|')
1223 str - string to parse, must be terminated by 0 or sep
1224 ... - pointers to store the parsed values
1226 return value - pointer to char after parsed data, 0 if there was an error.
1230 /* '0'-'3' are ASCII 0x30 to 0x33 */
1231 #define is0123(x) (((x) & 0xfc) == 0x30)
1233 const char* parse_list(const char *fmt
, const char sep
, const char* str
, ...)
1236 const char* p
= str
;
1244 /* Check for separator, if we're not at the start */
1254 case 's': /* string - return a pointer to it (not a copy) */
1255 s
= va_arg(ap
, const char **);
1258 while (*p
&& *p
!= sep
)
1264 d
= va_arg(ap
, int*);
1271 *d
= (*d
* 10) + (*p
++ - '0');
1275 #ifdef HAVE_LCD_COLOR
1276 case 'c': /* colour (rrggbb - e.g. f3c1a8) */
1277 d
= va_arg(ap
, int*);
1279 if (hex_to_rgb(p
, d
) < 0)
1287 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1288 case 'g': /* greyscale colour (0-3) */
1289 d
= va_arg(ap
, int*);
1299 default: /* Unknown format type */