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"
39 #include "ata_idle_notify.h"
47 #ifdef HAVE_LCD_BITMAP
50 #include "peakmeter.h"
54 #include "powermgmt.h"
59 #include "rbunicode.h"
63 #include "settings_list.h"
64 #include "filetypes.h"
65 #include "option_select.h"
70 #include "skin_engine/skin_engine.h"
72 #include "statusbar-skinned.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 strlcpy(temp
, start
, end
-start
+1);
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
)
285 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
289 #ifdef HAVE_LCD_COLOR
290 if (settings
[i
].flags
&F_RGB
)
291 hex_to_rgb(value
, (int*)settings
[i
].setting
);
294 if (settings
[i
].cfg_vals
== NULL
)
296 *(int*)settings
[i
].setting
= atoi(value
);
300 int temp
, *v
= (int*)settings
[i
].setting
;
301 bool found
= cfg_string_to_int(i
, &temp
, value
);
304 if (settings
[i
].flags
&F_TABLE_SETTING
)
305 *v
= settings
[i
].table_setting
->values
[temp
];
310 { /* atoi breaks choice settings because they
311 * don't have int-like values, and would
312 * fall back to the first value (i.e. 0)
314 if (!(settings
[i
].flags
&F_CHOICE_SETTING
))
322 if (cfg_string_to_int(i
,&temp
,value
))
323 *(bool*)settings
[i
].setting
= (temp
!=0);
324 if (settings
[i
].bool_setting
->option_callback
)
325 settings
[i
].bool_setting
->option_callback(temp
!=0);
331 char storage
[MAX_PATH
];
332 if (settings
[i
].filename_setting
->prefix
)
334 int len
= strlen(settings
[i
].filename_setting
->prefix
);
335 if (!strncasecmp(value
,
336 settings
[i
].filename_setting
->prefix
,
339 strlcpy(storage
, &value
[len
], MAX_PATH
);
341 else strlcpy(storage
, value
, MAX_PATH
);
343 else strlcpy(storage
, value
, MAX_PATH
);
344 if (settings
[i
].filename_setting
->suffix
)
346 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
349 strlcpy((char*)settings
[i
].setting
, storage
,
350 settings
[i
].filename_setting
->max_len
);
355 } /* if (!strcmp(name,settings[i].cfg_name)) */
362 settings_apply(true);
366 /** Writing to a config file and saving settings **/
368 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
370 int flags
= settings
[setting_id
].flags
;
371 const char* start
= settings
[setting_id
].cfg_vals
;
375 if ((flags
&F_T_MASK
)==F_T_INT
&&
376 flags
&F_TABLE_SETTING
)
378 const int *value
= settings
[setting_id
].table_setting
->values
;
381 end
= strchr(start
,',');
382 if (value
[count
] == val
)
385 strlcpy(buf
, start
, buf_len
);
388 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
389 strlcpy(buf
, start
, len
+1);
405 start
= strchr(start
,',');
411 end
= strchr(start
,',');
413 strlcpy(buf
, start
, buf_len
);
416 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
417 strlcpy(buf
, start
, len
+1);
422 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
424 switch (settings
[i
].flags
&F_T_MASK
)
427 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
432 #ifdef HAVE_LCD_COLOR
433 if (settings
[i
].flags
&F_RGB
)
435 int colour
= *(int*)settings
[i
].setting
;
436 snprintf(buf
,buf_len
,"%02x%02x%02x",
437 (int)RGB_UNPACK_RED(colour
),
438 (int)RGB_UNPACK_GREEN(colour
),
439 (int)RGB_UNPACK_BLUE(colour
));
443 if (settings
[i
].cfg_vals
== NULL
)
445 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
449 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
450 buf
, buf_len
) == false)
452 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
460 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
464 if (((char*)settings
[i
].setting
)[0]
465 && settings
[i
].filename_setting
->prefix
)
467 snprintf(buf
,buf_len
,"%s%s%s",
468 settings
[i
].filename_setting
->prefix
,
469 (char*)settings
[i
].setting
,
470 settings
[i
].filename_setting
->suffix
);
472 else strlcpy(buf
,(char*)settings
[i
].setting
,
473 settings
[i
].filename_setting
->max_len
);
480 static bool is_changed(int setting_id
)
482 const struct settings_list
*setting
= &settings
[setting_id
];
483 switch (setting
->flags
&F_T_MASK
)
486 return setting
->custom_setting
->is_changed(setting
->setting
,
487 setting
->default_val
.custom
);
491 if (setting
->flags
&F_DEF_ISFUNC
)
493 if (*(int*)setting
->setting
== setting
->default_val
.func())
496 else if (setting
->flags
&F_T_SOUND
)
498 if (*(int*)setting
->setting
==
499 sound_default(setting
->sound_setting
->setting
))
502 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
506 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
511 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
518 static bool settings_write_config(const char* filename
, int options
)
522 char value
[MAX_PATH
];
523 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
526 fdprintf(fd
, "# .cfg file created by rockbox %s - "
527 "http://www.rockbox.org\r\n\r\n", appsversion
);
528 for(i
=0; i
<nb_settings
; i
++)
530 if (settings
[i
].cfg_name
== NULL
)
536 case SETTINGS_SAVE_CHANGED
:
540 case SETTINGS_SAVE_SOUND
:
541 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
544 case SETTINGS_SAVE_THEME
:
545 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
548 #ifdef HAVE_RECORDING
549 case SETTINGS_SAVE_RECPRESETS
:
550 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
554 #if CONFIG_CODEC == SWCODEC
555 case SETTINGS_SAVE_EQPRESET
:
556 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
562 cfg_to_string(i
, value
, MAX_PATH
);
563 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
569 static void flush_global_status_callback(void *data
)
572 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
575 static void flush_config_block_callback(void *data
)
578 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
579 settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
583 * persist all runtime user settings to disk or RTC RAM
585 static void update_runtime(void)
589 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
590 global_status
.runtime
+= elapsed_secs
;
591 lasttime
+= (elapsed_secs
* HZ
);
593 if ( global_status
.runtime
> global_status
.topruntime
)
594 global_status
.topruntime
= global_status
.runtime
;
597 void status_save(void)
601 /* this will be done in the storage_callback if
602 target doesnt have rtc ram */
603 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
605 register_storage_idle_func(flush_global_status_callback
);
609 int settings_save(void)
613 /* this will be done in the storage_callback if
614 target doesnt have rtc ram */
615 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
617 register_storage_idle_func(flush_config_block_callback
);
621 bool settings_save_config(int options
)
623 char filename
[MAX_PATH
];
624 char *folder
, *namebase
;
627 case SETTINGS_SAVE_THEME
:
631 #ifdef HAVE_RECORDING
632 case SETTINGS_SAVE_RECPRESETS
:
633 folder
= RECPRESETS_DIR
;
634 namebase
= "recording";
637 #if CONFIG_CODEC == SWCODEC
638 case SETTINGS_SAVE_EQPRESET
:
643 case SETTINGS_SAVE_SOUND
:
644 folder
= ROCKBOX_DIR
;
648 folder
= ROCKBOX_DIR
;
652 create_numbered_filename(filename
, folder
, namebase
, ".cfg", 2
653 IF_CNFN_NUM_(, NULL
));
655 /* allow user to modify filename */
657 if (!kbd_input(filename
, sizeof filename
)) {
665 if (settings_write_config(filename
, options
))
666 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
668 splash(HZ
, ID2P(LANG_FAILED
));
672 /** Apply and Reset settings **/
675 #ifdef HAVE_LCD_BITMAP
677 * Applies the range infos stored in global_settings to
680 void settings_apply_pm_range(void)
684 /* depending on the scale mode (dBfs or percent) the values
685 of global_settings.peak_meter_dbfs have different meanings */
686 if (global_settings
.peak_meter_dbfs
)
688 /* convert to dBfs * 100 */
689 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
690 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
694 /* percent is stored directly -> no conversion */
695 pm_min
= global_settings
.peak_meter_min
;
696 pm_max
= global_settings
.peak_meter_max
;
699 /* apply the range */
700 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
702 #endif /* HAVE_LCD_BITMAP */
704 void sound_settings_apply(void)
706 #if CONFIG_CODEC == SWCODEC
707 sound_set_dsp_callback(dsp_callback
);
709 sound_set(SOUND_BASS
, global_settings
.bass
);
710 sound_set(SOUND_TREBLE
, global_settings
.treble
);
711 sound_set(SOUND_BALANCE
, global_settings
.balance
);
712 sound_set(SOUND_VOLUME
, global_settings
.volume
);
713 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
714 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
715 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
716 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
717 sound_set(SOUND_AVC
, global_settings
.avc
);
718 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
719 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
720 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
721 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
722 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
723 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
727 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
728 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
734 /* call this after loading a .wps/.rwps pr other skin files, so that the
735 * skin buffer is reset properly
737 void settings_apply_skins(void)
740 /* re-initialize the skin buffer before we start reloading skins */
742 #ifdef HAVE_LCD_BITMAP
743 if ( global_settings
.sbs_file
[0] &&
744 global_settings
.sbs_file
[0] != 0xff )
746 snprintf(buf
, sizeof buf
, SBS_DIR
"/%s.sbs",
747 global_settings
.sbs_file
);
748 sb_skin_data_load(SCREEN_MAIN
, buf
, true);
752 sb_skin_data_load(SCREEN_MAIN
, NULL
, true);
755 if ( global_settings
.wps_file
[0] &&
756 global_settings
.wps_file
[0] != 0xff )
758 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
759 global_settings
.wps_file
);
760 wps_data_load(SCREEN_MAIN
, buf
, true);
764 wps_data_load(SCREEN_MAIN
, NULL
, true);
766 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
767 if ( global_settings
.rsbs_file
[0] &&
768 global_settings
.rsbs_file
[0] != 0xff ) {
769 snprintf(buf
, sizeof buf
, SBS_DIR
"/%s.rsbs",
770 global_settings
.rsbs_file
);
771 sb_skin_data_load(SCREEN_REMOTE
, buf
, true);
775 sb_skin_data_load(SCREEN_REMOTE
, NULL
, true);
777 if ( global_settings
.rwps_file
[0])
779 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
780 global_settings
.rwps_file
);
781 wps_data_load(SCREEN_REMOTE
, buf
, true);
785 wps_data_load(SCREEN_REMOTE
, NULL
, true);
788 viewportmanager_theme_changed(THEME_STATUSBAR
);
791 void settings_apply(bool read_disk
)
795 #if CONFIG_CODEC == SWCODEC
798 sound_settings_apply();
800 #ifdef HAVE_DISK_STORAGE
801 audio_set_buffer_margin(global_settings
.buffer_margin
);
804 #ifdef HAVE_LCD_CONTRAST
805 lcd_set_contrast(global_settings
.contrast
);
807 lcd_scroll_speed(global_settings
.scroll_speed
);
808 #ifdef HAVE_REMOTE_LCD
809 lcd_remote_set_contrast(global_settings
.remote_contrast
);
810 lcd_remote_set_invert_display(global_settings
.remote_invert
);
813 lcd_remote_set_flip(global_settings
.remote_flip_display
);
816 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
817 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
818 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
819 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
820 #ifdef HAVE_REMOTE_LCD_TICKING
821 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
823 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
825 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
827 #ifdef HAS_REMOTE_BUTTON_HOLD
828 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
830 #endif /* HAVE_REMOTE_LCD */
831 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
832 backlight_set_brightness(global_settings
.brightness
);
834 #ifdef HAVE_BACKLIGHT
835 backlight_set_timeout(global_settings
.backlight_timeout
);
837 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
839 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
840 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
841 backlight_set_fade_in(global_settings
.backlight_fade_in
);
842 backlight_set_fade_out(global_settings
.backlight_fade_out
);
845 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
846 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
848 #ifdef HAVE_BUTTON_LIGHT
849 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
851 #ifdef HAVE_DISK_STORAGE
852 storage_spindown(global_settings
.disk_spindown
);
854 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
855 dac_line_in(global_settings
.line_in
);
857 set_poweroff_timeout(global_settings
.poweroff
);
859 set_battery_capacity(global_settings
.battery_capacity
);
860 #if BATTERY_TYPES_COUNT > 1
861 set_battery_type(global_settings
.battery_type
);
864 #ifdef HAVE_LCD_BITMAP
865 #ifdef HAVE_LCD_INVERT
866 lcd_set_invert_display(global_settings
.invert
);
869 lcd_set_flip(global_settings
.flip_display
);
870 button_set_flip(global_settings
.flip_display
);
872 lcd_update(); /* refresh after flipping the screen */
873 settings_apply_pm_range();
874 peak_meter_init_times(
875 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
876 global_settings
.peak_meter_clip_hold
);
880 audiohw_enable_speaker(global_settings
.speaker_enabled
);
886 #ifdef HAVE_LCD_BITMAP
887 /* fonts need to be loaded before the WPS */
888 if ( global_settings
.font_file
[0]) {
889 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
890 global_settings
.font_file
);
891 if (font_load(buf
) == NULL
)
897 if ( global_settings
.kbd_file
[0]) {
898 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
899 global_settings
.kbd_file
);
906 if ( global_settings
.lang_file
[0]) {
907 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
908 global_settings
.lang_file
);
910 talk_init(); /* use voice of same language */
914 settings_apply_skins();
916 /* load the icon set */
919 #ifdef HAVE_LCD_COLOR
920 if (global_settings
.colors_file
[0])
921 read_color_theme_file();
925 #ifdef HAVE_LCD_COLOR
926 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
927 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
928 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
929 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
930 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
933 #ifdef HAVE_LCD_BITMAP
934 lcd_scroll_step(global_settings
.scroll_step
);
935 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
936 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
938 lcd_jump_scroll(global_settings
.jump_scroll
);
939 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
941 lcd_bidir_scroll(global_settings
.bidir_limit
);
942 lcd_scroll_delay(global_settings
.scroll_delay
);
945 set_codepage(global_settings
.default_codepage
);
947 #if CONFIG_CODEC == SWCODEC
948 #ifdef HAVE_CROSSFADE
949 audio_set_crossfade(global_settings
.crossfade
);
951 dsp_set_replaygain();
952 dsp_set_crossfeed(global_settings
.crossfeed
);
953 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
954 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
955 global_settings
.crossfeed_hf_attenuation
,
956 global_settings
.crossfeed_hf_cutoff
);
958 /* Configure software equalizer, hardware eq is handled in audio_init() */
959 dsp_set_eq(global_settings
.eq_enabled
);
960 dsp_set_eq_precut(global_settings
.eq_precut
);
961 for(i
= 0; i
< 5; i
++) {
965 dsp_dither_enable(global_settings
.dithering_enabled
);
966 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
967 dsp_set_compressor(global_settings
.compressor_threshold
,
968 global_settings
.compressor_makeup_gain
,
969 global_settings
.compressor_ratio
,
970 global_settings
.compressor_knee
,
971 global_settings
.compressor_release_time
);
974 #ifdef HAVE_SPDIF_POWER
975 spdif_power_enable(global_settings
.spdif_enable
);
978 #ifdef HAVE_BACKLIGHT
979 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
980 #ifdef HAVE_REMOTE_LCD
981 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
983 #ifdef HAS_BUTTON_HOLD
984 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
986 #ifdef HAVE_LCD_SLEEP_SETTING
987 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
989 #endif /* HAVE_BACKLIGHT */
991 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
992 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
995 #ifdef HAVE_USB_CHARGING_ENABLE
996 usb_charging_enable(global_settings
.usb_charging
);
999 #ifdef HAVE_TOUCHSCREEN
1000 touchscreen_set_mode(global_settings
.touch_mode
);
1001 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1004 /* This should stay last */
1005 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1006 enc_global_settings_apply();
1008 #ifdef HAVE_LCD_BITMAP
1009 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1010 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
);
1016 * reset all settings to their default value
1018 void reset_setting(const struct settings_list
*setting
, void *var
)
1020 switch (setting
->flags
&F_T_MASK
)
1023 setting
->custom_setting
->set_default(setting
->setting
,
1024 setting
->default_val
.custom
);
1028 if (setting
->flags
&F_DEF_ISFUNC
)
1029 *(int*)var
= setting
->default_val
.func();
1030 else if (setting
->flags
&F_T_SOUND
)
1031 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1032 else *(int*)var
= setting
->default_val
.int_
;
1035 *(bool*)var
= setting
->default_val
.bool_
;
1039 strlcpy((char*)var
, setting
->default_val
.charptr
,
1040 setting
->filename_setting
->max_len
);
1045 void settings_reset(void)
1049 for(i
=0; i
<nb_settings
; i
++)
1050 reset_setting(&settings
[i
], settings
[i
].setting
);
1051 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1052 enc_global_settings_reset();
1056 /** Changing setting values **/
1057 const struct settings_list
* find_setting(const void* variable
, int *id
)
1060 for(i
=0;i
<nb_settings
;i
++)
1062 if (settings
[i
].setting
== variable
)
1066 return &settings
[i
];
1072 bool set_bool(const char* string
, const bool* variable
)
1074 return set_bool_options(string
, variable
,
1075 (char *)STR(LANG_SET_BOOL_YES
),
1076 (char *)STR(LANG_SET_BOOL_NO
),
1081 bool set_bool_options(const char* string
, const bool* variable
,
1082 const char* yes_str
, int yes_voice
,
1083 const char* no_str
, int no_voice
,
1084 void (*function
)(bool))
1086 struct opt_items names
[] = {
1087 {(unsigned const char *)no_str
, no_voice
},
1088 {(unsigned const char *)yes_str
, yes_voice
}
1092 result
= set_option(string
, variable
, BOOL
, names
, 2,
1093 (void (*)(int))function
);
1097 bool set_int(const unsigned char* string
,
1100 const int* variable
,
1101 void (*function
)(int),
1105 const char* (*formatter
)(char*, size_t, int, const char*) )
1107 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1108 step
, min
, max
, formatter
, NULL
);
1111 bool set_int_ex(const unsigned char* string
,
1114 const int* variable
,
1115 void (*function
)(int),
1119 const char* (*formatter
)(char*, size_t, int, const char*),
1120 int32_t (*get_talk_id
)(int, int))
1123 struct settings_list item
;
1124 struct int_setting data
= {
1125 function
, voice_unit
, min
, max
, step
,
1126 formatter
, get_talk_id
1128 item
.int_setting
= &data
;
1129 item
.flags
= F_INT_SETTING
|F_T_INT
;
1131 item
.cfg_vals
= (char*)string
;
1132 item
.setting
= (void *)variable
;
1133 return option_screen(&item
, NULL
, false, NULL
);
1137 static const struct opt_items
*set_option_options
;
1138 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1140 (void)buf
, (void)unit
, (void)size
;
1141 return P2STR(set_option_options
[item
].string
);
1144 static int32_t set_option_get_talk_id(int value
, int unit
)
1147 return set_option_options
[value
].voice_id
;
1150 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1151 const struct opt_items
* options
,
1152 int numoptions
, void (*function
)(int))
1155 struct settings_list item
;
1156 struct int_setting data
= {
1157 function
, UNIT_INT
, 0, numoptions
-1, 1,
1158 set_option_formatter
, set_option_get_talk_id
1160 set_option_options
= options
;
1161 item
.int_setting
= &data
;
1162 item
.flags
= F_INT_SETTING
|F_T_INT
;
1164 item
.cfg_vals
= (char*)string
;
1165 item
.setting
= &temp
;
1167 temp
= *(bool*)variable
? 1: 0;
1169 temp
= *(int*)variable
;
1170 if (!option_screen(&item
, NULL
, false, NULL
))
1173 *(bool*)variable
= (temp
== 1);
1175 *(int*)variable
= temp
;
1182 void set_file(const char* filename
, char* setting
, int maxlen
)
1184 const char* fptr
= strrchr(filename
,'/');
1196 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1200 if(ptr
== fptr
) extlen
= 0;
1202 if (strncasecmp(ROCKBOX_DIR
, filename
, strlen(ROCKBOX_DIR
)) ||
1203 (len
-extlen
> maxlen
))
1206 strlcpy(setting
, fptr
, len
-extlen
+1);