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"
32 #include "filefuncs.h"
36 #include "lcd-remote.h"
37 #include "timefuncs.h"
39 #include "usb_screen.h"
42 #include "mp3_playback.h"
45 #include "ata_idle_notify.h"
48 #include "powermgmt.h"
49 #include "backlight.h"
54 #include "scrobbler.h"
67 #ifdef IPOD_ACCESSORY_PROTOCOL
71 #if (CONFIG_STORAGE & STORAGE_MMC)
75 #include "eeprom_settings.h"
76 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
77 #include "recording.h"
79 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
82 #endif /* End HAVE_LCD_BITMAP */
86 #if CONFIG_CODEC == SWCODEC
87 #include "voice_thread.h"
91 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
92 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
97 #ifdef HAVE_HARDWARE_CLICK
101 /* units used with output_dyn_value */
102 const unsigned char * const byte_units
[] =
110 const unsigned char * const * const kbyte_units
= &byte_units
[1];
112 /* Format a large-range value for output, using the appropriate unit so that
113 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
114 * units) if possible, and 3 significant digits are shown. If a buffer is
115 * given, the result is snprintf()'d into that buffer, otherwise the result is
117 char *output_dyn_value(char *buf
, int buf_size
, int value
,
118 const unsigned char * const *units
, bool bin_scale
)
120 int scale
= bin_scale
? 1024 : 1000;
125 while (value
>= scale
)
127 fraction
= value
% scale
;
132 fraction
= fraction
* 1000 / 1024;
134 if (value
>= 100 || !unit_no
)
136 else if (value
>= 10)
137 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
139 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
144 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
145 tbuf
, P2STR(units
[unit_no
]));
147 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
151 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
156 /* Ask the user if they really want to erase the current dynamic playlist
157 * returns true if the playlist should be replaced */
158 bool warn_on_pl_erase(void)
160 if (global_settings
.warnon_erase_dynplaylist
&&
161 !global_settings
.party_mode
&&
162 playlist_modified(NULL
))
164 static const char *lines
[] =
165 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
166 static const struct text_message message
={lines
, 1};
168 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
175 /* Performance optimized version of the read_line() (see below) function. */
176 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
177 int (*callback
)(int n
, char *buf
, void *parameters
))
187 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
191 if ( (p
= strchr(buf
, '\n')) != NULL
)
197 rc
= callback(count
, buf
, parameters
);
204 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
205 memmove(buf
, next
, pos
);
214 /* parse a line from a configuration file. the line format is:
218 Any whitespace before setting name or value (after ':') is ignored.
219 A # as first non-whitespace character discards the whole line.
220 Function sets pointers to null-terminated setting name and value.
221 Returns false if no valid config entry was found.
224 bool settings_parseline(char* line
, char** name
, char** value
)
228 line
= skip_whitespace(line
);
233 ptr
= strchr(line
, ':');
240 ptr
= skip_whitespace(ptr
);
245 static void system_flush(void)
249 call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
252 static void system_restore(void)
257 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
261 scrobbler_poweroff();
263 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
264 if(!charger_inserted())
267 bool batt_safe
= battery_level_safe();
268 #if CONFIG_CODEC != SWCODEC || defined(HAVE_RECORDING)
269 int audio_stat
= audio_status();
274 screens
[i
].clear_display();
282 if (!tagcache_prepare_shutdown())
285 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
289 level
= battery_level();
290 if (level
> 10 || level
< 0)
291 splash(0, str(LANG_SHUTTINGDOWN
));
294 msg_id
= LANG_WARNING_BATTERY_LOW
;
295 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
296 str(LANG_SHUTTINGDOWN
));
301 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
302 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY
),
303 str(LANG_SHUTTINGDOWN
));
305 #if CONFIG_CODEC != SWCODEC
306 if (global_settings
.fade_on_stop
307 && (audio_stat
& AUDIO_STATUS_PLAY
))
313 if (batt_safe
) /* do not save on critical battery */
315 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
316 if (audio_stat
& AUDIO_STATUS_RECORD
)
318 rec_command(RECORDING_CMD_STOP
);
319 /* wait for stop to complete */
320 while (audio_status() & AUDIO_STATUS_RECORD
)
324 bookmark_autobookmark(false);
326 /* audio_stop_recording == audio_stop for HWCODEC */
329 if (callback
!= NULL
)
332 #if CONFIG_CODEC != SWCODEC
333 /* wait for audio_stop or audio_stop_recording to complete */
334 while (audio_status())
338 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
339 audio_close_recording();
342 if(global_settings
.talk_menu
)
344 bool enqueue
= false;
347 talk_id(msg_id
, enqueue
);
350 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
351 #if CONFIG_CODEC == SWCODEC
357 #ifdef HAVE_EEPROM_SETTINGS
358 if (firmware_settings
.initialized
)
360 firmware_settings
.disk_clean
= true;
361 firmware_settings
.bl_version
= 0;
362 eeprom_settings_store();
376 bool list_stop_handler(void)
384 /* Stop the music if it is playing */
387 if (!global_settings
.party_mode
)
389 #if CONFIG_CODEC != SWCODEC
390 if (global_settings
.fade_on_stop
)
393 bookmark_autobookmark(true);
395 ret
= true; /* bookmarking can make a refresh necessary */
399 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
402 if (charger_inserted())
405 shutdown_screen(); /* won't return if shutdown actually happens */
407 ret
= true; /* screen is dirty, caller needs to refresh */
410 #ifndef HAVE_POWEROFF_WHILE_CHARGING
412 static long last_off
= 0;
414 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
416 if (charger_inserted())
419 ret
= true; /* screen is dirty, caller needs to refresh */
422 last_off
= current_tick
;
425 #endif /* CONFIG_CHARGING */
430 static bool waiting_to_resume_play
= false;
431 static long play_resume_tick
;
433 static void car_adapter_mode_processing(bool inserted
)
435 if (global_settings
.car_adapter_mode
)
440 * Just got plugged in, delay & resume if we were playing
442 if (audio_status() & AUDIO_STATUS_PAUSE
)
444 /* delay resume a bit while the engine is cranking */
445 play_resume_tick
= current_tick
+ HZ
*5;
446 waiting_to_resume_play
= true;
452 * Just got unplugged, pause if playing
454 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
455 !(audio_status() & AUDIO_STATUS_PAUSE
))
457 pause_action(true, true);
459 waiting_to_resume_play
= false;
464 static void car_adapter_tick(void)
466 if (waiting_to_resume_play
)
468 if (TIME_AFTER(current_tick
, play_resume_tick
))
470 if (audio_status() & AUDIO_STATUS_PAUSE
)
472 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
474 waiting_to_resume_play
= false;
479 void car_adapter_mode_init(void)
481 tick_add_task(car_adapter_tick
);
485 #ifdef HAVE_HEADPHONE_DETECTION
486 static void unplug_change(bool inserted
)
488 static bool headphone_caused_pause
= false;
490 if (global_settings
.unplug_mode
)
492 int audio_stat
= audio_status();
496 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
497 headphone_caused_pause
&&
498 global_settings
.unplug_mode
> 1 )
499 unpause_action(true, true);
500 headphone_caused_pause
= false;
502 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
503 !(audio_stat
& AUDIO_STATUS_PAUSE
))
505 headphone_caused_pause
= true;
506 pause_action(false, false);
513 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
515 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
516 static bool resume
= false;
521 case SYS_BATTERY_UPDATE
:
522 if(global_settings
.talk_battery_level
)
524 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
526 TALK_ID(battery_level(), UNIT_PERCENT
),
528 talk_force_enqueue_next();
531 case SYS_USB_CONNECTED
:
532 if (callback
!= NULL
)
534 #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
535 if (!mmc_touched() ||
536 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
541 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
542 check_bootfile(false); /* gets initial size */
545 gui_usb_screen_run(false);
547 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
548 check_bootfile(true);
553 return SYS_USB_CONNECTED
;
556 if (!clean_shutdown(callback
, parameter
))
560 case SYS_CHARGER_CONNECTED
:
561 car_adapter_mode_processing(true);
562 return SYS_CHARGER_CONNECTED
;
564 case SYS_CHARGER_DISCONNECTED
:
565 car_adapter_mode_processing(false);
566 /*reset rockbox battery runtime*/
567 global_status
.runtime
= 0;
568 return SYS_CHARGER_DISCONNECTED
;
570 case SYS_CAR_ADAPTER_RESUME
:
571 unpause_action(true, true);
572 return SYS_CAR_ADAPTER_RESUME
;
574 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
577 /* simple sanity: assume rockbox is on the first hotswappable
578 * driver, abort out if that one isn't inserted */
580 for (i
= 0; i
< NUM_DRIVES
; i
++)
582 if (storage_removable(i
) && !storage_present(i
))
583 return SYS_FS_CHANGED
;
586 check_bootfile(true); /* state gotten in main.c:init() */
589 return SYS_FS_CHANGED
;
591 #ifdef HAVE_HEADPHONE_DETECTION
592 case SYS_PHONE_PLUGGED
:
594 return SYS_PHONE_PLUGGED
;
596 case SYS_PHONE_UNPLUGGED
:
597 unplug_change(false);
598 return SYS_PHONE_UNPLUGGED
;
600 #ifdef IPOD_ACCESSORY_PROTOCOL
601 case SYS_IAP_PERIODIC
:
603 return SYS_IAP_PERIODIC
;
604 case SYS_IAP_HANDLEPKT
:
606 return SYS_IAP_HANDLEPKT
;
608 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
609 /* stop playback if we receive a call */
610 case SYS_CALL_INCOMING
:
611 resume
= audio_status() == AUDIO_STATUS_PLAY
;
613 return SYS_CALL_INCOMING
;
614 /* resume playback if needed */
615 case SYS_CALL_HUNG_UP
:
616 if (resume
&& playlist_resume() != -1)
618 playlist_start(global_status
.resume_index
,
619 global_status
.resume_offset
);
622 return SYS_CALL_HUNG_UP
;
624 #if (CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(PLATFORM_HAS_VOLUME_CHANGE)
625 case SYS_VOLUME_CHANGED
:
627 static bool firstvolume
= true;
628 /* kludge: since this events go to the button_queue,
629 * event data is available in the last button data */
630 int volume
= button_get_data();
631 DEBUGF("SYS_VOLUME_CHANGED: %d\n", volume
);
632 if (global_settings
.volume
!= volume
) {
633 global_settings
.volume
= volume
;
642 #ifdef HAVE_MULTIMEDIA_KEYS
643 /* multimedia keys on keyboards, headsets */
644 case BUTTON_MULTIMEDIA_PLAYPAUSE
:
646 int status
= audio_status();
647 if (status
& AUDIO_STATUS_PLAY
)
649 if (status
& AUDIO_STATUS_PAUSE
)
650 unpause_action(true, true);
652 pause_action(true, true);
655 if (playlist_resume() != -1)
657 playlist_start(global_status
.resume_index
,
658 global_status
.resume_offset
);
662 case BUTTON_MULTIMEDIA_NEXT
:
665 case BUTTON_MULTIMEDIA_PREV
:
668 case BUTTON_MULTIMEDIA_STOP
:
671 case BUTTON_MULTIMEDIA_REW
:
672 case BUTTON_MULTIMEDIA_FFWD
:
673 /* not supported yet, needs to be done in the WPS */
680 long default_event_handler(long event
)
682 return default_event_handler_ex(event
, NULL
, NULL
);
685 int show_logo( void )
687 #ifdef HAVE_LCD_BITMAP
691 snprintf(version
, sizeof(version
), "Ver. %s", rbversion
);
694 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2) || defined(SANSA_CLIPPLUS)
695 /* display the logo in the blue area of the screen */
696 lcd_setfont(FONT_SYSFIXED
);
697 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
698 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
699 0, (unsigned char *)version
);
700 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 16);
702 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 10);
703 lcd_setfont(FONT_SYSFIXED
);
704 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
705 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
706 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
708 lcd_setfont(FONT_UI
);
711 char *rockbox
= " ROCKbox!";
714 lcd_double_height(true);
715 lcd_puts(0, 0, rockbox
);
716 lcd_puts_scroll(0, 1, rbversion
);
720 #ifdef HAVE_REMOTE_LCD
721 lcd_remote_clear_display();
722 lcd_remote_bmp(&bm_remote_rockboxlogo
, 0, 10);
723 lcd_remote_setfont(FONT_SYSFIXED
);
724 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
725 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
726 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
727 lcd_remote_setfont(FONT_UI
);
735 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
737 memorize/compare details about the BOOTFILE
738 we don't use dircache because it may not be up to date after
739 USB disconnect (scanning in the background)
741 void check_bootfile(bool do_rolo
)
743 static unsigned short wrtdate
= 0;
744 static unsigned short wrttime
= 0;
746 struct dirent
* entry
= NULL
;
748 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
749 dir
= opendir(BOOTDIR
);
751 if(!dir
) return; /* do we want an error splash? */
753 /* loop all files in BOOTDIR */
754 while(0 != (entry
= readdir(dir
)))
756 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
758 struct dirinfo info
= dir_get_info(dir
, entry
);
759 /* found the bootfile */
760 if(wrtdate
&& do_rolo
)
762 if((info
.wrtdate
!= wrtdate
) ||
763 (info
.wrttime
!= wrttime
))
765 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
766 ID2P(LANG_REBOOT_NOW
) };
767 static const struct text_message message
={ lines
, 2 };
768 button_clear_queue(); /* Empty the keyboard buffer */
769 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
772 rolo_load(BOOTDIR
"/" BOOTFILE
);
776 wrtdate
= info
.wrtdate
;
777 wrttime
= info
.wrttime
;
785 /* check range, set volume and save settings */
788 const int min_vol
= sound_min(SOUND_VOLUME
);
789 const int max_vol
= sound_max(SOUND_VOLUME
);
790 if (global_settings
.volume
< min_vol
)
791 global_settings
.volume
= min_vol
;
792 if (global_settings
.volume
> max_vol
)
793 global_settings
.volume
= max_vol
;
794 sound_set_volume(global_settings
.volume
);
795 global_status
.last_volume_change
= current_tick
;
799 char* strrsplt(char* str
, int c
)
801 char* s
= strrchr(str
, c
);
816 * removes the extension of filename (if it doesn't start with a .)
817 * puts the result in buffer
819 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
821 char *dot
= strrchr(filename
, '.');
824 if (buffer_size
<= 0)
829 buffer_size
--; /* Make room for end nil */
831 if (dot
!= 0 && filename
[0] != '.')
833 len
= dot
- filename
;
834 len
= MIN(len
, buffer_size
);
841 strlcpy(buffer
, filename
, len
+ 1);
846 #if CONFIG_CODEC == SWCODEC
847 /* Play a standard sound */
848 void system_sound_play(enum system_sound sound
)
850 static const struct beep_params
853 unsigned short frequency
;
854 unsigned short duration
;
855 unsigned short amplitude
;
859 { &global_settings
.keyclick
,
860 4000, KEYCLICK_DURATION
, 2500 },
862 { &global_settings
.beep
,
864 [SOUND_TRACK_NO_MORE
] =
865 { &global_settings
.beep
,
869 const struct beep_params
*params
= &beep_params
[sound
];
871 if (*params
->setting
)
873 beep_play(params
->frequency
, params
->duration
,
874 params
->amplitude
* *params
->setting
);
878 /* Produce keyclick based upon button and global settings */
879 void keyclick_click(int button
)
881 static long last_button
= BUTTON_NONE
;
882 bool do_beep
= false;
883 /* Settings filters */
885 #ifdef HAVE_HARDWARE_CLICK
886 (global_settings
.keyclick
|| global_settings
.keyclick_hardware
)
888 global_settings
.keyclick
892 if (global_settings
.keyclick_repeats
|| !(button
& BUTTON_REPEAT
))
895 if (button
!= BUTTON_NONE
&& !(button
& BUTTON_REL
)
896 && !(button
& (SYS_EVENT
|BUTTON_MULTIMEDIA
)) )
901 else if ((button
& BUTTON_REPEAT
) && (last_button
== BUTTON_NONE
))
905 #ifdef HAVE_SCROLLWHEEL
906 else if (button
& (BUTTON_SCROLL_BACK
| BUTTON_SCROLL_FWD
))
912 if (button
&BUTTON_REPEAT
)
913 last_button
= button
;
915 last_button
= BUTTON_NONE
;
918 #ifdef HAVE_HARDWARE_CLICK
919 if (global_settings
.keyclick
)
921 system_sound_play(SOUND_KEYCLICK
);
923 if (global_settings
.keyclick_hardware
)
925 #if !defined(SIMULATOR)
926 piezo_button_beep(false, false);
930 system_sound_play(SOUND_KEYCLICK
);
934 #endif /* CONFIG_CODEC == SWCODEC */
936 #endif /* !defined(__PCTOOL__) */
938 /* Read (up to) a line of text from fd into buffer and return number of bytes
939 * read (which may be larger than the number of bytes stored in buffer). If
940 * an error occurs, -1 is returned (and buffer contains whatever could be
941 * read). A line is terminated by a LF char. Neither LF nor CR chars are
944 int read_line(int fd
, char* buffer
, int buffer_size
)
951 while (count
< buffer_size
)
955 if (1 != read(fd
, &c
, 1))
969 buffer
[MIN(count
, buffer_size
- 1)] = 0;
971 return errno
? -1 : num_read
;
975 char* skip_whitespace(char* const str
)
985 /* Format time into buf.
987 * buf - buffer to format to.
988 * buf_size - size of buffer.
989 * t - time to format, in milliseconds.
991 void format_time(char* buf
, int buf_size
, long t
)
993 int const time
= abs(t
/ 1000);
994 int const hours
= time
/ 3600;
995 int const minutes
= time
/ 60 - hours
* 60;
996 int const seconds
= time
% 60;
997 const char * const sign
= &"-"[t
< 0 ? 0 : 1];
1001 snprintf(buf
, buf_size
, "%s%d:%02d", sign
, minutes
, seconds
);
1005 snprintf(buf
, buf_size
, "%s%d:%02d:%02d", sign
, hours
, minutes
,
1011 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1012 * If no BOM is present this behaves like open().
1013 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1014 * the opened file and leave the file pointer set after the BOM.
1017 int open_utf8(const char* pathname
, int flags
)
1020 unsigned char bom
[BOM_UTF_8_SIZE
];
1022 fd
= open(pathname
, flags
, 0666);
1026 if(flags
& (O_TRUNC
| O_WRONLY
))
1028 write(fd
, BOM_UTF_8
, BOM_UTF_8_SIZE
);
1032 read(fd
, bom
, BOM_UTF_8_SIZE
);
1034 if(memcmp(bom
, BOM_UTF_8
, BOM_UTF_8_SIZE
))
1035 lseek(fd
, 0, SEEK_SET
);
1041 #ifdef HAVE_LCD_COLOR
1043 * Helper function to convert a string of 6 hex digits to a native colour
1046 static int hex2dec(int c
)
1048 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1049 (toupper(c
)) - 'A' + 10);
1052 int hex_to_rgb(const char* hex
, int* color
)
1054 int red
, green
, blue
;
1057 while ((i
< 6) && (isxdigit(hex
[i
])))
1063 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1064 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1065 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1067 *color
= LCD_RGBPACK(red
,green
,blue
);
1071 #endif /* HAVE_LCD_COLOR */
1073 #ifdef HAVE_LCD_BITMAP
1074 /* '0'-'3' are ASCII 0x30 to 0x33 */
1075 #define is0123(x) (((x) & 0xfc) == 0x30)
1076 #if !defined(__PCTOOL__) || defined(CHECKWPS)
1077 bool parse_color(enum screen_type screen
, char *text
, int *value
)
1079 (void)text
; (void)value
; /* silence warnings on mono bitmap */
1082 #ifdef HAVE_LCD_COLOR
1083 if (screens
[screen
].depth
> 2)
1085 if (hex_to_rgb(text
, value
) < 0)
1092 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1093 if (screens
[screen
].depth
== 2)
1095 if (text
[1] != '\0' || !is0123(*text
))
1097 *value
= *text
- '0';
1103 #endif /* !defined(__PCTOOL__) || defined(CHECKWPS) */
1105 /* only used in USB HID and set_time screen */
1106 #if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
1107 int clamp_value_wrap(int value
, int max
, int min
)
1117 #define MAX_ACTIVITY_DEPTH 12
1118 static enum current_activity
1119 current_activity
[MAX_ACTIVITY_DEPTH
] = {ACTIVITY_UNKNOWN
};
1120 static int current_activity_top
= 0;
1121 void push_current_activity(enum current_activity screen
)
1123 current_activity
[current_activity_top
++] = screen
;
1124 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1126 skinlist_set_cfg(i
, NULL
);
1129 void pop_current_activity(void)
1131 current_activity_top
--;
1132 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1134 skinlist_set_cfg(i
, NULL
);
1137 enum current_activity
get_current_activity(void)
1139 return current_activity
[current_activity_top
?current_activity_top
-1:0];