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"
102 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
103 /* NVRAM is set out as
107 [3] stored variable count
109 [8-NVRAM_BLOCK_SIZE] data
111 #define NVRAM_DATA_START 8
112 #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
113 static char nvram_buffer
[NVRAM_BLOCK_SIZE
];
115 static bool read_nvram_data(char* buf
, int max_len
)
117 unsigned crc32
= 0xffffffff;
118 int var_count
= 0, i
= 0, buf_pos
= 0;
120 int fd
= open(NVRAM_FILE
,O_RDONLY
);
123 memset(buf
,0,max_len
);
124 if (read(fd
,buf
,max_len
) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
128 memset(buf
,0,max_len
);
130 for (i
=0; i
< max_len
; i
++ )
131 buf
[i
] = rtc_read(0x14+i
);
133 /* check magic, version */
134 if ((buf
[0] != 'R') || (buf
[1] != 'b')
135 || (buf
[2] != NVRAM_CONFIG_VERSION
))
138 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
139 max_len
-NVRAM_DATA_START
-1,0xffffffff);
140 if (memcmp(&crc32
,&buf
[4],4))
142 /* all good, so read in the settings */
144 buf_pos
= NVRAM_DATA_START
;
145 for(i
=0; i
<nb_settings
; i
++)
147 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
148 >>F_NVRAM_MASK_SHIFT
;
151 if ((var_count
>0) && (buf_pos
<max_len
))
153 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
154 buf_pos
+= nvram_bytes
;
157 else /* should only happen when new items are added to the end */
159 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
165 static bool write_nvram_data(char* buf
, int max_len
)
167 unsigned crc32
= 0xffffffff;
168 int i
= 0, buf_pos
= 0;
173 memset(buf
,0,max_len
);
175 buf
[0] = 'R'; buf
[1] = 'b';
176 buf
[2] = NVRAM_CONFIG_VERSION
;
177 buf_pos
= NVRAM_DATA_START
;
178 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
180 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
181 >>F_NVRAM_MASK_SHIFT
;
184 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
185 buf_pos
+= nvram_bytes
;
189 /* count and crc32 */
191 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
192 max_len
-NVRAM_DATA_START
-1,0xffffffff);
193 memcpy(&buf
[4],&crc32
,4);
195 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
);
198 int len
= write(fd
,buf
,max_len
);
204 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
205 that it would write a number of bytes at a time since the RTC chip
206 supports that, but this will have to do for now 8-) */
207 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
208 int r
= rtc_write(0x14+i
, buf
[i
]);
210 DEBUGF( "save_config_buffer: rtc_write failed at addr 0x%02x: %d\n",
219 /** Reading from a config file **/
221 * load settings from disk or RTC RAM
223 void settings_load(int which
)
225 DEBUGF( "reload_all_settings()\n" );
226 if (which
&SETTINGS_RTC
)
227 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
228 if (which
&SETTINGS_HD
)
230 settings_load_config(CONFIGFILE
,false);
231 settings_load_config(FIXEDSETTINGSFILE
,false);
235 static bool cfg_string_to_int(int setting_id
, int* out
, char* str
)
237 const char* start
= settings
[setting_id
].cfg_vals
;
243 end
= strchr(start
, ',');
246 if (!strcmp(str
, start
))
253 strncpy(temp
, start
, end
-start
);
254 temp
[end
-start
] = '\0';
255 if (!strcmp(str
, temp
))
266 bool settings_load_config(const char* file
, bool apply
)
273 fd
= open(file
, O_RDONLY
);
277 while (read_line(fd
, line
, sizeof line
) > 0)
279 if (!settings_parseline(line
, &name
, &value
))
281 for(i
=0; i
<nb_settings
; i
++)
283 if (settings
[i
].cfg_name
== NULL
)
285 if (!strcasecmp(name
,settings
[i
].cfg_name
))
287 switch (settings
[i
].flags
&F_T_MASK
)
291 #ifdef HAVE_LCD_COLOR
292 if (settings
[i
].flags
&F_RGB
)
293 *(int*)settings
[i
].setting
= hex_to_rgb(value
);
296 if (settings
[i
].cfg_vals
== NULL
)
298 *(int*)settings
[i
].setting
= atoi(value
);
302 int temp
, *v
= (int*)settings
[i
].setting
;
303 bool found
= cfg_string_to_int(i
, &temp
, value
);
306 if (settings
[i
].flags
&F_TABLE_SETTING
)
307 *v
= settings
[i
].table_setting
->values
[temp
];
318 if (cfg_string_to_int(i
,&temp
,value
))
319 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
325 char storage
[MAX_PATH
];
326 if (settings
[i
].filename_setting
->prefix
)
328 int len
= strlen(settings
[i
].filename_setting
->prefix
);
329 if (!strncasecmp(value
,
330 settings
[i
].filename_setting
->prefix
,
333 strncpy(storage
,&value
[len
],MAX_PATH
);
335 else strncpy(storage
,value
,MAX_PATH
);
337 else strncpy(storage
,value
,MAX_PATH
);
338 if (settings
[i
].filename_setting
->suffix
)
340 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
343 strncpy((char*)settings
[i
].setting
,storage
,
344 settings
[i
].filename_setting
->max_len
);
345 ((char*)settings
[i
].setting
)
346 [settings
[i
].filename_setting
->max_len
-1] = '\0';
351 } /* if (!strcmp(name,settings[i].cfg_name)) */
362 /** Writing to a config file and saving settings **/
364 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
366 int flags
= settings
[setting_id
].flags
;
367 const char* start
= settings
[setting_id
].cfg_vals
;
371 if ((flags
&F_T_MASK
)==F_T_INT
&&
372 flags
&F_TABLE_SETTING
)
374 const int *value
= settings
[setting_id
].table_setting
->values
;
377 end
= strchr(start
,',');
378 if (value
[count
] == val
)
381 strncpy(buf
, start
, buf_len
);
384 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
385 strncpy(buf
, start
, len
);
402 start
= strchr(start
,',');
408 end
= strchr(start
,',');
410 strncpy(buf
, start
, buf_len
);
413 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
414 strncpy(buf
, start
, len
);
419 static bool is_changed(int setting_id
)
421 const struct settings_list
*setting
= &settings
[setting_id
];
422 switch (setting
->flags
&F_T_MASK
)
426 if (setting
->flags
&F_DEF_ISFUNC
)
428 if (*(int*)setting
->setting
== setting
->default_val
.func())
431 else if (setting
->flags
&F_T_SOUND
)
433 if (*(int*)setting
->setting
==
434 sound_default(setting
->sound_setting
->setting
))
437 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
441 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
446 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
453 static bool settings_write_config(char* filename
, int options
)
457 char value
[MAX_PATH
];
458 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
461 fdprintf(fd
, "# .cfg file created by rockbox %s - "
462 "http://www.rockbox.org\r\n\r\n", appsversion
);
463 for(i
=0; i
<nb_settings
; i
++)
465 if (settings
[i
].cfg_name
== NULL
)
469 if ((options
== SETTINGS_SAVE_CHANGED
) &&
472 else if ((options
== SETTINGS_SAVE_THEME
) &&
473 ((settings
[i
].flags
&F_THEMESETTING
) == 0))
475 #ifdef HAVE_RECORDING
476 else if ((options
== SETTINGS_SAVE_RECPRESETS
) &&
477 ((settings
[i
].flags
&F_RECSETTING
) == 0))
480 #if CONFIG_CODEC == SWCODEC
481 else if ((options
== SETTINGS_SAVE_EQPRESET
) &&
482 ((settings
[i
].flags
&F_EQSETTING
) == 0))
485 switch (settings
[i
].flags
&F_T_MASK
)
489 #ifdef HAVE_LCD_COLOR
490 if (settings
[i
].flags
&F_RGB
)
492 int colour
= *(int*)settings
[i
].setting
;
493 snprintf(value
,MAX_PATH
,"%02x%02x%02x",
494 (int)RGB_UNPACK_RED(colour
),
495 (int)RGB_UNPACK_GREEN(colour
),
496 (int)RGB_UNPACK_BLUE(colour
));
500 if (settings
[i
].cfg_vals
== NULL
)
502 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
506 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
507 value
, MAX_PATH
) == false)
509 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
515 *(bool*)settings
[i
].setting
==false?0:1, value
, MAX_PATH
);
519 if (((char*)settings
[i
].setting
)[0] == '\0')
521 if (settings
[i
].filename_setting
->prefix
)
523 snprintf(value
,MAX_PATH
,"%s%s%s",
524 settings
[i
].filename_setting
->prefix
,
525 (char*)settings
[i
].setting
,
526 settings
[i
].filename_setting
->suffix
);
528 else strncpy(value
,(char*)settings
[i
].setting
,
529 settings
[i
].filename_setting
->max_len
);
533 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
539 static bool flush_global_status_callback(void)
541 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
544 static bool flush_config_block_callback(void)
547 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
548 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
553 * persist all runtime user settings to disk or RTC RAM
555 static void update_runtime(void)
559 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
560 global_status
.runtime
+= elapsed_secs
;
561 lasttime
+= (elapsed_secs
* HZ
);
563 if ( global_status
.runtime
> global_status
.topruntime
)
564 global_status
.topruntime
= global_status
.runtime
;
567 void status_save( void )
571 /* this will be done in the ata_callback if
572 target doesnt have rtc ram */
573 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
575 register_ata_idle_func(flush_global_status_callback
);
579 int settings_save( void )
583 /* this will be done in the ata_callback if
584 target doesnt have rtc ram */
585 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
587 if(!register_ata_idle_func(flush_config_block_callback
))
592 screens
[i
].clear_display();
593 #ifdef HAVE_LCD_CHARCELLS
594 screens
[i
].puts(0, 0, str(LANG_SETTINGS_SAVE_FAILED
));
595 screens
[i
].puts(0, 1, str(LANG_SETTINGS_PARTITION
));
597 screens
[i
].puts(4, 2, str(LANG_SETTINGS_SAVE_FAILED
));
598 screens
[i
].puts(2, 4, str(LANG_SETTINGS_PARTITION
));
602 cond_talk_ids_fq(LANG_SETTINGS_SAVE_FAILED
);
608 bool settings_save_config(int options
)
610 char filename
[MAX_PATH
];
614 case SETTINGS_SAVE_THEME
:
617 #ifdef HAVE_RECORDING
618 case SETTINGS_SAVE_RECPRESETS
:
619 folder
= RECPRESETS_DIR
;
622 #if CONFIG_CODEC == SWCODEC
623 case SETTINGS_SAVE_EQPRESET
:
628 folder
= ROCKBOX_DIR
;
630 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
631 IF_CNFN_NUM_(, NULL
));
633 /* allow user to modify filename */
635 if (!kbd_input(filename
, sizeof filename
)) {
639 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
644 if (settings_write_config(filename
, options
))
645 gui_syncsplash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
647 gui_syncsplash(HZ
, ID2P(LANG_FAILED
));
651 /** Apply and Reset settings **/
654 #ifdef HAVE_LCD_BITMAP
656 * Applies the range infos stored in global_settings to
659 void settings_apply_pm_range(void)
663 /* depending on the scale mode (dBfs or percent) the values
664 of global_settings.peak_meter_dbfs have different meanings */
665 if (global_settings
.peak_meter_dbfs
)
667 /* convert to dBfs * 100 */
668 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
669 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
673 /* percent is stored directly -> no conversion */
674 pm_min
= global_settings
.peak_meter_min
;
675 pm_max
= global_settings
.peak_meter_max
;
678 /* apply the range */
679 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
681 #endif /* HAVE_LCD_BITMAP */
683 void sound_settings_apply(void)
685 #if CONFIG_CODEC == SWCODEC
686 sound_set_dsp_callback(dsp_callback
);
688 sound_set(SOUND_BASS
, global_settings
.bass
);
689 sound_set(SOUND_TREBLE
, global_settings
.treble
);
690 sound_set(SOUND_BALANCE
, global_settings
.balance
);
691 sound_set(SOUND_VOLUME
, global_settings
.volume
);
692 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
693 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
694 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
695 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
696 sound_set(SOUND_AVC
, global_settings
.avc
);
697 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
698 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
699 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
700 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
701 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
702 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
706 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
707 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
710 #ifdef HAVE_USB_POWER
712 usb_charging_enable(global_settings
.usb_charging
);
717 void settings_apply(void)
720 #if CONFIG_CODEC == SWCODEC
724 DEBUGF( "settings_apply()\n" );
725 sound_settings_apply();
727 #ifndef HAVE_FLASH_STORAGE
728 audio_set_buffer_margin(global_settings
.buffer_margin
);
731 #ifdef HAVE_LCD_CONTRAST
732 lcd_set_contrast(global_settings
.contrast
);
734 lcd_scroll_speed(global_settings
.scroll_speed
);
735 #ifdef HAVE_REMOTE_LCD
736 lcd_remote_set_contrast(global_settings
.remote_contrast
);
737 lcd_remote_set_invert_display(global_settings
.remote_invert
);
738 lcd_remote_set_flip(global_settings
.remote_flip_display
);
739 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
740 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
741 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
742 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
743 #ifdef HAVE_REMOTE_LCD_TICKING
744 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
746 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
748 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
750 #ifdef HAS_REMOTE_BUTTON_HOLD
751 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
753 #endif /* HAVE_REMOTE_LCD */
754 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
755 backlight_set_brightness(global_settings
.brightness
);
757 #ifdef HAVE_BACKLIGHT
758 backlight_set_timeout(global_settings
.backlight_timeout
);
760 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
762 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
763 backlight_set_fade_in(global_settings
.backlight_fade_in
);
764 backlight_set_fade_out(global_settings
.backlight_fade_out
);
767 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
768 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
770 #ifdef HAVE_BUTTON_LIGHT
771 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
773 #ifndef HAVE_FLASH_STORAGE
774 ata_spindown(global_settings
.disk_spindown
);
776 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
777 dac_line_in(global_settings
.line_in
);
779 set_poweroff_timeout(global_settings
.poweroff
);
781 set_battery_capacity(global_settings
.battery_capacity
);
782 #if BATTERY_TYPES_COUNT > 1
783 set_battery_type(global_settings
.battery_type
);
786 #ifdef HAVE_LCD_BITMAP
787 lcd_set_invert_display(global_settings
.invert
);
788 lcd_set_flip(global_settings
.flip_display
);
789 button_set_flip(global_settings
.flip_display
);
790 lcd_update(); /* refresh after flipping the screen */
791 settings_apply_pm_range();
792 peak_meter_init_times(
793 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
794 global_settings
.peak_meter_clip_hold
);
798 unload_wps_backdrop();
800 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
801 unload_remote_wps_backdrop();
803 if ( global_settings
.wps_file
[0] &&
804 global_settings
.wps_file
[0] != 0xff ) {
805 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
806 global_settings
.wps_file
);
807 wps_data_load(gui_wps
[0].data
, buf
, true);
811 wps_data_init(gui_wps
[0].data
);
812 #ifdef HAVE_REMOTE_LCD
813 gui_wps
[0].data
->remote_wps
= false;
818 if ( global_settings
.backdrop_file
[0] &&
819 global_settings
.backdrop_file
[0] != 0xff ) {
820 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
821 global_settings
.backdrop_file
);
822 load_main_backdrop(buf
);
824 unload_main_backdrop();
826 show_main_backdrop();
828 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
829 show_remote_main_backdrop();
832 #ifdef HAVE_LCD_COLOR
833 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
834 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
835 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
836 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
837 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
840 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
841 if ( global_settings
.rwps_file
[0]) {
842 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
843 global_settings
.rwps_file
);
844 wps_data_load(gui_wps
[1].data
, buf
, true);
848 wps_data_init(gui_wps
[1].data
);
849 gui_wps
[1].data
->remote_wps
= true;
853 #ifdef HAVE_LCD_BITMAP
854 if ( global_settings
.font_file
[0]) {
855 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
856 global_settings
.font_file
);
862 if ( global_settings
.kbd_file
[0]) {
863 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
864 global_settings
.kbd_file
);
870 lcd_scroll_step(global_settings
.scroll_step
);
871 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
872 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
874 lcd_jump_scroll(global_settings
.jump_scroll
);
875 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
877 lcd_bidir_scroll(global_settings
.bidir_limit
);
878 lcd_scroll_delay(global_settings
.scroll_delay
);
880 if ( global_settings
.lang_file
[0]) {
881 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
882 global_settings
.lang_file
);
884 talk_init(); /* use voice of same language */
887 set_codepage(global_settings
.default_codepage
);
889 #if CONFIG_CODEC == SWCODEC
890 audio_set_crossfade(global_settings
.crossfade
);
891 dsp_set_replaygain();
892 dsp_set_crossfeed(global_settings
.crossfeed
);
893 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
894 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
895 global_settings
.crossfeed_hf_attenuation
,
896 global_settings
.crossfeed_hf_cutoff
);
898 /* Configure software equalizer, hardware eq is handled in audio_init() */
899 dsp_set_eq(global_settings
.eq_enabled
);
900 dsp_set_eq_precut(global_settings
.eq_precut
);
901 for(i
= 0; i
< 5; i
++) {
905 dsp_dither_enable(global_settings
.dithering_enabled
);
908 #ifdef HAVE_SPDIF_POWER
909 spdif_power_enable(global_settings
.spdif_enable
);
912 #ifdef HAVE_BACKLIGHT
913 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
914 #ifdef HAVE_REMOTE_LCD
915 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
917 #ifdef HAS_BUTTON_HOLD
918 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
920 #ifdef HAVE_LCD_SLEEP
921 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
923 #endif /* HAVE_BACKLIGHT */
925 /* This should stay last */
926 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
927 enc_global_settings_apply();
929 /* load the icon set */
932 #ifdef HAVE_LCD_COLOR
933 if (global_settings
.colors_file
)
934 read_color_theme_file();
941 * reset all settings to their default value
943 void settings_reset(void) {
946 DEBUGF( "settings_reset()\n" );
948 for(i
=0; i
<nb_settings
; i
++)
950 switch (settings
[i
].flags
&F_T_MASK
)
954 if (settings
[i
].flags
&F_DEF_ISFUNC
)
955 *(int*)settings
[i
].setting
= settings
[i
].default_val
.func();
956 else if (settings
[i
].flags
&F_T_SOUND
)
957 *(int*)settings
[i
].setting
=
958 sound_default(settings
[i
].sound_setting
->setting
);
959 else *(int*)settings
[i
].setting
= settings
[i
].default_val
.int_
;
962 *(bool*)settings
[i
].setting
= settings
[i
].default_val
.bool_
;
966 strncpy((char*)settings
[i
].setting
,
967 settings
[i
].default_val
.charptr
,MAX_FILENAME
);
971 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
972 enc_global_settings_reset();
976 /** Changing setting values **/
977 const struct settings_list
* find_setting(void* variable
, int *id
)
980 for(i
=0;i
<nb_settings
;i
++)
982 if (settings
[i
].setting
== variable
)
992 void talk_setting(void *global_settings_variable
)
994 const struct settings_list
*setting
;
995 if (!global_settings
.talk_menu
)
997 setting
= find_setting(global_settings_variable
, NULL
);
1000 if (setting
->lang_id
)
1001 talk_id(setting
->lang_id
,false);
1004 bool set_bool(const char* string
, bool* variable
)
1006 return set_bool_options(string
, variable
,
1007 (char *)STR(LANG_SET_BOOL_YES
),
1008 (char *)STR(LANG_SET_BOOL_NO
),
1013 bool set_bool_options(const char* string
, bool* variable
,
1014 const char* yes_str
, int yes_voice
,
1015 const char* no_str
, int no_voice
,
1016 void (*function
)(bool))
1018 struct opt_items names
[] = {
1019 {(unsigned char *)no_str
, no_voice
},
1020 {(unsigned char *)yes_str
, yes_voice
}
1024 result
= set_option(string
, variable
, BOOL
, names
, 2,
1025 (void (*)(int))function
);
1029 bool set_int(const unsigned char* string
,
1033 void (*function
)(int),
1037 void (*formatter
)(char*, size_t, int, const char*) )
1039 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1040 step
, min
, max
, formatter
, NULL
);
1044 /** extra stuff which is probably misplaced **/
1046 void set_file(char* filename
, char* setting
, int maxlen
)
1048 char* fptr
= strrchr(filename
,'/');
1061 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1065 if(ptr
== fptr
) extlen
= 0;
1067 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1068 (len
-extlen
> maxlen
))
1071 strncpy(setting
, fptr
, len
-extlen
);
1072 setting
[len
-extlen
]=0;