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 ****************************************************************************/
34 #include "lcd-remote.h"
37 #include "timefuncs.h"
42 #include "mp3_playback.h"
45 #include "ata_idle_notify.h"
48 #include "powermgmt.h"
49 #include "backlight.h"
54 #include "scrobbler.h"
63 #include "eeprom_settings.h"
64 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
65 #include "recording.h"
67 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
70 #endif /* End HAVE_LCD_BITMAP */
71 #include "gui/gwps-common.h"
78 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
84 /* Format a large-range value for output, using the appropriate unit so that
85 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
86 * units) if possible, and 3 significant digits are shown. If a buffer is
87 * given, the result is snprintf()'d into that buffer, otherwise the result is
89 char *output_dyn_value(char *buf
, int buf_size
, int value
,
90 const unsigned char **units
, bool bin_scale
)
92 int scale
= bin_scale
? 1024 : 1000;
97 while (value
>= scale
)
99 fraction
= value
% scale
;
104 fraction
= fraction
* 1000 / 1024;
106 if (value
>= 100 || !unit_no
)
108 else if (value
>= 10)
109 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
111 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
116 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
117 tbuf
, P2STR(units
[unit_no
]));
119 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
123 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
128 /* Create a filename with a number part in a way that the number is 1
129 * higher than the highest numbered file matching the same pattern.
130 * It is allowed that buffer and path point to the same memory location,
131 * saving a strcpy(). Path must always be given without trailing slash.
132 * "num" can point to an int specifying the number to use or NULL or a value
133 * less than zero to number automatically. The final number used will also
134 * be returned in *num. If *num is >= 0 then *num will be incremented by
136 char *create_numbered_filename(char *buffer
, const char *path
,
137 const char *prefix
, const char *suffix
,
138 int numberlen
IF_CNFN_NUM_(, int *num
))
141 struct dirent
*entry
;
144 int prefixlen
= strlen(prefix
);
148 strncpy(buffer
, path
, MAX_PATH
);
150 pathlen
= strlen(buffer
);
153 if (num
&& *num
>= 0)
155 /* number specified */
161 /* automatic numbering */
164 dir
= opendir(pathlen
? buffer
: "/");
168 while ((entry
= readdir(dir
)))
172 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
173 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
176 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
177 if (curr_num
> max_num
)
186 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
187 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
198 /* Format time into buf.
200 * buf - buffer to format to.
201 * buf_size - size of buffer.
202 * t - time to format, in milliseconds.
204 void format_time(char* buf
, int buf_size
, long t
)
208 snprintf(buf
, buf_size
, "%d:%02d",
209 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
213 snprintf(buf
, buf_size
, "%d:%02d:%02d",
214 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
215 (int) (t
% 60000 / 1000));
220 /* Create a filename with a date+time part.
221 It is allowed that buffer and path point to the same memory location,
222 saving a strcpy(). Path must always be given without trailing slash.
223 unique_time as true makes the function wait until the current time has
225 char *create_datetime_filename(char *buffer
, const char *path
,
226 const char *prefix
, const char *suffix
,
229 struct tm
*tm
= get_time();
230 static struct tm last_tm
;
233 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
239 strncpy(buffer
, path
, MAX_PATH
);
241 pathlen
= strlen(buffer
);
242 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
243 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
244 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
245 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
249 #endif /* CONFIG_RTC */
251 /* Ask the user if they really want to erase the current dynamic playlist
252 * returns true if the playlist should be replaced */
253 bool warn_on_pl_erase(void)
255 if (global_settings
.warnon_erase_dynplaylist
&&
256 !global_settings
.party_mode
&&
257 playlist_modified(NULL
))
259 static const char *lines
[] =
260 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
261 static const struct text_message message
={lines
, 1};
263 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
269 /* Read (up to) a line of text from fd into buffer and return number of bytes
270 * read (which may be larger than the number of bytes stored in buffer). If
271 * an error occurs, -1 is returned (and buffer contains whatever could be
272 * read). A line is terminated by a LF char. Neither LF nor CR chars are
275 int read_line(int fd
, char* buffer
, int buffer_size
)
282 while (count
< buffer_size
)
286 if (1 != read(fd
, &c
, 1))
300 buffer
[MIN(count
, buffer_size
- 1)] = 0;
302 return errno
? -1 : num_read
;
305 /* Performance optimized version of the previous function. */
306 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
307 int (*callback
)(int n
, const char *buf
, void *parameters
))
317 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
321 if ( (p
= strchr(buf
, '\r')) != NULL
)
329 if ( (p
= strchr(p
, '\n')) != NULL
)
335 rc
= callback(count
, buf
, parameters
);
342 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
343 memmove(buf
, next
, pos
);
352 #ifdef HAVE_LCD_BITMAP
355 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
356 #define BMP_NUMCOLORS 3
358 #define BMP_COMPRESSION 0 /* BI_RGB */
360 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
362 #define BMP_NUMCOLORS 0
368 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
371 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
374 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
375 #elif LCD_DEPTH <= 16
377 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
380 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
383 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
384 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
385 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
387 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
388 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
390 static const unsigned char bmpheader
[] =
392 0x42, 0x4d, /* 'BM' */
393 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
394 0x00, 0x00, 0x00, 0x00, /* Reserved */
395 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
397 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
398 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
399 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
400 0x01, 0x00, /* Number of planes (always 1) */
401 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
402 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
403 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
404 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
405 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
406 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
407 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
411 2, 2, 94, 0x00, /* Colour #0 */
412 3, 6, 241, 0x00 /* Colour #1 */
414 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
415 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
418 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
419 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
420 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
421 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
422 #elif LCD_DEPTH == 16
423 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
424 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
425 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
429 static void (*screen_dump_hook
)(int fh
) = NULL
;
431 void screen_dump(void)
434 char filename
[MAX_PATH
];
437 static unsigned char line_block
[8][BMP_LINESIZE
];
439 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
440 static unsigned char line_block
[BMP_LINESIZE
];
441 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
442 static unsigned char line_block
[4][BMP_LINESIZE
];
443 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
444 static unsigned char line_block
[8][BMP_LINESIZE
];
446 #elif LCD_DEPTH == 16
447 static unsigned short line_block
[BMP_LINESIZE
/2];
451 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
453 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
454 IF_CNFN_NUM_(, NULL
));
457 fh
= creat(filename
);
461 if (screen_dump_hook
)
463 screen_dump_hook(fh
);
467 write(fh
, bmpheader
, sizeof(bmpheader
));
469 /* BMP image goes bottom up */
471 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
473 unsigned char *src
= &lcd_framebuffer
[by
][0];
474 unsigned char *dst
= &line_block
[0][0];
476 memset(line_block
, 0, sizeof(line_block
));
477 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
479 unsigned dst_mask
= 0x80;
482 for (ix
= 8; ix
> 0; ix
--)
484 unsigned char *dst_blk
= dst
;
485 unsigned src_byte
= *src
++;
488 for (iy
= 8; iy
> 0; iy
--)
491 *dst_blk
|= dst_mask
;
493 dst_blk
+= BMP_LINESIZE
;
500 write(fh
, line_block
, sizeof(line_block
));
503 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
504 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
506 unsigned char *src
= &lcd_framebuffer
[by
][0];
507 unsigned char *dst
= line_block
;
509 memset(line_block
, 0, sizeof(line_block
));
510 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
512 unsigned src_byte
= *src
++;
514 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
515 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
518 write(fh
, line_block
, sizeof(line_block
));
520 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
521 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
523 unsigned char *src
= &lcd_framebuffer
[by
][0];
524 unsigned char *dst
= &line_block
[3][0];
526 memset(line_block
, 0, sizeof(line_block
));
527 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
529 unsigned char *dst_blk
= dst
++;
530 unsigned src_byte0
= *src
++ << 4;
531 unsigned src_byte1
= *src
++;
534 for (iy
= 4; iy
> 0; iy
--)
536 *dst_blk
= (src_byte0
& 0x30) | (src_byte1
& 0x03);
539 dst_blk
-= BMP_LINESIZE
;
543 write(fh
, line_block
, sizeof(line_block
));
545 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
546 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
548 const fb_data
*src
= &lcd_framebuffer
[by
][0];
549 unsigned char *dst
= &line_block
[7][0];
551 memset(line_block
, 0, sizeof(line_block
));
552 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
554 unsigned char *dst_blk
= dst
++;
555 unsigned src_data0
= *src
++ << 4;
556 unsigned src_data1
= *src
++;
559 for (iy
= 8; iy
> 0; iy
--)
561 *dst_blk
= (src_data0
& 0x10) | (src_data1
& 0x01)
562 | ((src_data0
& 0x1000) | (src_data1
& 0x0100)) >> 7;
565 dst_blk
-= BMP_LINESIZE
;
569 write(fh
, line_block
, sizeof(line_block
));
572 #elif LCD_DEPTH == 16
573 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
575 unsigned short *src
= &lcd_framebuffer
[by
][0];
576 unsigned short *dst
= line_block
;
578 memset(line_block
, 0, sizeof(line_block
));
579 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
581 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
582 /* iPod LCD data is big endian although the CPU is not */
583 *dst
++ = htobe16(*src
++);
585 *dst
++ = htole16(*src
++);
589 write(fh
, line_block
, sizeof(line_block
));
591 #endif /* LCD_DEPTH */
597 void screen_dump_set_hook(void (*hook
)(int fh
))
599 screen_dump_hook
= hook
;
602 #endif /* HAVE_LCD_BITMAP */
604 /* parse a line from a configuration file. the line format is:
608 Any whitespace before setting name or value (after ':') is ignored.
609 A # as first non-whitespace character discards the whole line.
610 Function sets pointers to null-terminated setting name and value.
611 Returns false if no valid config entry was found.
614 bool settings_parseline(char* line
, char** name
, char** value
)
618 while ( isspace(*line
) )
624 ptr
= strchr(line
, ':');
631 while (isspace(*ptr
))
637 static void system_flush(void)
640 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
643 static void system_restore(void)
648 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
653 bookmark_autobookmark();
654 call_ata_idle_notifys(true);
660 scrobbler_poweroff();
662 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
663 if(!charger_inserted())
666 bool batt_safe
= battery_level_safe();
667 int audio_stat
= audio_status();
670 screens
[i
].clear_display();
675 if (!tagcache_prepare_shutdown())
678 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
682 if (battery_level() > 10)
683 splash(0, str(LANG_SHUTTINGDOWN
));
686 msg_id
= LANG_WARNING_BATTERY_LOW
;
687 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
688 str(LANG_SHUTTINGDOWN
));
693 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
694 splashf(0, "%s %s", 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 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1182 * If no BOM is present this behaves like open().
1183 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1184 * the opened file and leave the file pointer set after the BOM.
1186 int open_utf8(const char* pathname
, int flags
)
1189 unsigned char bom
[BOM_SIZE
];
1191 fd
= open(pathname
, flags
);
1195 if(flags
& (O_TRUNC
| O_WRONLY
))
1197 write(fd
, BOM
, BOM_SIZE
);
1201 read(fd
, bom
, BOM_SIZE
);
1203 if(memcmp(bom
, BOM
, BOM_SIZE
))
1204 lseek(fd
, 0, SEEK_SET
);
1210 #ifdef HAVE_LCD_COLOR
1212 * Helper function to convert a string of 6 hex digits to a native colour
1215 static int hex2dec(int c
)
1217 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1218 (toupper(c
)) - 'A' + 10);
1221 int hex_to_rgb(const char* hex
, int* color
)
1223 int red
, green
, blue
;
1226 while ((i
< 6) && (isxdigit(hex
[i
])))
1232 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1233 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1234 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1236 *color
= LCD_RGBPACK(red
,green
,blue
);
1240 #endif /* HAVE_LCD_COLOR */
1242 #ifdef HAVE_LCD_BITMAP
1243 /* A simplified scanf - used (at time of writing) by wps parsing functions.
1245 fmt - char array specifying the format of each list option. Valid values
1247 s - string (sets pointer to string, without copying)
1248 c - hex colour (RGB888 - e.g. ff00ff)
1249 g - greyscale "colour" (0-3)
1250 set_vals - if not NULL 1 is set in the bitplace if the item was read OK
1252 first item is LSB, (max 32 items! )
1253 Stops parseing if an item is invalid unless the item == '-'
1254 sep - list separator (e.g. ',' or '|')
1255 str - string to parse, must be terminated by 0 or sep
1256 ... - pointers to store the parsed values
1258 return value - pointer to char after parsed data, 0 if there was an error.
1262 /* '0'-'3' are ASCII 0x30 to 0x33 */
1263 #define is0123(x) (((x) & 0xfc) == 0x30)
1265 const char* parse_list(const char *fmt
, uint32_t *set_vals
,
1266 const char sep
, const char* str
, ...)
1269 const char* p
= str
, *f
= fmt
;
1280 /* Check for separator, if we're not at the start */
1290 case 's': /* string - return a pointer to it (not a copy) */
1291 s
= va_arg(ap
, const char **);
1294 while (*p
&& *p
!= sep
)
1296 set
= (s
[0][0]!='-') && (s
[0][1]!=sep
) ;
1300 d
= va_arg(ap
, int*);
1303 if (!set_vals
|| *p
!= '-')
1305 while (*p
&& *p
!= sep
)
1312 *d
= (*d
* 10) + (*p
++ - '0');
1318 #ifdef HAVE_LCD_COLOR
1319 case 'c': /* colour (rrggbb - e.g. f3c1a8) */
1320 d
= va_arg(ap
, int*);
1322 if (hex_to_rgb(p
, d
) < 0)
1324 if (!set_vals
|| *p
!= '-')
1326 while (*p
&& *p
!= sep
)
1338 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1339 case 'g': /* greyscale colour (0-3) */
1340 d
= va_arg(ap
, int*);
1347 else if (!set_vals
|| *p
!= '-')
1351 while (*p
&& *p
!= sep
)
1358 default: /* Unknown format type */
1362 if (set_vals
&& set
)
1363 *set_vals
|= (1<<i
);