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"
48 #ifdef HAVE_LCD_BITMAP
51 #include "peakmeter.h"
56 #include "powermgmt.h"
61 #include "rbunicode.h"
65 #include "settings_list.h"
66 #include "filetypes.h"
67 #include "option_select.h"
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
]);
216 /** Reading from a config file **/
218 * load settings from disk or RTC RAM
220 void settings_load(int which
)
222 if (which
&SETTINGS_RTC
)
223 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
224 if (which
&SETTINGS_HD
)
226 settings_load_config(CONFIGFILE
,false);
227 settings_load_config(FIXEDSETTINGSFILE
,false);
231 static bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
233 const char* start
= settings
[setting_id
].cfg_vals
;
239 end
= strchr(start
, ',');
242 if (!strcmp(str
, start
))
249 strncpy(temp
, start
, end
-start
);
250 temp
[end
-start
] = '\0';
251 if (!strcmp(str
, temp
))
262 bool settings_load_config(const char* file
, bool apply
)
269 fd
= open_utf8(file
, O_RDONLY
);
273 while (read_line(fd
, line
, sizeof line
) > 0)
275 if (!settings_parseline(line
, &name
, &value
))
277 for(i
=0; i
<nb_settings
; i
++)
279 if (settings
[i
].cfg_name
== NULL
)
281 if (!strcasecmp(name
,settings
[i
].cfg_name
))
283 switch (settings
[i
].flags
&F_T_MASK
)
286 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
290 #ifdef HAVE_LCD_COLOR
291 if (settings
[i
].flags
&F_RGB
)
292 hex_to_rgb(value
, (int*)settings
[i
].setting
);
295 if (settings
[i
].cfg_vals
== NULL
)
297 *(int*)settings
[i
].setting
= atoi(value
);
301 int temp
, *v
= (int*)settings
[i
].setting
;
302 bool found
= cfg_string_to_int(i
, &temp
, value
);
305 if (settings
[i
].flags
&F_TABLE_SETTING
)
306 *v
= settings
[i
].table_setting
->values
[temp
];
317 if (cfg_string_to_int(i
,&temp
,value
))
318 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
319 if (settings
[i
].bool_setting
->option_callback
)
320 settings
[i
].bool_setting
->option_callback(temp
==0?false:true);
326 char storage
[MAX_PATH
];
327 if (settings
[i
].filename_setting
->prefix
)
329 int len
= strlen(settings
[i
].filename_setting
->prefix
);
330 if (!strncasecmp(value
,
331 settings
[i
].filename_setting
->prefix
,
334 strncpy(storage
,&value
[len
],MAX_PATH
);
336 else strncpy(storage
,value
,MAX_PATH
);
338 else strncpy(storage
,value
,MAX_PATH
);
339 if (settings
[i
].filename_setting
->suffix
)
341 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
344 strncpy((char*)settings
[i
].setting
,storage
,
345 settings
[i
].filename_setting
->max_len
);
346 ((char*)settings
[i
].setting
)
347 [settings
[i
].filename_setting
->max_len
-1] = '\0';
352 } /* if (!strcmp(name,settings[i].cfg_name)) */
359 settings_apply(true);
363 /** Writing to a config file and saving settings **/
365 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
367 int flags
= settings
[setting_id
].flags
;
368 const char* start
= settings
[setting_id
].cfg_vals
;
372 if ((flags
&F_T_MASK
)==F_T_INT
&&
373 flags
&F_TABLE_SETTING
)
375 const int *value
= settings
[setting_id
].table_setting
->values
;
378 end
= strchr(start
,',');
379 if (value
[count
] == val
)
382 strncpy(buf
, start
, buf_len
);
385 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
386 strncpy(buf
, start
, len
);
403 start
= strchr(start
,',');
409 end
= strchr(start
,',');
411 strncpy(buf
, start
, buf_len
);
414 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
415 strncpy(buf
, start
, len
);
421 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
423 switch (settings
[i
].flags
&F_T_MASK
)
426 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
431 #ifdef HAVE_LCD_COLOR
432 if (settings
[i
].flags
&F_RGB
)
434 int colour
= *(int*)settings
[i
].setting
;
435 snprintf(buf
,buf_len
,"%02x%02x%02x",
436 (int)RGB_UNPACK_RED(colour
),
437 (int)RGB_UNPACK_GREEN(colour
),
438 (int)RGB_UNPACK_BLUE(colour
));
442 if (settings
[i
].cfg_vals
== NULL
)
444 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
448 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
449 buf
, buf_len
) == false)
451 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
459 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
463 if (((char*)settings
[i
].setting
)[0]
464 && settings
[i
].filename_setting
->prefix
)
466 snprintf(buf
,buf_len
,"%s%s%s",
467 settings
[i
].filename_setting
->prefix
,
468 (char*)settings
[i
].setting
,
469 settings
[i
].filename_setting
->suffix
);
471 else strncpy(buf
,(char*)settings
[i
].setting
,
472 settings
[i
].filename_setting
->max_len
);
479 static bool is_changed(int setting_id
)
481 const struct settings_list
*setting
= &settings
[setting_id
];
482 switch (setting
->flags
&F_T_MASK
)
485 return setting
->custom_setting
->is_changed(setting
->setting
,
486 setting
->default_val
.custom
);
490 if (setting
->flags
&F_DEF_ISFUNC
)
492 if (*(int*)setting
->setting
== setting
->default_val
.func())
495 else if (setting
->flags
&F_T_SOUND
)
497 if (*(int*)setting
->setting
==
498 sound_default(setting
->sound_setting
->setting
))
501 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
505 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
510 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
517 static bool settings_write_config(const char* filename
, int options
)
521 char value
[MAX_PATH
];
522 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
525 fdprintf(fd
, "# .cfg file created by rockbox %s - "
526 "http://www.rockbox.org\r\n\r\n", appsversion
);
527 for(i
=0; i
<nb_settings
; i
++)
529 if (settings
[i
].cfg_name
== NULL
)
535 case SETTINGS_SAVE_CHANGED
:
539 case SETTINGS_SAVE_SOUND
:
540 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
543 case SETTINGS_SAVE_THEME
:
544 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
547 #ifdef HAVE_RECORDING
548 case SETTINGS_SAVE_RECPRESETS
:
549 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
553 #if CONFIG_CODEC == SWCODEC
554 case SETTINGS_SAVE_EQPRESET
:
555 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
561 cfg_to_string(i
, value
, MAX_PATH
);
562 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
568 static bool flush_global_status_callback(void)
570 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
573 static bool flush_config_block_callback(void)
576 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
577 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
582 * persist all runtime user settings to disk or RTC RAM
584 static void update_runtime(void)
588 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
589 global_status
.runtime
+= elapsed_secs
;
590 lasttime
+= (elapsed_secs
* HZ
);
592 if ( global_status
.runtime
> global_status
.topruntime
)
593 global_status
.topruntime
= global_status
.runtime
;
596 void status_save(void)
600 /* this will be done in the storage_callback if
601 target doesnt have rtc ram */
602 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
604 register_storage_idle_func(flush_global_status_callback
);
608 int settings_save(void)
612 /* this will be done in the storage_callback if
613 target doesnt have rtc ram */
614 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
616 register_storage_idle_func(flush_config_block_callback
);
620 bool settings_save_config(int options
)
622 char filename
[MAX_PATH
];
626 case SETTINGS_SAVE_THEME
:
629 #ifdef HAVE_RECORDING
630 case SETTINGS_SAVE_RECPRESETS
:
631 folder
= RECPRESETS_DIR
;
634 #if CONFIG_CODEC == SWCODEC
635 case SETTINGS_SAVE_EQPRESET
:
639 case SETTINGS_SAVE_SOUND
:
641 folder
= ROCKBOX_DIR
;
643 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
644 IF_CNFN_NUM_(, NULL
));
646 /* allow user to modify filename */
648 if (!kbd_input(filename
, sizeof filename
)) {
652 splash(HZ
, ID2P(LANG_CANCEL
));
657 if (settings_write_config(filename
, options
))
658 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
660 splash(HZ
, ID2P(LANG_FAILED
));
664 /** Apply and Reset settings **/
667 #ifdef HAVE_LCD_BITMAP
669 * Applies the range infos stored in global_settings to
672 void settings_apply_pm_range(void)
676 /* depending on the scale mode (dBfs or percent) the values
677 of global_settings.peak_meter_dbfs have different meanings */
678 if (global_settings
.peak_meter_dbfs
)
680 /* convert to dBfs * 100 */
681 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
682 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
686 /* percent is stored directly -> no conversion */
687 pm_min
= global_settings
.peak_meter_min
;
688 pm_max
= global_settings
.peak_meter_max
;
691 /* apply the range */
692 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
694 #endif /* HAVE_LCD_BITMAP */
696 void sound_settings_apply(void)
698 #if CONFIG_CODEC == SWCODEC
699 sound_set_dsp_callback(dsp_callback
);
701 sound_set(SOUND_BASS
, global_settings
.bass
);
702 sound_set(SOUND_TREBLE
, global_settings
.treble
);
703 sound_set(SOUND_BALANCE
, global_settings
.balance
);
704 sound_set(SOUND_VOLUME
, global_settings
.volume
);
705 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
706 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
707 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
708 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
709 sound_set(SOUND_AVC
, global_settings
.avc
);
710 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
711 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
712 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
713 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
714 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
715 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
719 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
720 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
724 void settings_apply(bool read_disk
)
727 #if CONFIG_CODEC == SWCODEC
731 sound_settings_apply();
733 #ifdef HAVE_DISK_STORAGE
734 audio_set_buffer_margin(global_settings
.buffer_margin
);
737 #ifdef HAVE_LCD_CONTRAST
738 lcd_set_contrast(global_settings
.contrast
);
740 lcd_scroll_speed(global_settings
.scroll_speed
);
741 #ifdef HAVE_REMOTE_LCD
742 lcd_remote_set_contrast(global_settings
.remote_contrast
);
743 lcd_remote_set_invert_display(global_settings
.remote_invert
);
746 lcd_remote_set_flip(global_settings
.remote_flip_display
);
749 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
750 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
751 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
752 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
753 #ifdef HAVE_REMOTE_LCD_TICKING
754 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
756 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
758 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
760 #ifdef HAS_REMOTE_BUTTON_HOLD
761 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
763 #endif /* HAVE_REMOTE_LCD */
764 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
765 backlight_set_brightness(global_settings
.brightness
);
767 #ifdef HAVE_BACKLIGHT
768 backlight_set_timeout(global_settings
.backlight_timeout
);
770 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
772 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
773 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
774 backlight_set_fade_in(global_settings
.backlight_fade_in
);
775 backlight_set_fade_out(global_settings
.backlight_fade_out
);
778 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
779 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
781 #ifdef HAVE_BUTTON_LIGHT
782 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
784 #ifdef HAVE_DISK_STORAGE
785 storage_spindown(global_settings
.disk_spindown
);
787 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
788 dac_line_in(global_settings
.line_in
);
790 set_poweroff_timeout(global_settings
.poweroff
);
792 set_battery_capacity(global_settings
.battery_capacity
);
793 #if BATTERY_TYPES_COUNT > 1
794 set_battery_type(global_settings
.battery_type
);
797 #ifdef HAVE_LCD_BITMAP
798 #ifdef HAVE_LCD_INVERT
799 lcd_set_invert_display(global_settings
.invert
);
802 lcd_set_flip(global_settings
.flip_display
);
803 button_set_flip(global_settings
.flip_display
);
805 lcd_update(); /* refresh after flipping the screen */
806 settings_apply_pm_range();
807 peak_meter_init_times(
808 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
809 global_settings
.peak_meter_clip_hold
);
813 audiohw_enable_speaker(global_settings
.speaker_enabled
);
819 #ifdef HAVE_LCD_BITMAP
820 /* fonts need to be loaded before the WPS */
821 if ( global_settings
.font_file
[0]) {
822 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
823 global_settings
.font_file
);
824 if (font_load(buf
) == NULL
)
830 if ( global_settings
.kbd_file
[0]) {
831 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
832 global_settings
.kbd_file
);
839 unload_wps_backdrop();
841 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
842 unload_remote_wps_backdrop();
844 if ( global_settings
.wps_file
[0] &&
845 global_settings
.wps_file
[0] != 0xff ) {
846 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
847 global_settings
.wps_file
);
848 wps_data_load(gui_wps
[0].data
, &screens
[0], buf
, true);
852 wps_data_init(gui_wps
[0].data
);
853 #ifdef HAVE_REMOTE_LCD
854 gui_wps
[0].data
->remote_wps
= false;
859 if ( global_settings
.backdrop_file
[0] &&
860 global_settings
.backdrop_file
[0] != 0xff ) {
861 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
862 global_settings
.backdrop_file
);
863 load_main_backdrop(buf
);
865 unload_main_backdrop();
867 show_main_backdrop();
869 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
870 show_remote_main_backdrop();
873 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
874 if ( global_settings
.rwps_file
[0]) {
875 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
876 global_settings
.rwps_file
);
877 wps_data_load(gui_wps
[1].data
, &screens
[1], buf
, true);
881 wps_data_init(gui_wps
[1].data
);
882 gui_wps
[1].data
->remote_wps
= true;
885 if ( global_settings
.lang_file
[0]) {
886 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
887 global_settings
.lang_file
);
889 talk_init(); /* use voice of same language */
891 /* load the icon set */
894 #ifdef HAVE_LCD_COLOR
895 if (global_settings
.colors_file
[0])
896 read_color_theme_file();
900 #ifdef HAVE_LCD_COLOR
901 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
902 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
903 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
904 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
905 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
908 #ifdef HAVE_LCD_BITMAP
909 lcd_scroll_step(global_settings
.scroll_step
);
910 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
911 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
913 lcd_jump_scroll(global_settings
.jump_scroll
);
914 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
916 lcd_bidir_scroll(global_settings
.bidir_limit
);
917 lcd_scroll_delay(global_settings
.scroll_delay
);
920 set_codepage(global_settings
.default_codepage
);
922 #if CONFIG_CODEC == SWCODEC
923 audio_set_crossfade(global_settings
.crossfade
);
924 dsp_set_replaygain();
925 dsp_set_crossfeed(global_settings
.crossfeed
);
926 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
927 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
928 global_settings
.crossfeed_hf_attenuation
,
929 global_settings
.crossfeed_hf_cutoff
);
931 /* Configure software equalizer, hardware eq is handled in audio_init() */
932 dsp_set_eq(global_settings
.eq_enabled
);
933 dsp_set_eq_precut(global_settings
.eq_precut
);
934 for(i
= 0; i
< 5; i
++) {
938 dsp_dither_enable(global_settings
.dithering_enabled
);
941 #ifdef HAVE_SPDIF_POWER
942 spdif_power_enable(global_settings
.spdif_enable
);
945 #ifdef HAVE_BACKLIGHT
946 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
947 #ifdef HAVE_REMOTE_LCD
948 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
950 #ifdef HAS_BUTTON_HOLD
951 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
953 #ifdef HAVE_LCD_SLEEP_SETTING
954 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
956 #endif /* HAVE_BACKLIGHT */
958 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
959 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
962 #ifdef HAVE_USB_CHARGING_ENABLE
963 usb_charging_enable(global_settings
.usb_charging
);
966 #ifdef HAVE_TOUCHSCREEN
967 touchscreen_set_mode(global_settings
.touch_mode
);
970 /* This should stay last */
971 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
972 enc_global_settings_apply();
974 list_init_viewports(NULL
);
979 * reset all settings to their default value
981 void reset_setting(const struct settings_list
*setting
, void *var
)
983 switch (setting
->flags
&F_T_MASK
)
986 setting
->custom_setting
->set_default(setting
->setting
,
987 setting
->default_val
.custom
);
991 if (setting
->flags
&F_DEF_ISFUNC
)
992 *(int*)var
= setting
->default_val
.func();
993 else if (setting
->flags
&F_T_SOUND
)
994 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
995 else *(int*)var
= setting
->default_val
.int_
;
998 *(bool*)var
= setting
->default_val
.bool_
;
1002 strncpy((char*)var
, setting
->default_val
.charptr
,
1003 setting
->filename_setting
->max_len
);
1008 void settings_reset(void)
1012 for(i
=0; i
<nb_settings
; i
++)
1013 reset_setting(&settings
[i
], settings
[i
].setting
);
1014 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1015 enc_global_settings_reset();
1019 /** Changing setting values **/
1020 const struct settings_list
* find_setting(const void* variable
, int *id
)
1023 for(i
=0;i
<nb_settings
;i
++)
1025 if (settings
[i
].setting
== variable
)
1029 return &settings
[i
];
1035 bool set_bool(const char* string
, const bool* variable
)
1037 return set_bool_options(string
, variable
,
1038 (char *)STR(LANG_SET_BOOL_YES
),
1039 (char *)STR(LANG_SET_BOOL_NO
),
1044 bool set_bool_options(const char* string
, const bool* variable
,
1045 const char* yes_str
, int yes_voice
,
1046 const char* no_str
, int no_voice
,
1047 void (*function
)(bool))
1049 struct opt_items names
[] = {
1050 {(unsigned const char *)no_str
, no_voice
},
1051 {(unsigned const char *)yes_str
, yes_voice
}
1055 result
= set_option(string
, variable
, BOOL
, names
, 2,
1056 (void (*)(int))function
);
1060 bool set_int(const unsigned char* string
,
1063 const int* variable
,
1064 void (*function
)(int),
1068 void (*formatter
)(char*, size_t, int, const char*) )
1070 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1071 step
, min
, max
, formatter
, NULL
);
1074 bool set_int_ex(const unsigned char* string
,
1077 const int* variable
,
1078 void (*function
)(int),
1082 void (*formatter
)(char*, size_t, int, const char*),
1083 int32_t (*get_talk_id
)(int, int))
1086 struct settings_list item
;
1087 struct int_setting data
= {
1088 function
, voice_unit
, min
, max
, step
,
1089 formatter
, get_talk_id
1091 item
.int_setting
= &data
;
1092 item
.flags
= F_INT_SETTING
|F_T_INT
;
1094 item
.cfg_vals
= (char*)string
;
1095 item
.setting
= (void *)variable
;
1096 return option_screen(&item
, NULL
, false, NULL
);
1100 static const struct opt_items
*set_option_options
;
1101 static void set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1104 const unsigned char *text
= set_option_options
[item
].string
;
1105 strncpy(buf
, P2STR(text
), size
);
1107 static int32_t set_option_get_talk_id(int value
, int unit
)
1110 return set_option_options
[value
].voice_id
;
1112 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1113 const struct opt_items
* options
,
1114 int numoptions
, void (*function
)(int))
1117 struct settings_list item
;
1118 struct int_setting data
= {
1119 function
, UNIT_INT
, 0, numoptions
-1, 1,
1120 set_option_formatter
, set_option_get_talk_id
1122 set_option_options
= options
;
1123 item
.int_setting
= &data
;
1124 item
.flags
= F_INT_SETTING
|F_T_INT
;
1126 item
.cfg_vals
= (char*)string
;
1127 item
.setting
= &temp
;
1129 temp
= *(bool*)variable
? 1: 0;
1131 temp
= *(int*)variable
;
1132 if (!option_screen(&item
, NULL
, false, NULL
))
1135 *(bool*)variable
= (temp
== 1? true: false);
1137 *(int*)variable
= temp
;
1144 void set_file(const char* filename
, char* setting
, int maxlen
)
1146 char* fptr
= strrchr(filename
,'/');
1159 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1163 if(ptr
== fptr
) extlen
= 0;
1165 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1166 (len
-extlen
> maxlen
))
1169 strncpy(setting
, fptr
, len
-extlen
);
1170 setting
[len
-extlen
]=0;