1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Stuart Martin
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"
65 #include "option_select.h"
72 #if CONFIG_CODEC == MAS3507D
73 void dac_line_in(bool enable
);
75 struct user_settings global_settings
;
76 struct system_status global_status
;
78 #if CONFIG_CODEC == SWCODEC
82 #include "enc_config.h"
84 #endif /* CONFIG_CODEC == SWCODEC */
86 #define NVRAM_BLOCK_SIZE 44
88 #ifdef HAVE_LCD_BITMAP
94 #ifdef HAVE_REMOTE_LCD
95 #include "lcd-remote.h"
100 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
101 /* NVRAM is set out as
105 [3] stored variable count
107 [8-NVRAM_BLOCK_SIZE] data
109 #define NVRAM_DATA_START 8
110 #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
111 static char nvram_buffer
[NVRAM_BLOCK_SIZE
];
113 static bool read_nvram_data(char* buf
, int max_len
)
115 unsigned crc32
= 0xffffffff;
116 int var_count
= 0, i
= 0, buf_pos
= 0;
118 int fd
= open(NVRAM_FILE
,O_RDONLY
);
121 memset(buf
,0,max_len
);
122 if (read(fd
,buf
,max_len
) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
126 memset(buf
,0,max_len
);
128 for (i
=0; i
< max_len
; i
++ )
129 buf
[i
] = rtc_read(0x14+i
);
131 /* check magic, version */
132 if ((buf
[0] != 'R') || (buf
[1] != 'b')
133 || (buf
[2] != NVRAM_CONFIG_VERSION
))
136 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
137 max_len
-NVRAM_DATA_START
-1,0xffffffff);
138 if (memcmp(&crc32
,&buf
[4],4))
140 /* all good, so read in the settings */
142 buf_pos
= NVRAM_DATA_START
;
143 for(i
=0; i
<nb_settings
; i
++)
145 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
146 >>F_NVRAM_MASK_SHIFT
;
149 if ((var_count
>0) && (buf_pos
<max_len
))
151 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
152 buf_pos
+= nvram_bytes
;
155 else /* should only happen when new items are added to the end */
157 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
163 static bool write_nvram_data(char* buf
, int max_len
)
165 unsigned crc32
= 0xffffffff;
166 int i
= 0, buf_pos
= 0;
171 memset(buf
,0,max_len
);
173 buf
[0] = 'R'; buf
[1] = 'b';
174 buf
[2] = NVRAM_CONFIG_VERSION
;
175 buf_pos
= NVRAM_DATA_START
;
176 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
178 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
179 >>F_NVRAM_MASK_SHIFT
;
182 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
183 buf_pos
+= nvram_bytes
;
187 /* count and crc32 */
189 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
190 max_len
-NVRAM_DATA_START
-1,0xffffffff);
191 memcpy(&buf
[4],&crc32
,4);
193 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
);
196 int len
= write(fd
,buf
,max_len
);
202 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
203 that it would write a number of bytes at a time since the RTC chip
204 supports that, but this will have to do for now 8-) */
205 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
206 int r
= rtc_write(0x14+i
, buf
[i
]);
214 /** Reading from a config file **/
216 * load settings from disk or RTC RAM
218 void settings_load(int which
)
220 if (which
&SETTINGS_RTC
)
221 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
222 if (which
&SETTINGS_HD
)
224 settings_load_config(CONFIGFILE
,false);
225 settings_load_config(FIXEDSETTINGSFILE
,false);
229 static bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
231 const char* start
= settings
[setting_id
].cfg_vals
;
237 end
= strchr(start
, ',');
240 if (!strcmp(str
, start
))
247 strncpy(temp
, start
, end
-start
);
248 temp
[end
-start
] = '\0';
249 if (!strcmp(str
, temp
))
260 bool settings_load_config(const char* file
, bool apply
)
267 fd
= open(file
, O_RDONLY
);
271 while (read_line(fd
, line
, sizeof line
) > 0)
273 if (!settings_parseline(line
, &name
, &value
))
275 for(i
=0; i
<nb_settings
; i
++)
277 if (settings
[i
].cfg_name
== NULL
)
279 if (!strcasecmp(name
,settings
[i
].cfg_name
))
281 switch (settings
[i
].flags
&F_T_MASK
)
285 #ifdef HAVE_LCD_COLOR
286 if (settings
[i
].flags
&F_RGB
)
287 hex_to_rgb(value
, (int*)settings
[i
].setting
);
290 if (settings
[i
].cfg_vals
== NULL
)
292 *(int*)settings
[i
].setting
= atoi(value
);
296 int temp
, *v
= (int*)settings
[i
].setting
;
297 bool found
= cfg_string_to_int(i
, &temp
, value
);
300 if (settings
[i
].flags
&F_TABLE_SETTING
)
301 *v
= settings
[i
].table_setting
->values
[temp
];
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)) */
352 settings_apply(true);
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 int flags
= settings
[setting_id
].flags
;
361 const char* start
= settings
[setting_id
].cfg_vals
;
365 if ((flags
&F_T_MASK
)==F_T_INT
&&
366 flags
&F_TABLE_SETTING
)
368 const int *value
= settings
[setting_id
].table_setting
->values
;
371 end
= strchr(start
,',');
372 if (value
[count
] == val
)
375 strncpy(buf
, start
, buf_len
);
378 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
379 strncpy(buf
, start
, len
);
396 start
= strchr(start
,',');
402 end
= strchr(start
,',');
404 strncpy(buf
, start
, buf_len
);
407 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
408 strncpy(buf
, start
, len
);
415 static bool is_changed(int setting_id
)
417 const struct settings_list
*setting
= &settings
[setting_id
];
418 switch (setting
->flags
&F_T_MASK
)
422 if (setting
->flags
&F_DEF_ISFUNC
)
424 if (*(int*)setting
->setting
== setting
->default_val
.func())
427 else if (setting
->flags
&F_T_SOUND
)
429 if (*(int*)setting
->setting
==
430 sound_default(setting
->sound_setting
->setting
))
433 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
437 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
442 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
449 static bool settings_write_config(const char* filename
, int options
)
453 char value
[MAX_PATH
];
454 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
458 bool statusbar
= global_settings
.statusbar
;
459 if (global_status
.statusbar_forced
!= 0 && statusbar
)
460 global_settings
.statusbar
= false;
462 fdprintf(fd
, "# .cfg file created by rockbox %s - "
463 "http://www.rockbox.org\r\n\r\n", appsversion
);
464 for(i
=0; i
<nb_settings
; i
++)
466 if (settings
[i
].cfg_name
== NULL
)
472 case SETTINGS_SAVE_CHANGED
:
476 case SETTINGS_SAVE_SOUND
:
477 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
480 case SETTINGS_SAVE_THEME
:
481 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
484 #ifdef HAVE_RECORDING
485 case SETTINGS_SAVE_RECPRESETS
:
486 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
490 #if CONFIG_CODEC == SWCODEC
491 case SETTINGS_SAVE_EQPRESET
:
492 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
497 switch (settings
[i
].flags
&F_T_MASK
)
501 #ifdef HAVE_LCD_COLOR
502 if (settings
[i
].flags
&F_RGB
)
504 int colour
= *(int*)settings
[i
].setting
;
505 snprintf(value
,MAX_PATH
,"%02x%02x%02x",
506 (int)RGB_UNPACK_RED(colour
),
507 (int)RGB_UNPACK_GREEN(colour
),
508 (int)RGB_UNPACK_BLUE(colour
));
512 if (settings
[i
].cfg_vals
== NULL
)
514 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
518 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
519 value
, MAX_PATH
) == false)
521 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
527 *(bool*)settings
[i
].setting
==false?0:1, value
, MAX_PATH
);
531 if (((char*)settings
[i
].setting
)[0]
532 && settings
[i
].filename_setting
->prefix
)
534 snprintf(value
,MAX_PATH
,"%s%s%s",
535 settings
[i
].filename_setting
->prefix
,
536 (char*)settings
[i
].setting
,
537 settings
[i
].filename_setting
->suffix
);
539 else strncpy(value
,(char*)settings
[i
].setting
,
540 settings
[i
].filename_setting
->max_len
);
543 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
547 global_settings
.statusbar
= statusbar
;
552 static bool flush_global_status_callback(void)
554 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
557 static bool flush_config_block_callback(void)
560 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
561 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
566 * persist all runtime user settings to disk or RTC RAM
568 static void update_runtime(void)
572 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
573 global_status
.runtime
+= elapsed_secs
;
574 lasttime
+= (elapsed_secs
* HZ
);
576 if ( global_status
.runtime
> global_status
.topruntime
)
577 global_status
.topruntime
= global_status
.runtime
;
580 void status_save(void)
584 /* this will be done in the ata_callback if
585 target doesnt have rtc ram */
586 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
588 register_ata_idle_func(flush_global_status_callback
);
592 int settings_save(void)
596 /* this will be done in the ata_callback if
597 target doesnt have rtc ram */
598 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
600 register_ata_idle_func(flush_config_block_callback
);
604 bool settings_save_config(int options
)
606 char filename
[MAX_PATH
];
610 case SETTINGS_SAVE_THEME
:
613 #ifdef HAVE_RECORDING
614 case SETTINGS_SAVE_RECPRESETS
:
615 folder
= RECPRESETS_DIR
;
618 #if CONFIG_CODEC == SWCODEC
619 case SETTINGS_SAVE_EQPRESET
:
623 case SETTINGS_SAVE_SOUND
:
625 folder
= ROCKBOX_DIR
;
627 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
628 IF_CNFN_NUM_(, NULL
));
630 /* allow user to modify filename */
632 if (!kbd_input(filename
, sizeof filename
)) {
636 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
641 if (settings_write_config(filename
, options
))
642 gui_syncsplash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
644 gui_syncsplash(HZ
, ID2P(LANG_FAILED
));
648 /** Apply and Reset settings **/
651 #ifdef HAVE_LCD_BITMAP
653 * Applies the range infos stored in global_settings to
656 void settings_apply_pm_range(void)
660 /* depending on the scale mode (dBfs or percent) the values
661 of global_settings.peak_meter_dbfs have different meanings */
662 if (global_settings
.peak_meter_dbfs
)
664 /* convert to dBfs * 100 */
665 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
666 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
670 /* percent is stored directly -> no conversion */
671 pm_min
= global_settings
.peak_meter_min
;
672 pm_max
= global_settings
.peak_meter_max
;
675 /* apply the range */
676 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
678 #endif /* HAVE_LCD_BITMAP */
680 void sound_settings_apply(void)
682 #if CONFIG_CODEC == SWCODEC
683 sound_set_dsp_callback(dsp_callback
);
685 sound_set(SOUND_BASS
, global_settings
.bass
);
686 sound_set(SOUND_TREBLE
, global_settings
.treble
);
687 sound_set(SOUND_BALANCE
, global_settings
.balance
);
688 sound_set(SOUND_VOLUME
, global_settings
.volume
);
689 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
690 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
691 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
692 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
693 sound_set(SOUND_AVC
, global_settings
.avc
);
694 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
695 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
696 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
697 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
698 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
699 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
703 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
704 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
707 #ifdef HAVE_USB_POWER
709 usb_charging_enable(global_settings
.usb_charging
);
714 void settings_apply(bool read_disk
)
717 #if CONFIG_CODEC == SWCODEC
721 sound_settings_apply();
723 #ifndef HAVE_FLASH_STORAGE
724 audio_set_buffer_margin(global_settings
.buffer_margin
);
727 #ifdef HAVE_LCD_CONTRAST
728 lcd_set_contrast(global_settings
.contrast
);
730 lcd_scroll_speed(global_settings
.scroll_speed
);
731 #ifdef HAVE_REMOTE_LCD
732 lcd_remote_set_contrast(global_settings
.remote_contrast
);
733 lcd_remote_set_invert_display(global_settings
.remote_invert
);
734 lcd_remote_set_flip(global_settings
.remote_flip_display
);
735 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
736 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
737 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
738 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
739 #ifdef HAVE_REMOTE_LCD_TICKING
740 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
742 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
744 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
746 #ifdef HAS_REMOTE_BUTTON_HOLD
747 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
749 #endif /* HAVE_REMOTE_LCD */
750 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
751 backlight_set_brightness(global_settings
.brightness
);
753 #ifdef HAVE_BACKLIGHT
754 backlight_set_timeout(global_settings
.backlight_timeout
);
756 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
758 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
759 backlight_set_fade_in(global_settings
.backlight_fade_in
);
760 backlight_set_fade_out(global_settings
.backlight_fade_out
);
763 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
764 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
766 #ifdef HAVE_BUTTON_LIGHT
767 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
769 #ifndef HAVE_FLASH_STORAGE
770 ata_spindown(global_settings
.disk_spindown
);
772 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
773 dac_line_in(global_settings
.line_in
);
775 set_poweroff_timeout(global_settings
.poweroff
);
777 set_battery_capacity(global_settings
.battery_capacity
);
778 #if BATTERY_TYPES_COUNT > 1
779 set_battery_type(global_settings
.battery_type
);
782 #ifdef HAVE_LCD_BITMAP
783 lcd_set_invert_display(global_settings
.invert
);
784 lcd_set_flip(global_settings
.flip_display
);
785 button_set_flip(global_settings
.flip_display
);
786 lcd_update(); /* refresh after flipping the screen */
787 settings_apply_pm_range();
788 peak_meter_init_times(
789 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
790 global_settings
.peak_meter_clip_hold
);
796 unload_wps_backdrop();
798 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
799 unload_remote_wps_backdrop();
801 if ( global_settings
.wps_file
[0] &&
802 global_settings
.wps_file
[0] != 0xff ) {
803 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
804 global_settings
.wps_file
);
805 wps_data_load(gui_wps
[0].data
, &screens
[0], buf
, true);
809 wps_data_init(gui_wps
[0].data
);
810 #ifdef HAVE_REMOTE_LCD
811 gui_wps
[0].data
->remote_wps
= false;
816 if ( global_settings
.backdrop_file
[0] &&
817 global_settings
.backdrop_file
[0] != 0xff ) {
818 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
819 global_settings
.backdrop_file
);
820 load_main_backdrop(buf
);
822 unload_main_backdrop();
824 show_main_backdrop();
826 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
827 show_remote_main_backdrop();
830 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
831 if ( global_settings
.rwps_file
[0]) {
832 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
833 global_settings
.rwps_file
);
834 wps_data_load(gui_wps
[1].data
, &screens
[1], buf
, true);
838 wps_data_init(gui_wps
[1].data
);
839 gui_wps
[1].data
->remote_wps
= true;
843 #ifdef HAVE_LCD_BITMAP
844 if ( global_settings
.font_file
[0]) {
845 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
846 global_settings
.font_file
);
852 if ( global_settings
.kbd_file
[0]) {
853 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
854 global_settings
.kbd_file
);
860 if ( global_settings
.lang_file
[0]) {
861 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
862 global_settings
.lang_file
);
864 talk_init(); /* use voice of same language */
866 /* load the icon set */
869 #ifdef HAVE_LCD_COLOR
870 if (global_settings
.colors_file
[0])
871 read_color_theme_file();
875 #ifdef HAVE_LCD_COLOR
876 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
877 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
878 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
879 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
880 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
883 #ifdef HAVE_LCD_BITMAP
884 lcd_scroll_step(global_settings
.scroll_step
);
885 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
886 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
888 lcd_jump_scroll(global_settings
.jump_scroll
);
889 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
891 lcd_bidir_scroll(global_settings
.bidir_limit
);
892 lcd_scroll_delay(global_settings
.scroll_delay
);
895 set_codepage(global_settings
.default_codepage
);
897 #if CONFIG_CODEC == SWCODEC
898 audio_set_crossfade(global_settings
.crossfade
);
899 dsp_set_replaygain();
900 dsp_set_crossfeed(global_settings
.crossfeed
);
901 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
902 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
903 global_settings
.crossfeed_hf_attenuation
,
904 global_settings
.crossfeed_hf_cutoff
);
906 /* Configure software equalizer, hardware eq is handled in audio_init() */
907 dsp_set_eq(global_settings
.eq_enabled
);
908 dsp_set_eq_precut(global_settings
.eq_precut
);
909 for(i
= 0; i
< 5; i
++) {
913 dsp_dither_enable(global_settings
.dithering_enabled
);
916 #ifdef HAVE_SPDIF_POWER
917 spdif_power_enable(global_settings
.spdif_enable
);
920 #ifdef HAVE_BACKLIGHT
921 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
922 #ifdef HAVE_REMOTE_LCD
923 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
925 #ifdef HAS_BUTTON_HOLD
926 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
928 #ifdef HAVE_LCD_SLEEP
929 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
931 #endif /* HAVE_BACKLIGHT */
933 /* This should stay last */
934 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
935 enc_global_settings_apply();
937 list_init_viewports(NULL
);
942 * reset all settings to their default value
944 void reset_setting(const struct settings_list
*setting
, void *var
)
946 switch (setting
->flags
&F_T_MASK
)
950 if (setting
->flags
&F_DEF_ISFUNC
)
951 *(int*)var
= setting
->default_val
.func();
952 else if (setting
->flags
&F_T_SOUND
)
953 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
954 else *(int*)var
= setting
->default_val
.int_
;
957 *(bool*)var
= setting
->default_val
.bool_
;
961 strncpy((char*)var
, setting
->default_val
.charptr
,
962 setting
->filename_setting
->max_len
);
967 void settings_reset(void)
971 for(i
=0; i
<nb_settings
; i
++)
972 reset_setting(&settings
[i
], settings
[i
].setting
);
973 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
974 enc_global_settings_reset();
978 /** Changing setting values **/
979 const struct settings_list
* find_setting(const void* variable
, int *id
)
982 for(i
=0;i
<nb_settings
;i
++)
984 if (settings
[i
].setting
== variable
)
994 bool set_bool(const char* string
, const bool* variable
)
996 return set_bool_options(string
, variable
,
997 (char *)STR(LANG_SET_BOOL_YES
),
998 (char *)STR(LANG_SET_BOOL_NO
),
1003 bool set_bool_options(const char* string
, const bool* variable
,
1004 const char* yes_str
, int yes_voice
,
1005 const char* no_str
, int no_voice
,
1006 void (*function
)(bool))
1008 struct opt_items names
[] = {
1009 {(unsigned const char *)no_str
, no_voice
},
1010 {(unsigned const char *)yes_str
, yes_voice
}
1014 result
= set_option(string
, variable
, BOOL
, names
, 2,
1015 (void (*)(int))function
);
1019 bool set_int(const unsigned char* string
,
1022 const int* variable
,
1023 void (*function
)(int),
1027 void (*formatter
)(char*, size_t, int, const char*) )
1029 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1030 step
, min
, max
, formatter
, NULL
);
1033 bool set_int_ex(const unsigned char* string
,
1036 const int* variable
,
1037 void (*function
)(int),
1041 void (*formatter
)(char*, size_t, int, const char*),
1042 int32_t (*get_talk_id
)(int, int))
1045 struct settings_list item
;
1046 struct int_setting data
= {
1047 function
, voice_unit
, min
, max
, step
,
1048 formatter
, get_talk_id
1050 item
.int_setting
= &data
;
1051 item
.flags
= F_INT_SETTING
|F_T_INT
;
1053 item
.cfg_vals
= (char*)string
;
1054 item
.setting
= (void *)variable
;
1055 return option_screen(&item
, false, NULL
);
1059 static const struct opt_items
*set_option_options
;
1060 static void set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1063 const unsigned char *text
= set_option_options
[item
].string
;
1064 snprintf(buf
, size
, "%s", P2STR(text
));
1066 static int32_t set_option_get_talk_id(int value
, int unit
)
1069 return set_option_options
[value
].voice_id
;
1071 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1072 const struct opt_items
* options
,
1073 int numoptions
, void (*function
)(int))
1076 struct settings_list item
;
1077 struct int_setting data
= {
1078 function
, UNIT_INT
, 0, numoptions
-1, 1,
1079 set_option_formatter
, set_option_get_talk_id
1081 set_option_options
= options
;
1082 item
.int_setting
= &data
;
1083 item
.flags
= F_INT_SETTING
|F_T_INT
;
1085 item
.cfg_vals
= (char*)string
;
1086 item
.setting
= &temp
;
1088 temp
= *(bool*)variable
? 1: 0;
1090 temp
= *(int*)variable
;
1091 if (!option_screen(&item
, false, NULL
))
1094 *(bool*)variable
= (temp
== 1? true: false);
1096 *(int*)variable
= temp
;
1103 void set_file(const char* filename
, char* setting
, int maxlen
)
1105 char* fptr
= strrchr(filename
,'/');
1118 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1122 if(ptr
== fptr
) extlen
= 0;
1124 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1125 (len
-extlen
> maxlen
))
1128 strncpy(setting
, fptr
, len
-extlen
);
1129 setting
[len
-extlen
]=0;