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 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
33 #include "backlight.h"
40 #include "ata_idle_notify.h"
46 #ifdef HAVE_LCD_BITMAP
49 #include "peakmeter.h"
54 #include "powermgmt.h"
59 #include "rbunicode.h"
61 #include "statusbar.h"
64 #include "settings_list.h"
65 #include "filetypes.h"
66 #include "option_select.h"
73 #if CONFIG_CODEC == MAS3507D
74 void dac_line_in(bool enable
);
76 struct user_settings global_settings
;
77 struct system_status global_status
;
79 #if CONFIG_CODEC == SWCODEC
83 #include "enc_config.h"
85 #endif /* CONFIG_CODEC == SWCODEC */
87 #define NVRAM_BLOCK_SIZE 44
89 #ifdef HAVE_LCD_BITMAP
95 #ifdef HAVE_REMOTE_LCD
96 #include "lcd-remote.h"
101 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
102 /* NVRAM is set out as
106 [3] stored variable count
108 [8-NVRAM_BLOCK_SIZE] data
110 #define NVRAM_DATA_START 8
111 #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
112 static char nvram_buffer
[NVRAM_BLOCK_SIZE
];
114 static bool read_nvram_data(char* buf
, int max_len
)
116 unsigned crc32
= 0xffffffff;
117 int var_count
= 0, i
= 0, buf_pos
= 0;
119 int fd
= open(NVRAM_FILE
,O_RDONLY
);
122 memset(buf
,0,max_len
);
123 if (read(fd
,buf
,max_len
) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
127 memset(buf
,0,max_len
);
129 for (i
=0; i
< max_len
; i
++ )
130 buf
[i
] = rtc_read(0x14+i
);
132 /* check magic, version */
133 if ((buf
[0] != 'R') || (buf
[1] != 'b')
134 || (buf
[2] != NVRAM_CONFIG_VERSION
))
137 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
138 max_len
-NVRAM_DATA_START
-1,0xffffffff);
139 if (memcmp(&crc32
,&buf
[4],4))
141 /* all good, so read in the settings */
143 buf_pos
= NVRAM_DATA_START
;
144 for(i
=0; i
<nb_settings
; i
++)
146 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
147 >>F_NVRAM_MASK_SHIFT
;
150 if ((var_count
>0) && (buf_pos
<max_len
))
152 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
153 buf_pos
+= nvram_bytes
;
156 else /* should only happen when new items are added to the end */
158 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
164 static bool write_nvram_data(char* buf
, int max_len
)
166 unsigned crc32
= 0xffffffff;
167 int i
= 0, buf_pos
= 0;
172 memset(buf
,0,max_len
);
174 buf
[0] = 'R'; buf
[1] = 'b';
175 buf
[2] = NVRAM_CONFIG_VERSION
;
176 buf_pos
= NVRAM_DATA_START
;
177 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
179 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
180 >>F_NVRAM_MASK_SHIFT
;
183 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
184 buf_pos
+= nvram_bytes
;
188 /* count and crc32 */
190 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
191 max_len
-NVRAM_DATA_START
-1,0xffffffff);
192 memcpy(&buf
[4],&crc32
,4);
194 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
);
197 int len
= write(fd
,buf
,max_len
);
203 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
204 that it would write a number of bytes at a time since the RTC chip
205 supports that, but this will have to do for now 8-) */
206 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
207 int r
= rtc_write(0x14+i
, buf
[i
]);
215 /** Reading from a config file **/
217 * load settings from disk or RTC RAM
219 void settings_load(int which
)
221 if (which
&SETTINGS_RTC
)
222 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
223 if (which
&SETTINGS_HD
)
225 settings_load_config(CONFIGFILE
,false);
226 settings_load_config(FIXEDSETTINGSFILE
,false);
230 static bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
232 const char* start
= settings
[setting_id
].cfg_vals
;
238 end
= strchr(start
, ',');
241 if (!strcmp(str
, start
))
248 strncpy(temp
, start
, end
-start
);
249 temp
[end
-start
] = '\0';
250 if (!strcmp(str
, temp
))
261 bool settings_load_config(const char* file
, bool apply
)
268 fd
= open_utf8(file
, O_RDONLY
);
272 while (read_line(fd
, line
, sizeof line
) > 0)
274 if (!settings_parseline(line
, &name
, &value
))
276 for(i
=0; i
<nb_settings
; i
++)
278 if (settings
[i
].cfg_name
== NULL
)
280 if (!strcasecmp(name
,settings
[i
].cfg_name
))
282 switch (settings
[i
].flags
&F_T_MASK
)
286 #ifdef HAVE_LCD_COLOR
287 if (settings
[i
].flags
&F_RGB
)
288 hex_to_rgb(value
, (int*)settings
[i
].setting
);
291 if (settings
[i
].cfg_vals
== NULL
)
293 *(int*)settings
[i
].setting
= atoi(value
);
297 int temp
, *v
= (int*)settings
[i
].setting
;
298 bool found
= cfg_string_to_int(i
, &temp
, value
);
301 if (settings
[i
].flags
&F_TABLE_SETTING
)
302 *v
= settings
[i
].table_setting
->values
[temp
];
313 if (cfg_string_to_int(i
,&temp
,value
))
314 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
320 char storage
[MAX_PATH
];
321 if (settings
[i
].filename_setting
->prefix
)
323 int len
= strlen(settings
[i
].filename_setting
->prefix
);
324 if (!strncasecmp(value
,
325 settings
[i
].filename_setting
->prefix
,
328 strncpy(storage
,&value
[len
],MAX_PATH
);
330 else strncpy(storage
,value
,MAX_PATH
);
332 else strncpy(storage
,value
,MAX_PATH
);
333 if (settings
[i
].filename_setting
->suffix
)
335 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
338 strncpy((char*)settings
[i
].setting
,storage
,
339 settings
[i
].filename_setting
->max_len
);
340 ((char*)settings
[i
].setting
)
341 [settings
[i
].filename_setting
->max_len
-1] = '\0';
346 } /* if (!strcmp(name,settings[i].cfg_name)) */
353 settings_apply(true);
357 /** Writing to a config file and saving settings **/
359 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
361 int flags
= settings
[setting_id
].flags
;
362 const char* start
= settings
[setting_id
].cfg_vals
;
366 if ((flags
&F_T_MASK
)==F_T_INT
&&
367 flags
&F_TABLE_SETTING
)
369 const int *value
= settings
[setting_id
].table_setting
->values
;
372 end
= strchr(start
,',');
373 if (value
[count
] == val
)
376 strncpy(buf
, start
, buf_len
);
379 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
380 strncpy(buf
, start
, len
);
397 start
= strchr(start
,',');
403 end
= strchr(start
,',');
405 strncpy(buf
, start
, buf_len
);
408 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
409 strncpy(buf
, start
, len
);
416 static bool is_changed(int setting_id
)
418 const struct settings_list
*setting
= &settings
[setting_id
];
419 switch (setting
->flags
&F_T_MASK
)
423 if (setting
->flags
&F_DEF_ISFUNC
)
425 if (*(int*)setting
->setting
== setting
->default_val
.func())
428 else if (setting
->flags
&F_T_SOUND
)
430 if (*(int*)setting
->setting
==
431 sound_default(setting
->sound_setting
->setting
))
434 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
438 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
443 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
450 static bool settings_write_config(const char* filename
, int options
)
454 char value
[MAX_PATH
];
455 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
459 bool statusbar
= global_settings
.statusbar
;
460 if (global_status
.statusbar_forced
!= 0 && statusbar
)
461 global_settings
.statusbar
= false;
463 fdprintf(fd
, "# .cfg file created by rockbox %s - "
464 "http://www.rockbox.org\r\n\r\n", appsversion
);
465 for(i
=0; i
<nb_settings
; i
++)
467 if (settings
[i
].cfg_name
== NULL
)
473 case SETTINGS_SAVE_CHANGED
:
477 case SETTINGS_SAVE_SOUND
:
478 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
481 case SETTINGS_SAVE_THEME
:
482 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
485 #ifdef HAVE_RECORDING
486 case SETTINGS_SAVE_RECPRESETS
:
487 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
491 #if CONFIG_CODEC == SWCODEC
492 case SETTINGS_SAVE_EQPRESET
:
493 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
498 switch (settings
[i
].flags
&F_T_MASK
)
502 #ifdef HAVE_LCD_COLOR
503 if (settings
[i
].flags
&F_RGB
)
505 int colour
= *(int*)settings
[i
].setting
;
506 snprintf(value
,MAX_PATH
,"%02x%02x%02x",
507 (int)RGB_UNPACK_RED(colour
),
508 (int)RGB_UNPACK_GREEN(colour
),
509 (int)RGB_UNPACK_BLUE(colour
));
513 if (settings
[i
].cfg_vals
== NULL
)
515 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
519 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
520 value
, MAX_PATH
) == false)
522 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
528 *(bool*)settings
[i
].setting
==false?0:1, value
, MAX_PATH
);
532 if (((char*)settings
[i
].setting
)[0]
533 && settings
[i
].filename_setting
->prefix
)
535 snprintf(value
,MAX_PATH
,"%s%s%s",
536 settings
[i
].filename_setting
->prefix
,
537 (char*)settings
[i
].setting
,
538 settings
[i
].filename_setting
->suffix
);
540 else strncpy(value
,(char*)settings
[i
].setting
,
541 settings
[i
].filename_setting
->max_len
);
544 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
548 global_settings
.statusbar
= statusbar
;
553 static bool flush_global_status_callback(void)
555 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
558 static bool flush_config_block_callback(void)
561 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
562 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
567 * persist all runtime user settings to disk or RTC RAM
569 static void update_runtime(void)
573 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
574 global_status
.runtime
+= elapsed_secs
;
575 lasttime
+= (elapsed_secs
* HZ
);
577 if ( global_status
.runtime
> global_status
.topruntime
)
578 global_status
.topruntime
= global_status
.runtime
;
581 void status_save(void)
585 /* this will be done in the ata_callback if
586 target doesnt have rtc ram */
587 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
589 register_ata_idle_func(flush_global_status_callback
);
593 int settings_save(void)
597 /* this will be done in the ata_callback if
598 target doesnt have rtc ram */
599 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
601 register_ata_idle_func(flush_config_block_callback
);
605 bool settings_save_config(int options
)
607 char filename
[MAX_PATH
];
611 case SETTINGS_SAVE_THEME
:
614 #ifdef HAVE_RECORDING
615 case SETTINGS_SAVE_RECPRESETS
:
616 folder
= RECPRESETS_DIR
;
619 #if CONFIG_CODEC == SWCODEC
620 case SETTINGS_SAVE_EQPRESET
:
624 case SETTINGS_SAVE_SOUND
:
626 folder
= ROCKBOX_DIR
;
628 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
629 IF_CNFN_NUM_(, NULL
));
631 /* allow user to modify filename */
633 if (!kbd_input(filename
, sizeof filename
)) {
637 splash(HZ
, ID2P(LANG_CANCEL
));
642 if (settings_write_config(filename
, options
))
643 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
645 splash(HZ
, ID2P(LANG_FAILED
));
649 /** Apply and Reset settings **/
652 #ifdef HAVE_LCD_BITMAP
654 * Applies the range infos stored in global_settings to
657 void settings_apply_pm_range(void)
661 /* depending on the scale mode (dBfs or percent) the values
662 of global_settings.peak_meter_dbfs have different meanings */
663 if (global_settings
.peak_meter_dbfs
)
665 /* convert to dBfs * 100 */
666 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
667 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
671 /* percent is stored directly -> no conversion */
672 pm_min
= global_settings
.peak_meter_min
;
673 pm_max
= global_settings
.peak_meter_max
;
676 /* apply the range */
677 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
679 #endif /* HAVE_LCD_BITMAP */
681 void sound_settings_apply(void)
683 #if CONFIG_CODEC == SWCODEC
684 sound_set_dsp_callback(dsp_callback
);
686 sound_set(SOUND_BASS
, global_settings
.bass
);
687 sound_set(SOUND_TREBLE
, global_settings
.treble
);
688 sound_set(SOUND_BALANCE
, global_settings
.balance
);
689 sound_set(SOUND_VOLUME
, global_settings
.volume
);
690 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
691 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
692 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
693 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
694 sound_set(SOUND_AVC
, global_settings
.avc
);
695 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
696 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
697 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
698 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
699 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
700 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
704 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
705 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
708 #ifdef HAVE_USB_POWER
710 usb_charging_enable(global_settings
.usb_charging
);
715 void settings_apply(bool read_disk
)
718 #if CONFIG_CODEC == SWCODEC
722 sound_settings_apply();
724 #ifndef HAVE_FLASH_STORAGE
725 audio_set_buffer_margin(global_settings
.buffer_margin
);
728 #ifdef HAVE_LCD_CONTRAST
729 lcd_set_contrast(global_settings
.contrast
);
731 lcd_scroll_speed(global_settings
.scroll_speed
);
732 #ifdef HAVE_REMOTE_LCD
733 lcd_remote_set_contrast(global_settings
.remote_contrast
);
734 lcd_remote_set_invert_display(global_settings
.remote_invert
);
735 lcd_remote_set_flip(global_settings
.remote_flip_display
);
736 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
737 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
738 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
739 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
740 #ifdef HAVE_REMOTE_LCD_TICKING
741 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
743 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
745 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
747 #ifdef HAS_REMOTE_BUTTON_HOLD
748 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
750 #endif /* HAVE_REMOTE_LCD */
751 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
752 backlight_set_brightness(global_settings
.brightness
);
754 #ifdef HAVE_BACKLIGHT
755 backlight_set_timeout(global_settings
.backlight_timeout
);
757 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
759 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
760 backlight_set_fade_in(global_settings
.backlight_fade_in
);
761 backlight_set_fade_out(global_settings
.backlight_fade_out
);
764 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
765 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
767 #ifdef HAVE_BUTTON_LIGHT
768 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
770 #ifndef HAVE_FLASH_STORAGE
771 ata_spindown(global_settings
.disk_spindown
);
773 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
774 dac_line_in(global_settings
.line_in
);
776 set_poweroff_timeout(global_settings
.poweroff
);
778 set_battery_capacity(global_settings
.battery_capacity
);
779 #if BATTERY_TYPES_COUNT > 1
780 set_battery_type(global_settings
.battery_type
);
783 #ifdef HAVE_LCD_BITMAP
784 lcd_set_invert_display(global_settings
.invert
);
785 lcd_set_flip(global_settings
.flip_display
);
786 button_set_flip(global_settings
.flip_display
);
787 lcd_update(); /* refresh after flipping the screen */
788 settings_apply_pm_range();
789 peak_meter_init_times(
790 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
791 global_settings
.peak_meter_clip_hold
);
797 #ifdef HAVE_LCD_BITMAP
798 /* fonts need to be loaded before the WPS */
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
);
816 unload_wps_backdrop();
818 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
819 unload_remote_wps_backdrop();
821 if ( global_settings
.wps_file
[0] &&
822 global_settings
.wps_file
[0] != 0xff ) {
823 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
824 global_settings
.wps_file
);
825 wps_data_load(gui_wps
[0].data
, &screens
[0], buf
, true);
829 wps_data_init(gui_wps
[0].data
);
830 #ifdef HAVE_REMOTE_LCD
831 gui_wps
[0].data
->remote_wps
= false;
836 if ( global_settings
.backdrop_file
[0] &&
837 global_settings
.backdrop_file
[0] != 0xff ) {
838 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
839 global_settings
.backdrop_file
);
840 load_main_backdrop(buf
);
842 unload_main_backdrop();
844 show_main_backdrop();
846 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
847 show_remote_main_backdrop();
850 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
851 if ( global_settings
.rwps_file
[0]) {
852 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
853 global_settings
.rwps_file
);
854 wps_data_load(gui_wps
[1].data
, &screens
[1], buf
, true);
858 wps_data_init(gui_wps
[1].data
);
859 gui_wps
[1].data
->remote_wps
= true;
862 if ( global_settings
.lang_file
[0]) {
863 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
864 global_settings
.lang_file
);
866 talk_init(); /* use voice of same language */
868 /* load the icon set */
871 #ifdef HAVE_LCD_COLOR
872 if (global_settings
.colors_file
[0])
873 read_color_theme_file();
877 #ifdef HAVE_LCD_COLOR
878 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
879 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
880 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
881 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
882 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
885 #ifdef HAVE_LCD_BITMAP
886 lcd_scroll_step(global_settings
.scroll_step
);
887 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
888 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
890 lcd_jump_scroll(global_settings
.jump_scroll
);
891 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
893 lcd_bidir_scroll(global_settings
.bidir_limit
);
894 lcd_scroll_delay(global_settings
.scroll_delay
);
897 set_codepage(global_settings
.default_codepage
);
899 #if CONFIG_CODEC == SWCODEC
900 audio_set_crossfade(global_settings
.crossfade
);
901 dsp_set_replaygain();
902 dsp_set_crossfeed(global_settings
.crossfeed
);
903 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
904 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
905 global_settings
.crossfeed_hf_attenuation
,
906 global_settings
.crossfeed_hf_cutoff
);
908 /* Configure software equalizer, hardware eq is handled in audio_init() */
909 dsp_set_eq(global_settings
.eq_enabled
);
910 dsp_set_eq_precut(global_settings
.eq_precut
);
911 for(i
= 0; i
< 5; i
++) {
915 dsp_dither_enable(global_settings
.dithering_enabled
);
918 #ifdef HAVE_SPDIF_POWER
919 spdif_power_enable(global_settings
.spdif_enable
);
922 #ifdef HAVE_BACKLIGHT
923 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
924 #ifdef HAVE_REMOTE_LCD
925 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
927 #ifdef HAS_BUTTON_HOLD
928 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
930 #ifdef HAVE_LCD_SLEEP_SETTING
931 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
933 #endif /* HAVE_BACKLIGHT */
935 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
936 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
939 /* This should stay last */
940 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
941 enc_global_settings_apply();
943 list_init_viewports(NULL
);
948 * reset all settings to their default value
950 void reset_setting(const struct settings_list
*setting
, void *var
)
952 switch (setting
->flags
&F_T_MASK
)
956 if (setting
->flags
&F_DEF_ISFUNC
)
957 *(int*)var
= setting
->default_val
.func();
958 else if (setting
->flags
&F_T_SOUND
)
959 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
960 else *(int*)var
= setting
->default_val
.int_
;
963 *(bool*)var
= setting
->default_val
.bool_
;
967 strncpy((char*)var
, setting
->default_val
.charptr
,
968 setting
->filename_setting
->max_len
);
973 void settings_reset(void)
977 for(i
=0; i
<nb_settings
; i
++)
978 reset_setting(&settings
[i
], settings
[i
].setting
);
979 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
980 enc_global_settings_reset();
984 /** Changing setting values **/
985 const struct settings_list
* find_setting(const void* variable
, int *id
)
988 for(i
=0;i
<nb_settings
;i
++)
990 if (settings
[i
].setting
== variable
)
1000 bool set_bool(const char* string
, const bool* variable
)
1002 return set_bool_options(string
, variable
,
1003 (char *)STR(LANG_SET_BOOL_YES
),
1004 (char *)STR(LANG_SET_BOOL_NO
),
1009 bool set_bool_options(const char* string
, const bool* variable
,
1010 const char* yes_str
, int yes_voice
,
1011 const char* no_str
, int no_voice
,
1012 void (*function
)(bool))
1014 struct opt_items names
[] = {
1015 {(unsigned const char *)no_str
, no_voice
},
1016 {(unsigned const char *)yes_str
, yes_voice
}
1020 result
= set_option(string
, variable
, BOOL
, names
, 2,
1021 (void (*)(int))function
);
1025 bool set_int(const unsigned char* string
,
1028 const int* variable
,
1029 void (*function
)(int),
1033 void (*formatter
)(char*, size_t, int, const char*) )
1035 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1036 step
, min
, max
, formatter
, NULL
);
1039 bool set_int_ex(const unsigned char* string
,
1042 const int* variable
,
1043 void (*function
)(int),
1047 void (*formatter
)(char*, size_t, int, const char*),
1048 int32_t (*get_talk_id
)(int, int))
1051 struct settings_list item
;
1052 struct int_setting data
= {
1053 function
, voice_unit
, min
, max
, step
,
1054 formatter
, get_talk_id
1056 item
.int_setting
= &data
;
1057 item
.flags
= F_INT_SETTING
|F_T_INT
;
1059 item
.cfg_vals
= (char*)string
;
1060 item
.setting
= (void *)variable
;
1061 return option_screen(&item
, NULL
, false, NULL
);
1065 static const struct opt_items
*set_option_options
;
1066 static void set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1069 const unsigned char *text
= set_option_options
[item
].string
;
1070 strncpy(buf
, P2STR(text
), size
);
1072 static int32_t set_option_get_talk_id(int value
, int unit
)
1075 return set_option_options
[value
].voice_id
;
1077 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1078 const struct opt_items
* options
,
1079 int numoptions
, void (*function
)(int))
1082 struct settings_list item
;
1083 struct int_setting data
= {
1084 function
, UNIT_INT
, 0, numoptions
-1, 1,
1085 set_option_formatter
, set_option_get_talk_id
1087 set_option_options
= options
;
1088 item
.int_setting
= &data
;
1089 item
.flags
= F_INT_SETTING
|F_T_INT
;
1091 item
.cfg_vals
= (char*)string
;
1092 item
.setting
= &temp
;
1094 temp
= *(bool*)variable
? 1: 0;
1096 temp
= *(int*)variable
;
1097 if (!option_screen(&item
, NULL
, false, NULL
))
1100 *(bool*)variable
= (temp
== 1? true: false);
1102 *(int*)variable
= temp
;
1109 void set_file(const char* filename
, char* setting
, int maxlen
)
1111 char* fptr
= strrchr(filename
,'/');
1124 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1128 if(ptr
== fptr
) extlen
= 0;
1130 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1131 (len
-extlen
> maxlen
))
1134 strncpy(setting
, fptr
, len
-extlen
);
1135 setting
[len
-extlen
]=0;