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 ****************************************************************************/
39 #include "lcd-remote.h"
42 #include "timefuncs.h"
47 #include "mp3_playback.h"
50 #include "ata_idle_notify.h"
53 #include "powermgmt.h"
54 #include "backlight.h"
59 #include "scrobbler.h"
64 #ifdef IPOD_ACCESSORY_PROTOCOL
68 #if (CONFIG_STORAGE & STORAGE_MMC)
72 #include "eeprom_settings.h"
73 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
74 #include "recording.h"
76 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
79 #endif /* End HAVE_LCD_BITMAP */
80 #include "gui/gwps-common.h"
86 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
92 /* Format a large-range value for output, using the appropriate unit so that
93 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
94 * units) if possible, and 3 significant digits are shown. If a buffer is
95 * given, the result is snprintf()'d into that buffer, otherwise the result is
97 char *output_dyn_value(char *buf
, int buf_size
, int value
,
98 const unsigned char **units
, bool bin_scale
)
100 int scale
= bin_scale
? 1024 : 1000;
105 while (value
>= scale
)
107 fraction
= value
% scale
;
112 fraction
= fraction
* 1000 / 1024;
114 if (value
>= 100 || !unit_no
)
116 else if (value
>= 10)
117 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
119 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
124 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
125 tbuf
, P2STR(units
[unit_no
]));
127 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
131 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
136 /* Create a filename with a number part in a way that the number is 1
137 * higher than the highest numbered file matching the same pattern.
138 * It is allowed that buffer and path point to the same memory location,
139 * saving a strcpy(). Path must always be given without trailing slash.
140 * "num" can point to an int specifying the number to use or NULL or a value
141 * less than zero to number automatically. The final number used will also
142 * be returned in *num. If *num is >= 0 then *num will be incremented by
144 char *create_numbered_filename(char *buffer
, const char *path
,
145 const char *prefix
, const char *suffix
,
146 int numberlen
IF_CNFN_NUM_(, int *num
))
149 struct dirent
*entry
;
152 int prefixlen
= strlen(prefix
);
156 strncpy(buffer
, path
, MAX_PATH
);
158 pathlen
= strlen(buffer
);
161 if (num
&& *num
>= 0)
163 /* number specified */
169 /* automatic numbering */
172 dir
= opendir(pathlen
? buffer
: "/");
176 while ((entry
= readdir(dir
)))
180 if (strncasecmp((char *)entry
->d_name
, prefix
, prefixlen
)
181 || strcasecmp((char *)entry
->d_name
+ prefixlen
+ numberlen
, suffix
))
184 curr_num
= atoi((char *)entry
->d_name
+ prefixlen
);
185 if (curr_num
> max_num
)
194 snprintf(fmtstring
, sizeof(fmtstring
), "/%%s%%0%dd%%s", numberlen
);
195 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
, fmtstring
, prefix
,
208 /* Create a filename with a date+time part.
209 It is allowed that buffer and path point to the same memory location,
210 saving a strcpy(). Path must always be given without trailing slash.
211 unique_time as true makes the function wait until the current time has
213 char *create_datetime_filename(char *buffer
, const char *path
,
214 const char *prefix
, const char *suffix
,
217 struct tm
*tm
= get_time();
218 static struct tm last_tm
;
221 while (unique_time
&& !memcmp(get_time(), &last_tm
, sizeof (struct tm
)))
227 strncpy(buffer
, path
, MAX_PATH
);
229 pathlen
= strlen(buffer
);
230 snprintf(buffer
+ pathlen
, MAX_PATH
- pathlen
,
231 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix
,
232 tm
->tm_year
% 100, tm
->tm_mon
+ 1, tm
->tm_mday
,
233 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, suffix
);
237 #endif /* CONFIG_RTC */
239 /* Ask the user if they really want to erase the current dynamic playlist
240 * returns true if the playlist should be replaced */
241 bool warn_on_pl_erase(void)
243 if (global_settings
.warnon_erase_dynplaylist
&&
244 !global_settings
.party_mode
&&
245 playlist_modified(NULL
))
247 static const char *lines
[] =
248 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
249 static const struct text_message message
={lines
, 1};
251 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
257 /* Read (up to) a line of text from fd into buffer and return number of bytes
258 * read (which may be larger than the number of bytes stored in buffer). If
259 * an error occurs, -1 is returned (and buffer contains whatever could be
260 * read). A line is terminated by a LF char. Neither LF nor CR chars are
263 int read_line(int fd
, char* buffer
, int buffer_size
)
270 while (count
< buffer_size
)
274 if (1 != read(fd
, &c
, 1))
288 buffer
[MIN(count
, buffer_size
- 1)] = 0;
290 return errno
? -1 : num_read
;
293 /* Performance optimized version of the previous function. */
294 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
295 int (*callback
)(int n
, const char *buf
, void *parameters
))
305 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
309 if ( (p
= strchr(buf
, '\r')) != NULL
)
317 if ( (p
= strchr(p
, '\n')) != NULL
)
323 rc
= callback(count
, buf
, parameters
);
330 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
331 memmove(buf
, next
, pos
);
340 #ifdef HAVE_LCD_BITMAP
343 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
344 #define BMP_NUMCOLORS 3
346 #define BMP_COMPRESSION 0 /* BI_RGB */
348 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
350 #define BMP_NUMCOLORS 0
356 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
359 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
362 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
363 #elif LCD_DEPTH <= 16
365 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
368 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
371 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
372 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
373 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
375 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
376 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
378 static const unsigned char bmpheader
[] =
380 0x42, 0x4d, /* 'BM' */
381 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
382 0x00, 0x00, 0x00, 0x00, /* Reserved */
383 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
385 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
386 LE32_CONST(LCD_WIDTH
), /* Width in pixels */
387 LE32_CONST(LCD_HEIGHT
), /* Height in pixels */
388 0x01, 0x00, /* Number of planes (always 1) */
389 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
390 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
391 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
392 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
393 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
394 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
395 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
399 2, 2, 94, 0x00, /* Colour #0 */
400 3, 6, 241, 0x00 /* Colour #1 */
402 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
403 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
406 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
407 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
408 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
409 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
410 #elif LCD_DEPTH == 16
411 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
412 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
413 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
417 static void (*screen_dump_hook
)(int fh
) = NULL
;
419 void screen_dump(void)
422 char filename
[MAX_PATH
];
425 static unsigned char line_block
[8][BMP_LINESIZE
];
427 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
428 static unsigned char line_block
[BMP_LINESIZE
];
429 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
430 static unsigned char line_block
[4][BMP_LINESIZE
];
431 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
432 static unsigned char line_block
[8][BMP_LINESIZE
];
434 #elif LCD_DEPTH == 16
435 static unsigned short line_block
[BMP_LINESIZE
/2];
439 create_datetime_filename(filename
, "", "dump ", ".bmp", false);
441 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
442 IF_CNFN_NUM_(, NULL
));
445 fh
= creat(filename
);
449 if (screen_dump_hook
)
451 screen_dump_hook(fh
);
455 write(fh
, bmpheader
, sizeof(bmpheader
));
457 /* BMP image goes bottom up */
459 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
461 unsigned char *src
= &lcd_framebuffer
[by
][0];
462 unsigned char *dst
= &line_block
[0][0];
464 memset(line_block
, 0, sizeof(line_block
));
465 for (bx
= LCD_WIDTH
/8; bx
> 0; bx
--)
467 unsigned dst_mask
= 0x80;
470 for (ix
= 8; ix
> 0; ix
--)
472 unsigned char *dst_blk
= dst
;
473 unsigned src_byte
= *src
++;
476 for (iy
= 8; iy
> 0; iy
--)
479 *dst_blk
|= dst_mask
;
481 dst_blk
+= BMP_LINESIZE
;
488 write(fh
, line_block
, sizeof(line_block
));
491 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
492 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
494 unsigned char *src
= &lcd_framebuffer
[by
][0];
495 unsigned char *dst
= line_block
;
497 memset(line_block
, 0, sizeof(line_block
));
498 for (bx
= LCD_FBWIDTH
; bx
> 0; bx
--)
500 unsigned src_byte
= *src
++;
502 *dst
++ = ((src_byte
>> 2) & 0x30) | ((src_byte
>> 4) & 0x03);
503 *dst
++ = ((src_byte
<< 2) & 0x30) | (src_byte
& 0x03);
506 write(fh
, line_block
, sizeof(line_block
));
508 #elif LCD_PIXELFORMAT == VERTICAL_PACKING
509 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
511 unsigned char *src
= &lcd_framebuffer
[by
][0];
512 unsigned char *dst
= &line_block
[3][0];
514 memset(line_block
, 0, sizeof(line_block
));
515 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
517 unsigned char *dst_blk
= dst
++;
518 unsigned src_byte0
= *src
++ << 4;
519 unsigned src_byte1
= *src
++;
522 for (iy
= 4; iy
> 0; iy
--)
524 *dst_blk
= (src_byte0
& 0x30) | (src_byte1
& 0x03);
527 dst_blk
-= BMP_LINESIZE
;
531 write(fh
, line_block
, sizeof(line_block
));
533 #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
534 for (by
= LCD_FBHEIGHT
- 1; by
>= 0; by
--)
536 const fb_data
*src
= &lcd_framebuffer
[by
][0];
537 unsigned char *dst
= &line_block
[7][0];
539 memset(line_block
, 0, sizeof(line_block
));
540 for (bx
= LCD_WIDTH
/2; bx
> 0; bx
--)
542 unsigned char *dst_blk
= dst
++;
543 unsigned src_data0
= *src
++ << 4;
544 unsigned src_data1
= *src
++;
547 for (iy
= 8; iy
> 0; iy
--)
549 *dst_blk
= (src_data0
& 0x10) | (src_data1
& 0x01)
550 | ((src_data0
& 0x1000) | (src_data1
& 0x0100)) >> 7;
553 dst_blk
-= BMP_LINESIZE
;
557 write(fh
, line_block
, sizeof(line_block
));
560 #elif LCD_DEPTH == 16
561 for (by
= LCD_HEIGHT
- 1; by
>= 0; by
--)
563 unsigned short *src
= &lcd_framebuffer
[by
][0];
564 unsigned short *dst
= line_block
;
566 memset(line_block
, 0, sizeof(line_block
));
567 for (bx
= LCD_WIDTH
; bx
> 0; bx
--)
569 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
570 /* iPod LCD data is big endian although the CPU is not */
571 *dst
++ = htobe16(*src
++);
573 *dst
++ = htole16(*src
++);
577 write(fh
, line_block
, sizeof(line_block
));
579 #endif /* LCD_DEPTH */
585 void screen_dump_set_hook(void (*hook
)(int fh
))
587 screen_dump_hook
= hook
;
590 #endif /* HAVE_LCD_BITMAP */
592 /* parse a line from a configuration file. the line format is:
596 Any whitespace before setting name or value (after ':') is ignored.
597 A # as first non-whitespace character discards the whole line.
598 Function sets pointers to null-terminated setting name and value.
599 Returns false if no valid config entry was found.
602 bool settings_parseline(char* line
, char** name
, char** value
)
606 while ( isspace(*line
) )
612 ptr
= strchr(line
, ':');
619 while (isspace(*ptr
))
625 static void system_flush(void)
627 scrobbler_shutdown();
630 call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
633 static void system_restore(void)
639 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
644 bookmark_autobookmark();
645 call_storage_idle_notifys(true);
651 scrobbler_poweroff();
653 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
654 if(!charger_inserted())
657 bool batt_safe
= battery_level_safe();
658 int audio_stat
= audio_status();
661 screens
[i
].clear_display();
666 if (!tagcache_prepare_shutdown())
669 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
673 if (battery_level() > 10)
674 splash(0, str(LANG_SHUTTINGDOWN
));
677 msg_id
= LANG_WARNING_BATTERY_LOW
;
678 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
679 str(LANG_SHUTTINGDOWN
));
684 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
685 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY
),
686 str(LANG_SHUTTINGDOWN
));
689 if (global_settings
.fade_on_stop
690 && (audio_stat
& AUDIO_STATUS_PLAY
))
695 if (batt_safe
) /* do not save on critical battery */
697 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
698 if (audio_stat
& AUDIO_STATUS_RECORD
)
700 rec_command(RECORDING_CMD_STOP
);
701 /* wait for stop to complete */
702 while (audio_status() & AUDIO_STATUS_RECORD
)
706 bookmark_autobookmark();
708 /* audio_stop_recording == audio_stop for HWCODEC */
711 if (callback
!= NULL
)
714 #if CONFIG_CODEC != SWCODEC
715 /* wait for audio_stop or audio_stop_recording to complete */
716 while (audio_status())
720 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
721 audio_close_recording();
724 if(global_settings
.talk_menu
)
726 bool enqueue
= false;
729 talk_id(msg_id
, enqueue
);
732 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
733 #if CONFIG_CODEC == SWCODEC
739 #ifdef HAVE_EEPROM_SETTINGS
740 if (firmware_settings
.initialized
)
742 firmware_settings
.disk_clean
= true;
743 firmware_settings
.bl_version
= 0;
744 eeprom_settings_store();
759 bool list_stop_handler(void)
763 /* Stop the music if it is playing */
766 if (!global_settings
.party_mode
)
768 if (global_settings
.fade_on_stop
)
770 bookmark_autobookmark();
772 ret
= true; /* bookmarking can make a refresh necessary */
776 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
779 if (charger_inserted())
782 shutdown_screen(); /* won't return if shutdown actually happens */
784 ret
= true; /* screen is dirty, caller needs to refresh */
787 #ifndef HAVE_POWEROFF_WHILE_CHARGING
789 static long last_off
= 0;
791 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
793 if (charger_inserted())
796 ret
= true; /* screen is dirty, caller needs to refresh */
799 last_off
= current_tick
;
802 #endif /* CONFIG_CHARGING */
807 static bool waiting_to_resume_play
= false;
808 static long play_resume_tick
;
810 static void car_adapter_mode_processing(bool inserted
)
812 if (global_settings
.car_adapter_mode
)
817 * Just got plugged in, delay & resume if we were playing
819 if (audio_status() & AUDIO_STATUS_PAUSE
)
821 /* delay resume a bit while the engine is cranking */
822 play_resume_tick
= current_tick
+ HZ
*5;
823 waiting_to_resume_play
= true;
829 * Just got unplugged, pause if playing
831 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
832 !(audio_status() & AUDIO_STATUS_PAUSE
))
834 if (global_settings
.fade_on_stop
)
839 waiting_to_resume_play
= false;
844 static void car_adapter_tick(void)
846 if (waiting_to_resume_play
)
848 if (TIME_AFTER(current_tick
, play_resume_tick
))
850 if (audio_status() & AUDIO_STATUS_PAUSE
)
852 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
854 waiting_to_resume_play
= false;
859 void car_adapter_mode_init(void)
861 tick_add_task(car_adapter_tick
);
865 #ifdef HAVE_HEADPHONE_DETECTION
866 static void unplug_change(bool inserted
)
868 static bool headphone_caused_pause
= false;
870 if (global_settings
.unplug_mode
)
872 int audio_stat
= audio_status();
875 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
876 headphone_caused_pause
&&
877 global_settings
.unplug_mode
> 1 )
880 headphone_caused_pause
= false;
882 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
883 !(audio_stat
& AUDIO_STATUS_PAUSE
))
885 headphone_caused_pause
= true;
888 if (global_settings
.unplug_rw
)
890 if (audio_current_track()->elapsed
>
891 (unsigned long)(global_settings
.unplug_rw
*1000))
892 audio_ff_rewind(audio_current_track()->elapsed
-
893 (global_settings
.unplug_rw
*1000));
903 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
907 case SYS_BATTERY_UPDATE
:
908 if(global_settings
.talk_battery_level
)
910 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
912 TALK_ID(battery_level(), UNIT_PERCENT
),
914 talk_force_enqueue_next();
917 case SYS_USB_CONNECTED
:
918 if (callback
!= NULL
)
920 #if (CONFIG_STORAGE & STORAGE_MMC)
921 if (!mmc_touched() ||
922 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
927 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
928 check_bootfile(false); /* gets initial size */
933 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
934 check_bootfile(true);
939 return SYS_USB_CONNECTED
;
941 if (!clean_shutdown(callback
, parameter
))
945 case SYS_CHARGER_CONNECTED
:
946 car_adapter_mode_processing(true);
947 return SYS_CHARGER_CONNECTED
;
949 case SYS_CHARGER_DISCONNECTED
:
950 car_adapter_mode_processing(false);
951 return SYS_CHARGER_DISCONNECTED
;
953 case SYS_CAR_ADAPTER_RESUME
:
955 return SYS_CAR_ADAPTER_RESUME
;
957 #ifdef HAVE_HEADPHONE_DETECTION
958 case SYS_PHONE_PLUGGED
:
960 return SYS_PHONE_PLUGGED
;
962 case SYS_PHONE_UNPLUGGED
:
963 unplug_change(false);
964 return SYS_PHONE_UNPLUGGED
;
966 #ifdef IPOD_ACCESSORY_PROTOCOL
967 case SYS_IAP_PERIODIC
:
969 return SYS_IAP_PERIODIC
;
970 case SYS_IAP_HANDLEPKT
:
972 return SYS_IAP_HANDLEPKT
;
978 long default_event_handler(long event
)
980 return default_event_handler_ex(event
, NULL
, NULL
);
983 int show_logo( void )
985 #ifdef HAVE_LCD_BITMAP
989 snprintf(version
, sizeof(version
), "Ver. %s", appsversion
);
992 #ifdef SANSA_CLIP /* display the logo in the blue area of the screen */
993 lcd_setfont(FONT_SYSFIXED
);
994 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
995 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
996 0, (unsigned char *)version
);
997 lcd_bitmap(rockboxlogo
, 0, 16, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
999 lcd_bitmap(rockboxlogo
, 0, 10, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
1000 lcd_setfont(FONT_SYSFIXED
);
1001 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
1002 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
1003 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
1005 lcd_setfont(FONT_UI
);
1008 char *rockbox
= " ROCKbox!";
1010 lcd_clear_display();
1011 lcd_double_height(true);
1012 lcd_puts(0, 0, rockbox
);
1013 lcd_puts_scroll(0, 1, appsversion
);
1017 #ifdef HAVE_REMOTE_LCD
1018 lcd_remote_clear_display();
1019 lcd_remote_bitmap(remote_rockboxlogo
, 0, 10, BMPWIDTH_remote_rockboxlogo
,
1020 BMPHEIGHT_remote_rockboxlogo
);
1021 lcd_remote_setfont(FONT_SYSFIXED
);
1022 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
1023 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
1024 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
1025 lcd_remote_setfont(FONT_UI
);
1026 lcd_remote_update();
1032 #if CONFIG_CODEC == SWCODEC
1033 int get_replaygain_mode(bool have_track_gain
, bool have_album_gain
)
1037 bool track
= ((global_settings
.replaygain_type
== REPLAYGAIN_TRACK
)
1038 || ((global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1039 && global_settings
.playlist_shuffle
));
1041 type
= (!track
&& have_album_gain
) ? REPLAYGAIN_ALBUM
1042 : have_track_gain
? REPLAYGAIN_TRACK
: -1;
1049 #if !defined(USB_NONE) && !defined(USB_IPODSTYLE)
1051 memorize/compare details about the BOOTFILE
1052 we don't use dircache because it may not be up to date after
1053 USB disconnect (scanning in the background)
1055 void check_bootfile(bool do_rolo
)
1057 static unsigned short wrtdate
= 0;
1058 static unsigned short wrttime
= 0;
1060 struct dirent
* entry
= NULL
;
1062 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
1063 dir
= opendir(BOOTDIR
);
1065 if(!dir
) return; /* do we want an error splash? */
1067 /* loop all files in BOOTDIR */
1068 while(0 != (entry
= readdir(dir
)))
1070 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
1072 /* found the bootfile */
1073 if(wrtdate
&& do_rolo
)
1075 if((entry
->wrtdate
!= wrtdate
) ||
1076 (entry
->wrttime
!= wrttime
))
1078 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
1079 ID2P(LANG_REBOOT_NOW
) };
1080 static const struct text_message message
={ lines
, 2 };
1081 button_clear_queue(); /* Empty the keyboard buffer */
1082 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
1083 rolo_load(BOOTDIR
"/" BOOTFILE
);
1086 wrtdate
= entry
->wrtdate
;
1087 wrttime
= entry
->wrttime
;
1095 /* check range, set volume and save settings */
1098 const int min_vol
= sound_min(SOUND_VOLUME
);
1099 const int max_vol
= sound_max(SOUND_VOLUME
);
1100 if (global_settings
.volume
< min_vol
)
1101 global_settings
.volume
= min_vol
;
1102 if (global_settings
.volume
> max_vol
)
1103 global_settings
.volume
= max_vol
;
1104 sound_set_volume(global_settings
.volume
);
1108 char* strrsplt(char* str
, int c
)
1110 char* s
= strrchr(str
, c
);
1124 /* Test file existence, using dircache of possible */
1125 bool file_exists(const char *file
)
1129 if (!file
|| strlen(file
) <= 0)
1132 #ifdef HAVE_DIRCACHE
1133 if (dircache_is_enabled())
1134 return (dircache_get_entry_ptr(file
) != NULL
);
1137 fd
= open(file
, O_RDONLY
);
1144 bool dir_exists(const char *path
)
1146 DIR* d
= opendir(path
);
1154 * removes the extension of filename (if it doesn't start with a .)
1155 * puts the result in buffer
1157 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
1159 char *dot
= strrchr(filename
, '.');
1162 if (buffer_size
<= 0)
1167 buffer_size
--; /* Make room for end nil */
1169 if (dot
!= 0 && filename
[0] != '.')
1171 len
= dot
- filename
;
1172 len
= MIN(len
, buffer_size
);
1173 strncpy(buffer
, filename
, len
);
1178 strncpy(buffer
, filename
, buffer_size
);
1185 #endif /* !defined(__PCTOOL__) */
1187 /* Format time into buf.
1189 * buf - buffer to format to.
1190 * buf_size - size of buffer.
1191 * t - time to format, in milliseconds.
1193 void format_time(char* buf
, int buf_size
, long t
)
1197 snprintf(buf
, buf_size
, "%d:%02d",
1198 (int) (t
/ 60000), (int) (t
% 60000 / 1000));
1202 snprintf(buf
, buf_size
, "%d:%02d:%02d",
1203 (int) (t
/ 3600000), (int) (t
% 3600000 / 60000),
1204 (int) (t
% 60000 / 1000));
1209 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1210 * If no BOM is present this behaves like open().
1211 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1212 * the opened file and leave the file pointer set after the BOM.
1214 #define BOM "\xef\xbb\xbf"
1217 int open_utf8(const char* pathname
, int flags
)
1220 unsigned char bom
[BOM_SIZE
];
1222 fd
= open(pathname
, flags
);
1226 if(flags
& (O_TRUNC
| O_WRONLY
))
1228 write(fd
, BOM
, BOM_SIZE
);
1232 read(fd
, bom
, BOM_SIZE
);
1234 if(memcmp(bom
, BOM
, BOM_SIZE
))
1235 lseek(fd
, 0, SEEK_SET
);
1241 #ifdef HAVE_LCD_COLOR
1243 * Helper function to convert a string of 6 hex digits to a native colour
1246 static int hex2dec(int c
)
1248 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1249 (toupper(c
)) - 'A' + 10);
1252 int hex_to_rgb(const char* hex
, int* color
)
1254 int red
, green
, blue
;
1257 while ((i
< 6) && (isxdigit(hex
[i
])))
1263 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1264 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1265 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1267 *color
= LCD_RGBPACK(red
,green
,blue
);
1271 #endif /* HAVE_LCD_COLOR */
1273 #ifdef HAVE_LCD_BITMAP
1274 /* A simplified scanf - used (at time of writing) by wps parsing functions.
1276 fmt - char array specifying the format of each list option. Valid values
1278 s - string (sets pointer to string, without copying)
1279 c - hex colour (RGB888 - e.g. ff00ff)
1280 g - greyscale "colour" (0-3)
1281 set_vals - if not NULL 1 is set in the bitplace if the item was read OK
1283 first item is LSB, (max 32 items! )
1284 Stops parseing if an item is invalid unless the item == '-'
1285 sep - list separator (e.g. ',' or '|')
1286 str - string to parse, must be terminated by 0 or sep
1287 ... - pointers to store the parsed values
1289 return value - pointer to char after parsed data, 0 if there was an error.
1293 /* '0'-'3' are ASCII 0x30 to 0x33 */
1294 #define is0123(x) (((x) & 0xfc) == 0x30)
1296 const char* parse_list(const char *fmt
, uint32_t *set_vals
,
1297 const char sep
, const char* str
, ...)
1300 const char* p
= str
, *f
= fmt
;
1311 /* Check for separator, if we're not at the start */
1321 case 's': /* string - return a pointer to it (not a copy) */
1322 s
= va_arg(ap
, const char **);
1325 while (*p
&& *p
!= sep
)
1327 set
= (s
[0][0]!='-') && (s
[0][1]!=sep
) ;
1331 d
= va_arg(ap
, int*);
1334 if (!set_vals
|| *p
!= '-')
1336 while (*p
&& *p
!= sep
)
1343 *d
= (*d
* 10) + (*p
++ - '0');
1349 #ifdef HAVE_LCD_COLOR
1350 case 'c': /* colour (rrggbb - e.g. f3c1a8) */
1351 d
= va_arg(ap
, int*);
1353 if (hex_to_rgb(p
, d
) < 0)
1355 if (!set_vals
|| *p
!= '-')
1357 while (*p
&& *p
!= sep
)
1369 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1370 case 'g': /* greyscale colour (0-3) */
1371 d
= va_arg(ap
, int*);
1378 else if (!set_vals
|| *p
!= '-')
1382 while (*p
&& *p
!= sep
)
1389 default: /* Unknown format type */
1393 if (set_vals
&& set
)
1394 *set_vals
|= (1<<i
);