1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by wavey@wavey.org
11 * RTC config saving code (C) 2002 by hessu@hes.iki.fi
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
31 #include "backlight.h"
38 #include "ata_idle_notify.h"
45 #ifdef HAVE_LCD_BITMAP
48 #include "peakmeter.h"
53 #include "powermgmt.h"
58 #include "rbunicode.h"
60 #include "statusbar.h"
63 #include "settings_list.h"
64 #include "filetypes.h"
66 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
74 #if CONFIG_CODEC == MAS3507D
75 void dac_line_in(bool enable
);
77 struct user_settings global_settings
;
78 struct system_status global_status
;
80 #if CONFIG_CODEC == SWCODEC
84 #include "enc_config.h"
86 #endif /* CONFIG_CODEC == SWCODEC */
88 #define NVRAM_BLOCK_SIZE 44
90 #ifdef HAVE_LCD_BITMAP
96 #ifdef HAVE_REMOTE_LCD
97 #include "lcd-remote.h"
101 #include "usbstack.h"
106 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
107 /* NVRAM is set out as
111 [3] stored variable count
113 [8-NVRAM_BLOCK_SIZE] data
115 #define NVRAM_DATA_START 8
116 #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
117 static char nvram_buffer
[NVRAM_BLOCK_SIZE
];
119 static bool read_nvram_data(char* buf
, int max_len
)
121 unsigned crc32
= 0xffffffff;
122 int var_count
= 0, i
= 0, buf_pos
= 0;
124 int fd
= open(NVRAM_FILE
,O_RDONLY
);
127 memset(buf
,0,max_len
);
128 if (read(fd
,buf
,max_len
) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
132 memset(buf
,0,max_len
);
134 for (i
=0; i
< max_len
; i
++ )
135 buf
[i
] = rtc_read(0x14+i
);
137 /* check magic, version */
138 if ((buf
[0] != 'R') || (buf
[1] != 'b')
139 || (buf
[2] != NVRAM_CONFIG_VERSION
))
142 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
143 max_len
-NVRAM_DATA_START
-1,0xffffffff);
144 if (memcmp(&crc32
,&buf
[4],4))
146 /* all good, so read in the settings */
148 buf_pos
= NVRAM_DATA_START
;
149 for(i
=0; i
<nb_settings
; i
++)
151 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
152 >>F_NVRAM_MASK_SHIFT
;
155 if ((var_count
>0) && (buf_pos
<max_len
))
157 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
158 buf_pos
+= nvram_bytes
;
161 else /* should only happen when new items are added to the end */
163 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
169 static bool write_nvram_data(char* buf
, int max_len
)
171 unsigned crc32
= 0xffffffff;
172 int i
= 0, buf_pos
= 0;
177 memset(buf
,0,max_len
);
179 buf
[0] = 'R'; buf
[1] = 'b';
180 buf
[2] = NVRAM_CONFIG_VERSION
;
181 buf_pos
= NVRAM_DATA_START
;
182 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
184 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
185 >>F_NVRAM_MASK_SHIFT
;
188 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
189 buf_pos
+= nvram_bytes
;
193 /* count and crc32 */
195 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
196 max_len
-NVRAM_DATA_START
-1,0xffffffff);
197 memcpy(&buf
[4],&crc32
,4);
199 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
);
202 int len
= write(fd
,buf
,max_len
);
208 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
209 that it would write a number of bytes at a time since the RTC chip
210 supports that, but this will have to do for now 8-) */
211 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
212 int r
= rtc_write(0x14+i
, buf
[i
]);
214 DEBUGF( "save_config_buffer: rtc_write failed at addr 0x%02x: %d\n",
223 /** Reading from a config file **/
225 * load settings from disk or RTC RAM
227 void settings_load(int which
)
229 DEBUGF( "reload_all_settings()\n" );
230 if (which
&SETTINGS_RTC
)
231 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
232 if (which
&SETTINGS_HD
)
234 settings_load_config(CONFIGFILE
,false);
235 settings_load_config(FIXEDSETTINGSFILE
,false);
239 static bool cfg_string_to_int(int setting_id
, int* out
, char* str
)
241 const char* start
= settings
[setting_id
].cfg_vals
;
247 end
= strchr(start
, ',');
250 if (!strcmp(str
, start
))
257 strncpy(temp
, start
, end
-start
);
258 temp
[end
-start
] = '\0';
259 if (!strcmp(str
, temp
))
270 bool settings_load_config(const char* file
, bool apply
)
277 fd
= open(file
, O_RDONLY
);
281 while (read_line(fd
, line
, sizeof line
) > 0)
283 if (!settings_parseline(line
, &name
, &value
))
285 for(i
=0; i
<nb_settings
; i
++)
287 if (settings
[i
].cfg_name
== NULL
)
289 if (!strcasecmp(name
,settings
[i
].cfg_name
))
291 switch (settings
[i
].flags
&F_T_MASK
)
295 #ifdef HAVE_LCD_COLOR
296 if (settings
[i
].flags
&F_RGB
)
297 *(int*)settings
[i
].setting
= hex_to_rgb(value
);
300 if (settings
[i
].cfg_vals
== NULL
)
302 *(int*)settings
[i
].setting
= atoi(value
);
306 cfg_string_to_int(i
,(int*)settings
[i
].setting
,value
);
312 if (cfg_string_to_int(i
,&temp
,value
))
313 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
319 char storage
[MAX_PATH
];
320 if (settings
[i
].filename_setting
->prefix
)
322 int len
= strlen(settings
[i
].filename_setting
->prefix
);
323 if (!strncasecmp(value
,
324 settings
[i
].filename_setting
->prefix
,
327 strncpy(storage
,&value
[len
],MAX_PATH
);
329 else strncpy(storage
,value
,MAX_PATH
);
331 else strncpy(storage
,value
,MAX_PATH
);
332 if (settings
[i
].filename_setting
->suffix
)
334 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
337 strncpy((char*)settings
[i
].setting
,storage
,
338 settings
[i
].filename_setting
->max_len
);
339 ((char*)settings
[i
].setting
)
340 [settings
[i
].filename_setting
->max_len
-1] = '\0';
345 } /* if (!strcmp(name,settings[i].cfg_name)) */
356 /** Writing to a config file and saving settings **/
358 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
360 const char* start
= settings
[setting_id
].cfg_vals
;
365 start
= strchr(start
,',');
371 end
= strchr(start
,',');
373 strncpy(buf
, start
, buf_len
);
376 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
377 strncpy(buf
, start
, len
);
382 static bool is_changed(int setting_id
)
384 const struct settings_list
*setting
= &settings
[setting_id
];
385 switch (setting
->flags
&F_T_MASK
)
389 if (setting
->flags
&F_DEF_ISFUNC
)
391 if (*(int*)setting
->setting
== setting
->default_val
.func())
394 else if (setting
->flags
&F_T_SOUND
)
396 if (*(int*)setting
->setting
==
397 sound_default(setting
->sound_setting
->setting
))
400 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
404 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
409 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
416 static bool settings_write_config(char* filename
, int options
)
420 char value
[MAX_PATH
];
421 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
424 fdprintf(fd
, "# .cfg file created by rockbox %s - "
425 "http://www.rockbox.org\r\n\r\n", appsversion
);
426 for(i
=0; i
<nb_settings
; i
++)
428 if (settings
[i
].cfg_name
== NULL
)
432 if ((options
== SETTINGS_SAVE_CHANGED
) &&
435 else if ((options
== SETTINGS_SAVE_THEME
) &&
436 ((settings
[i
].flags
&F_THEMESETTING
) == 0))
438 #ifdef HAVE_RECORDING
439 else if ((options
== SETTINGS_SAVE_RECPRESETS
) &&
440 ((settings
[i
].flags
&F_RECSETTING
) == 0))
443 switch (settings
[i
].flags
&F_T_MASK
)
447 #ifdef HAVE_LCD_COLOR
448 if (settings
[i
].flags
&F_RGB
)
450 int colour
= *(int*)settings
[i
].setting
;
451 snprintf(value
,MAX_PATH
,"%02x%02x%02x",
452 (int)RGB_UNPACK_RED(colour
),
453 (int)RGB_UNPACK_GREEN(colour
),
454 (int)RGB_UNPACK_BLUE(colour
));
458 if (settings
[i
].cfg_vals
== NULL
)
460 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
464 cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
470 *(bool*)settings
[i
].setting
==false?0:1, value
, MAX_PATH
);
474 if (((char*)settings
[i
].setting
)[0] == '\0')
476 if (settings
[i
].filename_setting
->prefix
)
478 snprintf(value
,MAX_PATH
,"%s%s%s",
479 settings
[i
].filename_setting
->prefix
,
480 (char*)settings
[i
].setting
,
481 settings
[i
].filename_setting
->suffix
);
483 else strncpy(value
,(char*)settings
[i
].setting
,
484 settings
[i
].filename_setting
->max_len
);
488 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
494 static bool flush_global_status_callback(void)
496 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
499 static bool flush_config_block_callback(void)
502 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
503 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
508 * persist all runtime user settings to disk or RTC RAM
510 static void update_runtime(void)
514 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
515 global_status
.runtime
+= elapsed_secs
;
516 lasttime
+= (elapsed_secs
* HZ
);
518 if ( global_status
.runtime
> global_status
.topruntime
)
519 global_status
.topruntime
= global_status
.runtime
;
522 void status_save( void )
526 /* this will be done in the ata_callback if
527 target doesnt have rtc ram */
528 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
530 register_ata_idle_func(flush_global_status_callback
);
534 int settings_save( void )
538 /* this will be done in the ata_callback if
539 target doesnt have rtc ram */
540 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
542 if(!register_ata_idle_func(flush_config_block_callback
))
547 screens
[i
].clear_display();
548 #ifdef HAVE_LCD_CHARCELLS
549 screens
[i
].puts(0, 0, str(LANG_SETTINGS_SAVE_FAILED
));
550 screens
[i
].puts(0, 1, str(LANG_SETTINGS_PARTITION
));
552 screens
[i
].puts(4, 2, str(LANG_SETTINGS_SAVE_FAILED
));
553 screens
[i
].puts(2, 4, str(LANG_SETTINGS_PARTITION
));
557 cond_talk_ids_fq(LANG_SETTINGS_SAVE_FAILED
);
563 bool settings_save_config(int options
)
565 char filename
[MAX_PATH
];
569 case SETTINGS_SAVE_THEME
:
572 #ifdef HAVE_RECORDING
573 case SETTINGS_SAVE_RECPRESETS
:
574 folder
= RECPRESETS_DIR
;
578 folder
= ROCKBOX_DIR
;
580 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
581 IF_CNFN_NUM_(, NULL
));
583 /* allow user to modify filename */
585 if (!kbd_input(filename
, sizeof filename
)) {
589 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
594 if (settings_write_config(filename
, options
))
595 gui_syncsplash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
597 gui_syncsplash(HZ
, ID2P(LANG_FAILED
));
601 /** Apply and Reset settings **/
604 #ifdef HAVE_LCD_BITMAP
606 * Applies the range infos stored in global_settings to
609 void settings_apply_pm_range(void)
613 /* depending on the scale mode (dBfs or percent) the values
614 of global_settings.peak_meter_dbfs have different meanings */
615 if (global_settings
.peak_meter_dbfs
)
617 /* convert to dBfs * 100 */
618 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
619 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
623 /* percent is stored directly -> no conversion */
624 pm_min
= global_settings
.peak_meter_min
;
625 pm_max
= global_settings
.peak_meter_max
;
628 /* apply the range */
629 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
631 #endif /* HAVE_LCD_BITMAP */
633 void sound_settings_apply(void)
635 #if CONFIG_CODEC == SWCODEC
636 sound_set_dsp_callback(dsp_callback
);
638 sound_set(SOUND_BASS
, global_settings
.bass
);
639 sound_set(SOUND_TREBLE
, global_settings
.treble
);
640 sound_set(SOUND_BALANCE
, global_settings
.balance
);
641 sound_set(SOUND_VOLUME
, global_settings
.volume
);
642 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
643 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
644 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
645 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
646 sound_set(SOUND_AVC
, global_settings
.avc
);
647 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
648 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
649 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
650 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
651 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
652 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
655 #ifdef HAVE_USB_POWER
657 usb_charging_enable(global_settings
.usb_charging
);
662 void settings_apply(void)
665 #if CONFIG_CODEC == SWCODEC
669 DEBUGF( "settings_apply()\n" );
670 sound_settings_apply();
672 #ifndef HAVE_FLASH_STORAGE
673 audio_set_buffer_margin(global_settings
.buffer_margin
);
676 #ifdef HAVE_LCD_CONTRAST
677 lcd_set_contrast(global_settings
.contrast
);
679 lcd_scroll_speed(global_settings
.scroll_speed
);
680 #ifdef HAVE_REMOTE_LCD
681 lcd_remote_set_contrast(global_settings
.remote_contrast
);
682 lcd_remote_set_invert_display(global_settings
.remote_invert
);
683 lcd_remote_set_flip(global_settings
.remote_flip_display
);
684 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
685 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
686 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
687 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
688 #ifdef HAVE_REMOTE_LCD_TICKING
689 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
691 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
693 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
695 #ifdef HAS_REMOTE_BUTTON_HOLD
696 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
698 #endif /* HAVE_REMOTE_LCD */
699 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
700 backlight_set_brightness(global_settings
.brightness
);
702 #ifdef HAVE_BACKLIGHT
703 backlight_set_timeout(global_settings
.backlight_timeout
);
705 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
707 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
708 backlight_set_fade_in(global_settings
.backlight_fade_in
);
709 backlight_set_fade_out(global_settings
.backlight_fade_out
);
712 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
713 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
715 #ifdef HAVE_BUTTON_LIGHT
716 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
718 #ifndef HAVE_FLASH_STORAGE
719 ata_spindown(global_settings
.disk_spindown
);
721 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
722 dac_line_in(global_settings
.line_in
);
724 set_poweroff_timeout(global_settings
.poweroff
);
726 set_battery_capacity(global_settings
.battery_capacity
);
727 #if BATTERY_TYPES_COUNT > 1
728 set_battery_type(global_settings
.battery_type
);
731 #ifdef HAVE_LCD_BITMAP
732 lcd_set_invert_display(global_settings
.invert
);
733 lcd_set_flip(global_settings
.flip_display
);
734 button_set_flip(global_settings
.flip_display
);
735 lcd_update(); /* refresh after flipping the screen */
736 settings_apply_pm_range();
737 peak_meter_init_times(
738 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
739 global_settings
.peak_meter_clip_hold
);
743 unload_wps_backdrop();
745 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
746 unload_remote_wps_backdrop();
748 if ( global_settings
.wps_file
[0] &&
749 global_settings
.wps_file
[0] != 0xff ) {
750 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
751 global_settings
.wps_file
);
752 wps_data_load(gui_wps
[0].data
, buf
, true);
756 wps_data_init(gui_wps
[0].data
);
757 #ifdef HAVE_REMOTE_LCD
758 gui_wps
[0].data
->remote_wps
= false;
763 if ( global_settings
.backdrop_file
[0] &&
764 global_settings
.backdrop_file
[0] != 0xff ) {
765 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
766 global_settings
.backdrop_file
);
767 load_main_backdrop(buf
);
769 unload_main_backdrop();
771 show_main_backdrop();
773 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
774 show_remote_main_backdrop();
777 #ifdef HAVE_LCD_COLOR
778 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
779 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
780 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
781 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
782 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
785 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
786 if ( global_settings
.rwps_file
[0]) {
787 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
788 global_settings
.rwps_file
);
789 wps_data_load(gui_wps
[1].data
, buf
, true);
793 wps_data_init(gui_wps
[1].data
);
794 gui_wps
[1].data
->remote_wps
= true;
798 #ifdef HAVE_LCD_BITMAP
799 if ( global_settings
.font_file
[0]) {
800 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
801 global_settings
.font_file
);
807 if ( global_settings
.kbd_file
[0]) {
808 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
809 global_settings
.kbd_file
);
815 lcd_scroll_step(global_settings
.scroll_step
);
816 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
817 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
819 lcd_jump_scroll(global_settings
.jump_scroll
);
820 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
822 lcd_bidir_scroll(global_settings
.bidir_limit
);
823 lcd_scroll_delay(global_settings
.scroll_delay
);
825 if ( global_settings
.lang_file
[0]) {
826 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
827 global_settings
.lang_file
);
829 talk_init(); /* use voice of same language */
832 set_codepage(global_settings
.default_codepage
);
834 #if CONFIG_CODEC == SWCODEC
835 audio_set_crossfade(global_settings
.crossfade
);
836 dsp_set_replaygain();
837 dsp_set_crossfeed(global_settings
.crossfeed
);
838 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
839 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
840 global_settings
.crossfeed_hf_attenuation
,
841 global_settings
.crossfeed_hf_cutoff
);
843 /* Configure software equalizer, hardware eq is handled in audio_init() */
844 dsp_set_eq(global_settings
.eq_enabled
);
845 dsp_set_eq_precut(global_settings
.eq_precut
);
846 for(i
= 0; i
< 5; i
++) {
850 dsp_dither_enable(global_settings
.dithering_enabled
);
853 #ifdef HAVE_SPDIF_POWER
854 spdif_power_enable(global_settings
.spdif_enable
);
857 #ifdef HAVE_BACKLIGHT
858 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
859 #ifdef HAVE_REMOTE_LCD
860 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
862 #ifdef HAS_BUTTON_HOLD
863 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
865 #ifdef HAVE_LCD_SLEEP
866 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
868 #endif /* HAVE_BACKLIGHT */
870 /* This should stay last */
871 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
872 enc_global_settings_apply();
874 /* load the icon set */
877 #ifdef HAVE_LCD_COLOR
878 if (global_settings
.colors_file
)
879 read_color_theme_file();
884 #if USBSTACK_CAPS == (CONTROLLER_DEVICE|CONTROLLER_HOST)
885 usb_controller_select(global_settings
.usb_stack_mode
);
886 #elif USBSTACK_CAPS == (CONTROLLER_DEVICE)
887 usb_controller_select(DEVICE
);
888 #elif USBSTACK_CAPS == (CONTROLLER_HOST)
889 usb_controller_select(HOST
);
892 usb_device_driver_bind(global_settings
.usb_stack_device_driver
);
898 * reset all settings to their default value
900 void settings_reset(void) {
903 DEBUGF( "settings_reset()\n" );
905 for(i
=0; i
<nb_settings
; i
++)
907 switch (settings
[i
].flags
&F_T_MASK
)
911 if (settings
[i
].flags
&F_DEF_ISFUNC
)
912 *(int*)settings
[i
].setting
= settings
[i
].default_val
.func();
913 else if (settings
[i
].flags
&F_T_SOUND
)
914 *(int*)settings
[i
].setting
=
915 sound_default(settings
[i
].sound_setting
->setting
);
916 else *(int*)settings
[i
].setting
= settings
[i
].default_val
.int_
;
919 *(bool*)settings
[i
].setting
= settings
[i
].default_val
.bool_
;
923 strncpy((char*)settings
[i
].setting
,
924 settings
[i
].default_val
.charptr
,MAX_FILENAME
);
928 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
929 enc_global_settings_reset();
933 /** Changing setting values **/
934 const struct settings_list
* find_setting(void* variable
, int *id
)
937 for(i
=0;i
<nb_settings
;i
++)
939 if (settings
[i
].setting
== variable
)
949 void talk_setting(void *global_settings_variable
)
951 const struct settings_list
*setting
;
952 if (!global_settings
.talk_menu
)
954 setting
= find_setting(global_settings_variable
, NULL
);
957 if (setting
->lang_id
)
958 talk_id(setting
->lang_id
,false);
961 bool set_bool(const char* string
, bool* variable
)
963 return set_bool_options(string
, variable
,
964 (char *)STR(LANG_SET_BOOL_YES
),
965 (char *)STR(LANG_SET_BOOL_NO
),
970 bool set_bool_options(const char* string
, bool* variable
,
971 const char* yes_str
, int yes_voice
,
972 const char* no_str
, int no_voice
,
973 void (*function
)(bool))
975 struct opt_items names
[] = {
976 {(unsigned char *)no_str
, no_voice
},
977 {(unsigned char *)yes_str
, yes_voice
}
981 result
= set_option(string
, variable
, BOOL
, names
, 2,
982 (void (*)(int))function
);
986 bool set_int(const unsigned char* string
,
990 void (*function
)(int),
994 void (*formatter
)(char*, size_t, int, const char*) )
996 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
997 step
, min
, max
, formatter
, NULL
);
1001 /** extra stuff which is probably misplaced **/
1003 void set_file(char* filename
, char* setting
, int maxlen
)
1005 char* fptr
= strrchr(filename
,'/');
1018 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1022 if(ptr
== fptr
) extlen
= 0;
1024 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1025 (len
-extlen
> maxlen
))
1028 strncpy(setting
, fptr
, len
-extlen
);
1029 setting
[len
-extlen
]=0;