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 #ifdef HAVE_REMOTE_LCD
37 #include "lcd-remote.h"
40 #include "timefuncs.h"
42 #include "usb_screen.h"
45 #include "mp3_playback.h"
48 #include "ata_idle_notify.h"
51 #include "powermgmt.h"
52 #include "backlight.h"
57 #include "scrobbler.h"
70 #ifdef IPOD_ACCESSORY_PROTOCOL
74 #if (CONFIG_STORAGE & STORAGE_MMC)
78 #include "eeprom_settings.h"
79 #if defined(HAVE_RECORDING) && !defined(__PCTOOL__)
80 #include "recording.h"
82 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
85 #endif /* End HAVE_LCD_BITMAP */
89 #if CONFIG_CODEC == SWCODEC
90 #include "voice_thread.h"
94 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
95 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
100 #ifdef HAVE_HARDWARE_CLICK
104 /* units used with output_dyn_value */
105 const unsigned char * const byte_units
[] =
113 const unsigned char * const * const kbyte_units
= &byte_units
[1];
115 /* Format a large-range value for output, using the appropriate unit so that
116 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
117 * units) if possible, and 3 significant digits are shown. If a buffer is
118 * given, the result is snprintf()'d into that buffer, otherwise the result is
120 char *output_dyn_value(char *buf
, int buf_size
, int value
,
121 const unsigned char * const *units
, bool bin_scale
)
123 int scale
= bin_scale
? 1024 : 1000;
128 while (value
>= scale
)
130 fraction
= value
% scale
;
135 fraction
= fraction
* 1000 / 1024;
137 if (value
>= 100 || !unit_no
)
139 else if (value
>= 10)
140 snprintf(tbuf
, sizeof(tbuf
), "%01d", fraction
/ 100);
142 snprintf(tbuf
, sizeof(tbuf
), "%02d", fraction
/ 10);
147 snprintf(buf
, buf_size
, "%d%s%s%s", value
, str(LANG_POINT
),
148 tbuf
, P2STR(units
[unit_no
]));
150 snprintf(buf
, buf_size
, "%d%s", value
, P2STR(units
[unit_no
]));
154 talk_fractional(tbuf
, value
, P2ID(units
[unit_no
]));
159 /* Ask the user if they really want to erase the current dynamic playlist
160 * returns true if the playlist should be replaced */
161 bool warn_on_pl_erase(void)
163 if (global_settings
.warnon_erase_dynplaylist
&&
164 !global_settings
.party_mode
&&
165 playlist_modified(NULL
))
167 static const char *lines
[] =
168 {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT
)};
169 static const struct text_message message
={lines
, 1};
171 return (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
);
178 /* Performance optimized version of the read_line() (see below) function. */
179 int fast_readline(int fd
, char *buf
, int buf_size
, void *parameters
,
180 int (*callback
)(int n
, char *buf
, void *parameters
))
190 rc
= read(fd
, &buf
[pos
], buf_size
- pos
- 1);
194 if ( (p
= strchr(buf
, '\n')) != NULL
)
200 rc
= callback(count
, buf
, parameters
);
207 pos
= buf_size
- ((long)next
- (long)buf
) - 1;
208 memmove(buf
, next
, pos
);
217 /* parse a line from a configuration file. the line format is:
221 Any whitespace before setting name or value (after ':') is ignored.
222 A # as first non-whitespace character discards the whole line.
223 Function sets pointers to null-terminated setting name and value.
224 Returns false if no valid config entry was found.
227 bool settings_parseline(char* line
, char** name
, char** value
)
231 line
= skip_whitespace(line
);
236 ptr
= strchr(line
, ':');
243 ptr
= skip_whitespace(ptr
);
248 static void system_flush(void)
252 call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
255 static void system_restore(void)
260 static bool clean_shutdown(void (*callback
)(void *), void *parameter
)
264 scrobbler_poweroff();
266 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
267 if(!charger_inserted())
270 bool batt_safe
= battery_level_safe();
271 #if CONFIG_CODEC != SWCODEC || defined(HAVE_RECORDING)
272 int audio_stat
= audio_status();
277 screens
[i
].clear_display();
285 if (!tagcache_prepare_shutdown())
288 splash(HZ
, ID2P(LANG_TAGCACHE_BUSY
));
292 level
= battery_level();
293 if (level
> 10 || level
< 0)
294 splash(0, str(LANG_SHUTTINGDOWN
));
297 msg_id
= LANG_WARNING_BATTERY_LOW
;
298 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_LOW
),
299 str(LANG_SHUTTINGDOWN
));
304 msg_id
= LANG_WARNING_BATTERY_EMPTY
;
305 splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY
),
306 str(LANG_SHUTTINGDOWN
));
308 #if CONFIG_CODEC != SWCODEC
309 if (global_settings
.fade_on_stop
310 && (audio_stat
& AUDIO_STATUS_PLAY
))
316 if (batt_safe
) /* do not save on critical battery */
318 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
319 if (audio_stat
& AUDIO_STATUS_RECORD
)
321 rec_command(RECORDING_CMD_STOP
);
322 /* wait for stop to complete */
323 while (audio_status() & AUDIO_STATUS_RECORD
)
327 bookmark_autobookmark(false);
329 /* audio_stop_recording == audio_stop for HWCODEC */
332 if (callback
!= NULL
)
335 #if CONFIG_CODEC != SWCODEC
336 /* wait for audio_stop or audio_stop_recording to complete */
337 while (audio_status())
341 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
342 audio_close_recording();
345 if(global_settings
.talk_menu
)
347 bool enqueue
= false;
350 talk_id(msg_id
, enqueue
);
353 talk_id(LANG_SHUTTINGDOWN
, enqueue
);
354 #if CONFIG_CODEC == SWCODEC
360 #ifdef HAVE_EEPROM_SETTINGS
361 if (firmware_settings
.initialized
)
363 firmware_settings
.disk_clean
= true;
364 firmware_settings
.bl_version
= 0;
365 eeprom_settings_store();
379 bool list_stop_handler(void)
387 /* Stop the music if it is playing */
390 if (!global_settings
.party_mode
)
392 #if CONFIG_CODEC != SWCODEC
393 if (global_settings
.fade_on_stop
)
396 bookmark_autobookmark(true);
398 ret
= true; /* bookmarking can make a refresh necessary */
402 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
405 if (charger_inserted())
408 shutdown_screen(); /* won't return if shutdown actually happens */
410 ret
= true; /* screen is dirty, caller needs to refresh */
413 #ifndef HAVE_POWEROFF_WHILE_CHARGING
415 static long last_off
= 0;
417 if (TIME_BEFORE(current_tick
, last_off
+ HZ
/2))
419 if (charger_inserted())
422 ret
= true; /* screen is dirty, caller needs to refresh */
425 last_off
= current_tick
;
428 #endif /* CONFIG_CHARGING */
433 static bool waiting_to_resume_play
= false;
434 static long play_resume_tick
;
436 static void car_adapter_mode_processing(bool inserted
)
438 if (global_settings
.car_adapter_mode
)
443 * Just got plugged in, delay & resume if we were playing
445 if (audio_status() & AUDIO_STATUS_PAUSE
)
447 /* delay resume a bit while the engine is cranking */
448 play_resume_tick
= current_tick
+ HZ
*5;
449 waiting_to_resume_play
= true;
455 * Just got unplugged, pause if playing
457 if ((audio_status() & AUDIO_STATUS_PLAY
) &&
458 !(audio_status() & AUDIO_STATUS_PAUSE
))
460 pause_action(true, true);
462 waiting_to_resume_play
= false;
467 static void car_adapter_tick(void)
469 if (waiting_to_resume_play
)
471 if (TIME_AFTER(current_tick
, play_resume_tick
))
473 if (audio_status() & AUDIO_STATUS_PAUSE
)
475 queue_broadcast(SYS_CAR_ADAPTER_RESUME
, 0);
477 waiting_to_resume_play
= false;
482 void car_adapter_mode_init(void)
484 tick_add_task(car_adapter_tick
);
488 #ifdef HAVE_HEADPHONE_DETECTION
489 static void unplug_change(bool inserted
)
491 static bool headphone_caused_pause
= false;
493 if (global_settings
.unplug_mode
)
495 int audio_stat
= audio_status();
499 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
500 headphone_caused_pause
&&
501 global_settings
.unplug_mode
> 1 )
502 unpause_action(true, true);
503 headphone_caused_pause
= false;
505 if ((audio_stat
& AUDIO_STATUS_PLAY
) &&
506 !(audio_stat
& AUDIO_STATUS_PAUSE
))
508 headphone_caused_pause
= true;
509 pause_action(false, false);
516 long default_event_handler_ex(long event
, void (*callback
)(void *), void *parameter
)
518 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
519 static bool resume
= false;
524 case SYS_BATTERY_UPDATE
:
525 if(global_settings
.talk_battery_level
)
527 talk_ids(true, VOICE_PAUSE
, VOICE_PAUSE
,
529 TALK_ID(battery_level(), UNIT_PERCENT
),
531 talk_force_enqueue_next();
534 case SYS_USB_CONNECTED
:
535 if (callback
!= NULL
)
537 #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM))
538 if (!mmc_touched() ||
539 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
544 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
545 check_bootfile(false); /* gets initial size */
548 gui_usb_screen_run(false);
550 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF)
551 check_bootfile(true);
556 return SYS_USB_CONNECTED
;
559 if (!clean_shutdown(callback
, parameter
))
563 case SYS_CHARGER_CONNECTED
:
564 car_adapter_mode_processing(true);
565 return SYS_CHARGER_CONNECTED
;
567 case SYS_CHARGER_DISCONNECTED
:
568 car_adapter_mode_processing(false);
569 /*reset rockbox battery runtime*/
570 global_status
.runtime
= 0;
571 return SYS_CHARGER_DISCONNECTED
;
573 case SYS_CAR_ADAPTER_RESUME
:
574 unpause_action(true, true);
575 return SYS_CAR_ADAPTER_RESUME
;
577 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
580 /* simple sanity: assume rockbox is on the first hotswappable
581 * driver, abort out if that one isn't inserted */
583 for (i
= 0; i
< NUM_DRIVES
; i
++)
585 if (storage_removable(i
) && !storage_present(i
))
586 return SYS_FS_CHANGED
;
589 check_bootfile(true); /* state gotten in main.c:init() */
592 return SYS_FS_CHANGED
;
594 #ifdef HAVE_HEADPHONE_DETECTION
595 case SYS_PHONE_PLUGGED
:
597 return SYS_PHONE_PLUGGED
;
599 case SYS_PHONE_UNPLUGGED
:
600 unplug_change(false);
601 return SYS_PHONE_UNPLUGGED
;
603 #ifdef IPOD_ACCESSORY_PROTOCOL
604 case SYS_IAP_PERIODIC
:
606 return SYS_IAP_PERIODIC
;
607 case SYS_IAP_HANDLEPKT
:
609 return SYS_IAP_HANDLEPKT
;
611 #if CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO)
612 /* stop playback if we receive a call */
613 case SYS_CALL_INCOMING
:
614 resume
= audio_status() == AUDIO_STATUS_PLAY
;
616 return SYS_CALL_INCOMING
;
617 /* resume playback if needed */
618 case SYS_CALL_HUNG_UP
:
619 if (resume
&& playlist_resume() != -1)
621 playlist_start(global_status
.resume_index
,
622 global_status
.resume_offset
);
625 return SYS_CALL_HUNG_UP
;
627 #if (CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(PLATFORM_HAS_VOLUME_CHANGE)
628 case SYS_VOLUME_CHANGED
:
630 static bool firstvolume
= true;
631 /* kludge: since this events go to the button_queue,
632 * event data is available in the last button data */
633 int volume
= button_get_data();
634 DEBUGF("SYS_VOLUME_CHANGED: %d\n", volume
);
635 if (global_settings
.volume
!= volume
) {
636 global_settings
.volume
= volume
;
645 #ifdef HAVE_MULTIMEDIA_KEYS
646 /* multimedia keys on keyboards, headsets */
647 case BUTTON_MULTIMEDIA_PLAYPAUSE
:
649 int status
= audio_status();
650 if (status
& AUDIO_STATUS_PLAY
)
652 if (status
& AUDIO_STATUS_PAUSE
)
653 unpause_action(true, true);
655 pause_action(true, true);
658 if (playlist_resume() != -1)
660 playlist_start(global_status
.resume_index
,
661 global_status
.resume_offset
);
665 case BUTTON_MULTIMEDIA_NEXT
:
668 case BUTTON_MULTIMEDIA_PREV
:
671 case BUTTON_MULTIMEDIA_STOP
:
674 case BUTTON_MULTIMEDIA_REW
:
675 case BUTTON_MULTIMEDIA_FFWD
:
676 /* not supported yet, needs to be done in the WPS */
683 long default_event_handler(long event
)
685 return default_event_handler_ex(event
, NULL
, NULL
);
688 int show_logo( void )
690 #ifdef HAVE_LCD_BITMAP
694 snprintf(version
, sizeof(version
), "Ver. %s", rbversion
);
697 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2) || defined(SANSA_CLIPPLUS)
698 /* display the logo in the blue area of the screen */
699 lcd_setfont(FONT_SYSFIXED
);
700 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
701 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
702 0, (unsigned char *)version
);
703 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 16);
705 lcd_bmp(&bm_rockboxlogo
, (LCD_WIDTH
- BMPWIDTH_rockboxlogo
) / 2, 10);
706 lcd_setfont(FONT_SYSFIXED
);
707 lcd_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
708 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
709 LCD_HEIGHT
-font_h
, (unsigned char *)version
);
711 lcd_setfont(FONT_UI
);
714 char *rockbox
= " ROCKbox!";
717 lcd_double_height(true);
718 lcd_puts(0, 0, rockbox
);
719 lcd_puts_scroll(0, 1, rbversion
);
723 #ifdef HAVE_REMOTE_LCD
724 lcd_remote_clear_display();
725 lcd_remote_bmp(&bm_remote_rockboxlogo
, 0, 10);
726 lcd_remote_setfont(FONT_SYSFIXED
);
727 lcd_remote_getstringsize((unsigned char *)"A", &font_w
, &font_h
);
728 lcd_remote_putsxy((LCD_REMOTE_WIDTH
/2) - ((strlen(version
)*font_w
)/2),
729 LCD_REMOTE_HEIGHT
-font_h
, (unsigned char *)version
);
730 lcd_remote_setfont(FONT_UI
);
738 #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
740 memorize/compare details about the BOOTFILE
741 we don't use dircache because it may not be up to date after
742 USB disconnect (scanning in the background)
744 void check_bootfile(bool do_rolo
)
746 static unsigned short wrtdate
= 0;
747 static unsigned short wrttime
= 0;
749 struct dirent
* entry
= NULL
;
751 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
752 dir
= opendir(BOOTDIR
);
754 if(!dir
) return; /* do we want an error splash? */
756 /* loop all files in BOOTDIR */
757 while(0 != (entry
= readdir(dir
)))
759 if(!strcasecmp(entry
->d_name
, BOOTFILE
))
761 struct dirinfo info
= dir_get_info(dir
, entry
);
762 /* found the bootfile */
763 if(wrtdate
&& do_rolo
)
765 if((info
.wrtdate
!= wrtdate
) ||
766 (info
.wrttime
!= wrttime
))
768 static const char *lines
[] = { ID2P(LANG_BOOT_CHANGED
),
769 ID2P(LANG_REBOOT_NOW
) };
770 static const struct text_message message
={ lines
, 2 };
771 button_clear_queue(); /* Empty the keyboard buffer */
772 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
775 rolo_load(BOOTDIR
"/" BOOTFILE
);
779 wrtdate
= info
.wrtdate
;
780 wrttime
= info
.wrttime
;
788 /* check range, set volume and save settings */
791 const int min_vol
= sound_min(SOUND_VOLUME
);
792 const int max_vol
= sound_max(SOUND_VOLUME
);
793 if (global_settings
.volume
< min_vol
)
794 global_settings
.volume
= min_vol
;
795 if (global_settings
.volume
> max_vol
)
796 global_settings
.volume
= max_vol
;
797 sound_set_volume(global_settings
.volume
);
798 global_status
.last_volume_change
= current_tick
;
802 char* strrsplt(char* str
, int c
)
804 char* s
= strrchr(str
, c
);
819 * removes the extension of filename (if it doesn't start with a .)
820 * puts the result in buffer
822 char *strip_extension(char* buffer
, int buffer_size
, const char *filename
)
824 char *dot
= strrchr(filename
, '.');
827 if (buffer_size
<= 0)
832 buffer_size
--; /* Make room for end nil */
834 if (dot
!= 0 && filename
[0] != '.')
836 len
= dot
- filename
;
837 len
= MIN(len
, buffer_size
);
844 strlcpy(buffer
, filename
, len
+ 1);
849 #if CONFIG_CODEC == SWCODEC
850 /* Play a standard sound */
851 void system_sound_play(enum system_sound sound
)
853 static const struct beep_params
856 unsigned short frequency
;
857 unsigned short duration
;
858 unsigned short amplitude
;
862 { &global_settings
.keyclick
,
863 4000, KEYCLICK_DURATION
, 2500 },
865 { &global_settings
.beep
,
867 [SOUND_TRACK_NO_MORE
] =
868 { &global_settings
.beep
,
872 const struct beep_params
*params
= &beep_params
[sound
];
874 if (*params
->setting
)
876 beep_play(params
->frequency
, params
->duration
,
877 params
->amplitude
* *params
->setting
);
881 static keyclick_callback keyclick_current_callback
= NULL
;
882 static void* keyclick_data
= NULL
;
883 void keyclick_set_callback(keyclick_callback cb
, void* data
)
885 keyclick_current_callback
= cb
;
886 keyclick_data
= data
;
889 /* Produce keyclick based upon button and global settings */
890 void keyclick_click(int action
)
893 static long last_button
= BUTTON_NONE
;
894 bool do_beep
= false;
896 get_action_statuscode(&button
);
897 /* Settings filters */
899 #ifdef HAVE_HARDWARE_CLICK
900 (global_settings
.keyclick
|| global_settings
.keyclick_hardware
)
902 global_settings
.keyclick
906 if (global_settings
.keyclick_repeats
|| !(button
& BUTTON_REPEAT
))
909 if (button
!= BUTTON_NONE
&& !(button
& BUTTON_REL
)
910 && !(button
& (SYS_EVENT
|BUTTON_MULTIMEDIA
)) )
915 else if ((button
& BUTTON_REPEAT
) && (last_button
== BUTTON_NONE
))
919 #ifdef HAVE_SCROLLWHEEL
920 else if (button
& (BUTTON_SCROLL_BACK
| BUTTON_SCROLL_FWD
))
926 if (button
&BUTTON_REPEAT
)
927 last_button
= button
;
929 last_button
= BUTTON_NONE
;
931 if (do_beep
&& keyclick_current_callback
)
932 do_beep
= keyclick_current_callback(action
, keyclick_data
);
933 keyclick_current_callback
= NULL
;
937 #ifdef HAVE_HARDWARE_CLICK
938 if (global_settings
.keyclick
)
940 system_sound_play(SOUND_KEYCLICK
);
942 if (global_settings
.keyclick_hardware
)
944 #if !defined(SIMULATOR)
945 piezo_button_beep(false, false);
949 system_sound_play(SOUND_KEYCLICK
);
953 #endif /* CONFIG_CODEC == SWCODEC */
955 #endif /* !defined(__PCTOOL__) */
957 /* Read (up to) a line of text from fd into buffer and return number of bytes
958 * read (which may be larger than the number of bytes stored in buffer). If
959 * an error occurs, -1 is returned (and buffer contains whatever could be
960 * read). A line is terminated by a LF char. Neither LF nor CR chars are
963 int read_line(int fd
, char* buffer
, int buffer_size
)
970 while (count
< buffer_size
)
974 if (1 != read(fd
, &c
, 1))
988 buffer
[MIN(count
, buffer_size
- 1)] = 0;
990 return errno
? -1 : num_read
;
994 char* skip_whitespace(char* const str
)
1004 /* Format time into buf.
1006 * buf - buffer to format to.
1007 * buf_size - size of buffer.
1008 * t - time to format, in milliseconds.
1010 void format_time(char* buf
, int buf_size
, long t
)
1012 int const time
= abs(t
/ 1000);
1013 int const hours
= time
/ 3600;
1014 int const minutes
= time
/ 60 - hours
* 60;
1015 int const seconds
= time
% 60;
1016 const char * const sign
= &"-"[t
< 0 ? 0 : 1];
1020 snprintf(buf
, buf_size
, "%s%d:%02d", sign
, minutes
, seconds
);
1024 snprintf(buf
, buf_size
, "%s%d:%02d:%02d", sign
, hours
, minutes
,
1030 /** Open a UTF-8 file and set file descriptor to first byte after BOM.
1031 * If no BOM is present this behaves like open().
1032 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1033 * the opened file and leave the file pointer set after the BOM.
1036 int open_utf8(const char* pathname
, int flags
)
1039 unsigned char bom
[BOM_UTF_8_SIZE
];
1041 fd
= open(pathname
, flags
, 0666);
1045 if(flags
& (O_TRUNC
| O_WRONLY
))
1047 write(fd
, BOM_UTF_8
, BOM_UTF_8_SIZE
);
1051 read(fd
, bom
, BOM_UTF_8_SIZE
);
1053 if(memcmp(bom
, BOM_UTF_8
, BOM_UTF_8_SIZE
))
1054 lseek(fd
, 0, SEEK_SET
);
1060 #ifdef HAVE_LCD_COLOR
1062 * Helper function to convert a string of 6 hex digits to a native colour
1065 static int hex2dec(int c
)
1067 return (((c
) >= '0' && ((c
) <= '9')) ? (c
) - '0' :
1068 (toupper(c
)) - 'A' + 10);
1071 int hex_to_rgb(const char* hex
, int* color
)
1073 int red
, green
, blue
;
1076 while ((i
< 6) && (isxdigit(hex
[i
])))
1082 red
= (hex2dec(hex
[0]) << 4) | hex2dec(hex
[1]);
1083 green
= (hex2dec(hex
[2]) << 4) | hex2dec(hex
[3]);
1084 blue
= (hex2dec(hex
[4]) << 4) | hex2dec(hex
[5]);
1086 *color
= LCD_RGBPACK(red
,green
,blue
);
1090 #endif /* HAVE_LCD_COLOR */
1092 #ifdef HAVE_LCD_BITMAP
1093 /* '0'-'3' are ASCII 0x30 to 0x33 */
1094 #define is0123(x) (((x) & 0xfc) == 0x30)
1095 #if !defined(__PCTOOL__) || defined(CHECKWPS)
1096 bool parse_color(enum screen_type screen
, char *text
, int *value
)
1098 (void)text
; (void)value
; /* silence warnings on mono bitmap */
1101 #ifdef HAVE_LCD_COLOR
1102 if (screens
[screen
].depth
> 2)
1104 if (hex_to_rgb(text
, value
) < 0)
1111 #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
1112 if (screens
[screen
].depth
== 2)
1114 if (text
[1] != '\0' || !is0123(*text
))
1116 *value
= *text
- '0';
1122 #endif /* !defined(__PCTOOL__) || defined(CHECKWPS) */
1124 /* only used in USB HID and set_time screen */
1125 #if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
1126 int clamp_value_wrap(int value
, int max
, int min
)
1136 #define MAX_ACTIVITY_DEPTH 12
1137 static enum current_activity
1138 current_activity
[MAX_ACTIVITY_DEPTH
] = {ACTIVITY_UNKNOWN
};
1139 static int current_activity_top
= 0;
1140 void push_current_activity(enum current_activity screen
)
1142 current_activity
[current_activity_top
++] = screen
;
1143 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1145 skinlist_set_cfg(i
, NULL
);
1148 void pop_current_activity(void)
1150 current_activity_top
--;
1151 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
1153 skinlist_set_cfg(i
, NULL
);
1156 enum current_activity
get_current_activity(void)
1158 return current_activity
[current_activity_top
?current_activity_top
-1:0];