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 ****************************************************************************/
26 #include "string-extra.h"
33 #include "filefuncs.h"
36 #ifdef HAVE_REMOTE_LCD
37 #include "lcd-remote.h"
40 #include "timefuncs.h"
42 #include "usb_screen.h"
47 #include "ata_idle_notify.h"
50 #include "powermgmt.h"
51 #include "backlight.h"
56 #include "scrobbler.h"
69 #ifdef IPOD_ACCESSORY_PROTOCOL
73 #if (CONFIG_STORAGE & STORAGE_MMC)
77 #include "eeprom_settings.h"
78 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
79 #include "recording.h"
81 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
84 #endif /* End HAVE_LCD_BITMAP */
88 #if CONFIG_CODEC == SWCODEC
89 #include "voice_thread.h"
91 #include "mp3_playback.h"
95 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
96 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
101 #ifdef HAVE_HARDWARE_CLICK
105 /* units used with output_dyn_value */
106 const unsigned char * const byte_units
[] =
114 const unsigned char * const * const kbyte_units
= &byte_units
[1];
116 /* Format a large-range value for output, using the appropriate unit so that
117 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
118 * units) if possible, and 3 significant digits are shown. If a buffer is
119 * given, the result is snprintf()'d into that buffer, otherwise the result is
121 char *output_dyn_value(char *buf
, int buf_size
, int value
,
122 const unsigned char * const *units
, bool bin_scale
)
124 int scale
= bin_scale
? 1024 : 1000;
129 while (value
>= scale
)
131 fraction
= value
% scale
;
136 fraction
= fraction
* 1000 / 1024;
138 if (value
>= 100 || !unit_no
)
140 else if (value
>= 10)
141 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
143 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
148 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
149 tbuf
, P2STR(units
[unit_no
]));
151 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
155 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
160 /* Ask the user if they really want to erase the current dynamic playlist
161 * returns true if the playlist should be replaced */
162 bool warn_on_pl_erase(void)
164 if (global_settings
.warnon_erase_dynplaylist
&&
165 !global_settings
.party_mode
&&
166 playlist_modified(NULL
))
168 static const char *lines
[] =
169 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
170 static const struct text_message message
={lines
, 1};
172 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
179 /* Performance optimized version of the read_line() (see below) function. */
180 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
181 int (*callback
)(int n
, char *buf
, void *parameters
))
191 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
195 if ( (p
= strchr(buf
, '\n')) != NULL
)
201 rc
= callback(count
, buf
, parameters
);
208 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
209 memmove(buf
, next
, pos
);
218 /* parse a line from a configuration file. the line format is:
222 Any whitespace before setting name or value (after ':') is ignored.
223 A # as first non-whitespace character discards the whole line.
224 Function sets pointers to null-terminated setting name and value.
225 Returns false if no valid config entry was found.
228 bool settings_parseline(char* line
, char** name
, char** value
)
232 line
= skip_whitespace(line
);
237 ptr
= strchr(line
, ':');
244 ptr
= skip_whitespace(ptr
);
249 static void system_flush(void)
253 call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
256 static void system_restore(void)
261 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
265 scrobbler_poweroff();
267 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
268 if(!charger_inserted())
271 bool batt_safe
= battery_level_safe();
272 #if CONFIG_CODEC != SWCODEC || defined(HAVE_RECORDING)
273 int audio_stat
= audio_status();
278 screens
[i
].clear_display();
286 if (!tagcache_prepare_shutdown())
289 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
293 level
= battery_level();
294 if (level
> 10 || level
< 0)
295 splash(0, str(LANG_SHUTTINGDOWN
));
298 msg_id
= LANG_WARNING_BATTERY_LOW
;
299 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
300 str(LANG_SHUTTINGDOWN
));
305 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
306 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY
),
307 str(LANG_SHUTTINGDOWN
));
309 #if CONFIG_CODEC != SWCODEC
310 if (global_settings
.fade_on_stop
311 && (audio_stat
& AUDIO_STATUS_PLAY
))
317 if (batt_safe
) /* do not save on critical battery */
319 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
320 if (audio_stat
& AUDIO_STATUS_RECORD
)
322 rec_command(RECORDING_CMD_STOP
);
323 /* wait for stop to complete */
324 while (audio_status() & AUDIO_STATUS_RECORD
)
328 bookmark_autobookmark(false);
330 /* audio_stop_recording == audio_stop for HWCODEC */
333 if (callback
!= NULL
)
336 #if CONFIG_CODEC != SWCODEC
337 /* wait for audio_stop or audio_stop_recording to complete */
338 while (audio_status())
342 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
343 audio_close_recording();
346 if(global_settings
.talk_menu
)
348 bool enqueue
= false;
351 talk_id(msg_id
, enqueue
);
354 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
355 #if CONFIG_CODEC == SWCODEC
361 #ifdef HAVE_EEPROM_SETTINGS
362 if (firmware_settings
.initialized
)
364 firmware_settings
.disk_clean
= true;
365 firmware_settings
.bl_version
= 0;
366 eeprom_settings_store();
380 bool list_stop_handler(void)
388 /* Stop the music if it is playing */
391 if (!global_settings
.party_mode
)
393 #if CONFIG_CODEC != SWCODEC
394 if (global_settings
.fade_on_stop
)
397 bookmark_autobookmark(true);
399 ret
= true; /* bookmarking can make a refresh necessary */
403 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
406 if (charger_inserted())
409 shutdown_screen(); /* won't return if shutdown actually happens */
411 ret
= true; /* screen is dirty, caller needs to refresh */
414 #ifndef HAVE_POWEROFF_WHILE_CHARGING
416 static long last_off
= 0;
418 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
420 if (charger_inserted())
423 ret
= true; /* screen is dirty, caller needs to refresh */
426 last_off
= current_tick
;
429 #endif /* CONFIG_CHARGING */
434 static bool waiting_to_resume_play
= false;
435 static long play_resume_tick
;
437 static void car_adapter_mode_processing(bool inserted
)
439 if (global_settings
.car_adapter_mode
)
444 * Just got plugged in, delay & resume if we were playing
446 if (audio_status() & AUDIO_STATUS_PAUSE
)
448 /* delay resume a bit while the engine is cranking */
449 play_resume_tick
= current_tick
+ HZ
*5;
450 waiting_to_resume_play
= true;
456 * Just got unplugged, pause if playing
458 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
459 !(audio_status() & AUDIO_STATUS_PAUSE
))
461 pause_action(true, true);
463 waiting_to_resume_play
= false;
468 static void car_adapter_tick(void)
470 if (waiting_to_resume_play
)
472 if (TIME_AFTER(current_tick
, play_resume_tick
))
474 if (audio_status() & AUDIO_STATUS_PAUSE
)
476 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
478 waiting_to_resume_play
= false;
483 void car_adapter_mode_init(void)
485 tick_add_task(car_adapter_tick
);
489 #ifdef HAVE_HEADPHONE_DETECTION
490 static void unplug_change(bool inserted
)
492 static bool headphone_caused_pause
= false;
494 if (global_settings
.unplug_mode
)
496 int audio_stat
= audio_status();
500 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
501 headphone_caused_pause
&&
502 global_settings
.unplug_mode
> 1 )
503 unpause_action(true, true);
504 headphone_caused_pause
= false;
506 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
507 !(audio_stat
& AUDIO_STATUS_PAUSE
))
509 headphone_caused_pause
= true;
510 pause_action(false, false);
517 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
519 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
520 static bool resume
= false;
525 case SYS_BATTERY_UPDATE
:
526 if(global_settings
.talk_battery_level
)
528 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
530 TALK_ID(battery_level(), UNIT_PERCENT
),
532 talk_force_enqueue_next();
535 case SYS_USB_CONNECTED
:
536 if (callback
!= NULL
)
538 #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
539 if (!mmc_touched() ||
540 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
545 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
546 check_bootfile(false); /* gets initial size */
549 gui_usb_screen_run(false);
551 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
552 check_bootfile(true);
557 return SYS_USB_CONNECTED
;
560 if (!clean_shutdown(callback
, parameter
))
564 case SYS_CHARGER_CONNECTED
:
565 car_adapter_mode_processing(true);
566 return SYS_CHARGER_CONNECTED
;
568 case SYS_CHARGER_DISCONNECTED
:
569 car_adapter_mode_processing(false);
570 /*reset rockbox battery runtime*/
571 global_status
.runtime
= 0;
572 return SYS_CHARGER_DISCONNECTED
;
574 case SYS_CAR_ADAPTER_RESUME
:
575 unpause_action(true, true);
576 return SYS_CAR_ADAPTER_RESUME
;
578 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
581 /* simple sanity: assume rockbox is on the first hotswappable
582 * driver, abort out if that one isn't inserted */
584 for (i
= 0; i
< NUM_DRIVES
; i
++)
586 if (storage_removable(i
) && !storage_present(i
))
587 return SYS_FS_CHANGED
;
590 check_bootfile(true); /* state gotten in main.c:init() */
593 return SYS_FS_CHANGED
;
595 #ifdef HAVE_HEADPHONE_DETECTION
596 case SYS_PHONE_PLUGGED
:
598 return SYS_PHONE_PLUGGED
;
600 case SYS_PHONE_UNPLUGGED
:
601 unplug_change(false);
602 return SYS_PHONE_UNPLUGGED
;
604 #ifdef IPOD_ACCESSORY_PROTOCOL
605 case SYS_IAP_PERIODIC
:
607 return SYS_IAP_PERIODIC
;
608 case SYS_IAP_HANDLEPKT
:
610 return SYS_IAP_HANDLEPKT
;
612 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
613 /* stop playback if we receive a call */
614 case SYS_CALL_INCOMING
:
615 resume
= audio_status() == AUDIO_STATUS_PLAY
;
617 return SYS_CALL_INCOMING
;
618 /* resume playback if needed */
619 case SYS_CALL_HUNG_UP
:
620 if (resume
&& playlist_resume() != -1)
622 playlist_start(global_status
.resume_index
,
623 global_status
.resume_offset
);
626 return SYS_CALL_HUNG_UP
;
628 #if (CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(PLATFORM_HAS_VOLUME_CHANGE)
629 case SYS_VOLUME_CHANGED
:
631 static bool firstvolume
= true;
632 /* kludge: since this events go to the button_queue,
633 * event data is available in the last button data */
634 int volume
= button_get_data();
635 DEBUGF("SYS_VOLUME_CHANGED: %d\n", volume
);
636 if (global_settings
.volume
!= volume
) {
637 global_settings
.volume
= volume
;
646 #ifdef HAVE_MULTIMEDIA_KEYS
647 /* multimedia keys on keyboards, headsets */
648 case BUTTON_MULTIMEDIA_PLAYPAUSE
:
650 int status
= audio_status();
651 if (status
& AUDIO_STATUS_PLAY
)
653 if (status
& AUDIO_STATUS_PAUSE
)
654 unpause_action(true, true);
656 pause_action(true, true);
659 if (playlist_resume() != -1)
661 playlist_start(global_status
.resume_index
,
662 global_status
.resume_offset
);
666 case BUTTON_MULTIMEDIA_NEXT
:
669 case BUTTON_MULTIMEDIA_PREV
:
672 case BUTTON_MULTIMEDIA_STOP
:
675 case BUTTON_MULTIMEDIA_REW
:
676 case BUTTON_MULTIMEDIA_FFWD
:
677 /* not supported yet, needs to be done in the WPS */
684 long default_event_handler(long event
)
686 return default_event_handler_ex(event
, NULL
, NULL
);
689 int show_logo( void )
691 #ifdef HAVE_LCD_BITMAP
695 snprintf(version
, sizeof(version
), "Ver. %s", rbversion
);
698 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2) || defined(SANSA_CLIPPLUS)
699 /* display the logo in the blue area of the screen */
700 lcd_setfont(FONT_SYSFIXED
);
701 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
702 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
703 0, (unsigned char *)version
);
704 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 16);
706 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 10);
707 lcd_setfont(FONT_SYSFIXED
);
708 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
709 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
710 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
712 lcd_setfont(FONT_UI
);
715 char *rockbox
= " ROCKbox!";
718 lcd_double_height(true);
719 lcd_puts(0, 0, rockbox
);
720 lcd_puts_scroll(0, 1, rbversion
);
724 #ifdef HAVE_REMOTE_LCD
725 lcd_remote_clear_display();
726 lcd_remote_bmp(&bm_remote_rockboxlogo
, 0, 10);
727 lcd_remote_setfont(FONT_SYSFIXED
);
728 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
729 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
730 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
731 lcd_remote_setfont(FONT_UI
);
739 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
741 memorize/compare details about the BOOTFILE
742 we don't use dircache because it may not be up to date after
743 USB disconnect (scanning in the background)
745 void check_bootfile(bool do_rolo
)
747 static unsigned short wrtdate
= 0;
748 static unsigned short wrttime
= 0;
750 struct dirent
* entry
= NULL
;
752 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
753 dir
= opendir(BOOTDIR
);
755 if(!dir
) return; /* do we want an error splash? */
757 /* loop all files in BOOTDIR */
758 while(0 != (entry
= readdir(dir
)))
760 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
762 struct dirinfo info
= dir_get_info(dir
, entry
);
763 /* found the bootfile */
764 if(wrtdate
&& do_rolo
)
766 if((info
.wrtdate
!= wrtdate
) ||
767 (info
.wrttime
!= wrttime
))
769 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
770 ID2P(LANG_REBOOT_NOW
) };
771 static const struct text_message message
={ lines
, 2 };
772 button_clear_queue(); /* Empty the keyboard buffer */
773 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
776 rolo_load(BOOTDIR
"/" BOOTFILE
);
780 wrtdate
= info
.wrtdate
;
781 wrttime
= info
.wrttime
;
789 /* check range, set volume and save settings */
792 const int min_vol
= sound_min(SOUND_VOLUME
);
793 const int max_vol
= sound_max(SOUND_VOLUME
);
794 if (global_settings
.volume
< min_vol
)
795 global_settings
.volume
= min_vol
;
796 if (global_settings
.volume
> max_vol
)
797 global_settings
.volume
= max_vol
;
798 sound_set_volume(global_settings
.volume
);
799 global_status
.last_volume_change
= current_tick
;
803 char* strrsplt(char* str
, int c
)
805 char* s
= strrchr(str
, c
);
820 * removes the extension of filename (if it doesn't start with a .)
821 * puts the result in buffer
823 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
825 char *dot
= strrchr(filename
, '.');
828 if (buffer_size
<= 0)
833 buffer_size
--; /* Make room for end nil */
835 if (dot
!= 0 && filename
[0] != '.')
837 len
= dot
- filename
;
838 len
= MIN(len
, buffer_size
);
845 strlcpy(buffer
, filename
, len
+ 1);
850 #if CONFIG_CODEC == SWCODEC
851 /* Play a standard sound */
852 void system_sound_play(enum system_sound sound
)
854 static const struct beep_params
857 unsigned short frequency
;
858 unsigned short duration
;
859 unsigned short amplitude
;
863 { &global_settings
.keyclick
,
864 4000, KEYCLICK_DURATION
, 2500 },
866 { &global_settings
.beep
,
868 [SOUND_TRACK_NO_MORE
] =
869 { &global_settings
.beep
,
873 const struct beep_params
*params
= &beep_params
[sound
];
875 if (*params
->setting
)
877 beep_play(params
->frequency
, params
->duration
,
878 params
->amplitude
* *params
->setting
);
882 static keyclick_callback keyclick_current_callback
= NULL
;
883 static void* keyclick_data
= NULL
;
884 void keyclick_set_callback(keyclick_callback cb
, void* data
)
886 keyclick_current_callback
= cb
;
887 keyclick_data
= data
;
890 /* Produce keyclick based upon button and global settings */
891 void keyclick_click(bool rawbutton
, int action
)
894 static long last_button
= BUTTON_NONE
;
895 bool do_beep
= false;
898 get_action_statuscode(&button
);
900 /* Settings filters */
902 #ifdef HAVE_HARDWARE_CLICK
903 (global_settings
.keyclick
|| global_settings
.keyclick_hardware
)
905 global_settings
.keyclick
909 if (global_settings
.keyclick_repeats
|| !(button
& BUTTON_REPEAT
))
912 if (button
!= BUTTON_NONE
&& !(button
& BUTTON_REL
)
913 && !(button
& (SYS_EVENT
|BUTTON_MULTIMEDIA
)) )
918 else if ((button
& BUTTON_REPEAT
) && (last_button
== BUTTON_NONE
))
922 #ifdef HAVE_SCROLLWHEEL
923 else if (button
& (BUTTON_SCROLL_BACK
| BUTTON_SCROLL_FWD
))
929 if (button
&BUTTON_REPEAT
)
930 last_button
= button
;
932 last_button
= BUTTON_NONE
;
934 if (do_beep
&& keyclick_current_callback
)
935 do_beep
= keyclick_current_callback(action
, keyclick_data
);
936 keyclick_current_callback
= NULL
;
940 #ifdef HAVE_HARDWARE_CLICK
941 if (global_settings
.keyclick
)
943 system_sound_play(SOUND_KEYCLICK
);
945 if (global_settings
.keyclick_hardware
)
947 #if !defined(SIMULATOR)
948 piezo_button_beep(false, false);
952 system_sound_play(SOUND_KEYCLICK
);
956 #endif /* CONFIG_CODEC == SWCODEC */
958 #endif /* !defined(__PCTOOL__) */
960 /* Read (up to) a line of text from fd into buffer and return number of bytes
961 * read (which may be larger than the number of bytes stored in buffer). If
962 * an error occurs, -1 is returned (and buffer contains whatever could be
963 * read). A line is terminated by a LF char. Neither LF nor CR chars are
966 int read_line(int fd
, char* buffer
, int buffer_size
)
973 while (count
< buffer_size
)
977 if (1 != read(fd
, &c
, 1))
991 buffer
[MIN(count
, buffer_size
- 1)] = 0;
993 return errno
? -1 : num_read
;
997 char* skip_whitespace(char* const str
)
1007 /* Format time into buf.
1009 * buf - buffer to format to.
1010 * buf_size - size of buffer.
1011 * t - time to format, in milliseconds.
1013 void format_time(char* buf
, int buf_size
, long t
)
1015 int const time
= abs(t
/ 1000);
1016 int const hours
= time
/ 3600;
1017 int const minutes
= time
/ 60 - hours
* 60;
1018 int const seconds
= time
% 60;
1019 const char * const sign
= &"-"[t
< 0 ? 0 : 1];
1023 snprintf(buf
, buf_size
, "%s%d:%02d", sign
, minutes
, seconds
);
1027 snprintf(buf
, buf_size
, "%s%d:%02d:%02d", sign
, hours
, minutes
,
1033 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1034 * If no BOM is present this behaves like open().
1035 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1036 * the opened file and leave the file pointer set after the BOM.
1039 int open_utf8(const char* pathname
, int flags
)
1042 unsigned char bom
[BOM_UTF_8_SIZE
];
1044 fd
= open(pathname
, flags
, 0666);
1048 if(flags
& (O_TRUNC
| O_WRONLY
))
1050 write(fd
, BOM_UTF_8
, BOM_UTF_8_SIZE
);
1054 read(fd
, bom
, BOM_UTF_8_SIZE
);
1056 if(memcmp(bom
, BOM_UTF_8
, BOM_UTF_8_SIZE
))
1057 lseek(fd
, 0, SEEK_SET
);
1063 #ifdef HAVE_LCD_COLOR
1065 * Helper function to convert a string of 6 hex digits to a native colour
1068 static int hex2dec(int c
)
1070 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1071 (toupper(c
)) - 'A' + 10);
1074 int hex_to_rgb(const char* hex
, int* color
)
1076 int red
, green
, blue
;
1079 while ((i
< 6) && (isxdigit(hex
[i
])))
1085 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1086 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1087 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1089 *color
= LCD_RGBPACK(red
,green
,blue
);
1093 #endif /* HAVE_LCD_COLOR */
1095 #ifdef HAVE_LCD_BITMAP
1096 /* '0'-'3' are ASCII 0x30 to 0x33 */
1097 #define is0123(x) (((x) & 0xfc) == 0x30)
1098 #if !defined(__PCTOOL__) || defined(CHECKWPS)
1099 bool parse_color(enum screen_type screen
, char *text
, int *value
)
1101 (void)text
; (void)value
; /* silence warnings on mono bitmap */
1104 #ifdef HAVE_LCD_COLOR
1105 if (screens
[screen
].depth
> 2)
1107 if (hex_to_rgb(text
, value
) < 0)
1114 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1115 if (screens
[screen
].depth
== 2)
1117 if (text
[1] != '\0' || !is0123(*text
))
1119 *value
= *text
- '0';
1125 #endif /* !defined(__PCTOOL__) || defined(CHECKWPS) */
1127 /* only used in USB HID and set_time screen */
1128 #if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
1129 int clamp_value_wrap(int value
, int max
, int min
)
1139 #define MAX_ACTIVITY_DEPTH 12
1140 static enum current_activity
1141 current_activity
[MAX_ACTIVITY_DEPTH
] = {ACTIVITY_UNKNOWN
};
1142 static int current_activity_top
= 0;
1143 void push_current_activity(enum current_activity screen
)
1145 current_activity
[current_activity_top
++] = screen
;
1146 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1148 skinlist_set_cfg(i
, NULL
);
1151 void pop_current_activity(void)
1153 current_activity_top
--;
1154 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1156 skinlist_set_cfg(i
, NULL
);
1159 enum current_activity
get_current_activity(void)
1161 return current_activity
[current_activity_top
?current_activity_top
-1:0];