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"
71 #include "skin_engine/skin_fonts.h"
73 #include "statusbar-skinned.h"
75 #if CONFIG_CODEC == MAS3507D
76 void dac_line_in(bool enable
);
78 struct user_settings global_settings
;
79 struct system_status global_status
;
81 #if CONFIG_CODEC == SWCODEC
85 #include "enc_config.h"
87 #endif /* CONFIG_CODEC == SWCODEC */
89 #define NVRAM_BLOCK_SIZE 44
91 #ifdef HAVE_LCD_BITMAP
97 #ifdef HAVE_REMOTE_LCD
98 #include "lcd-remote.h"
103 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
104 /* NVRAM is set out as
108 [3] stored variable count
110 [8-NVRAM_BLOCK_SIZE] data
112 #define NVRAM_DATA_START 8
113 #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
114 static char nvram_buffer
[NVRAM_BLOCK_SIZE
];
116 static bool read_nvram_data(char* buf
, int max_len
)
118 unsigned crc32
= 0xffffffff;
119 int var_count
= 0, i
= 0, buf_pos
= 0;
121 int fd
= open(NVRAM_FILE
,O_RDONLY
);
124 memset(buf
,0,max_len
);
125 if (read(fd
,buf
,max_len
) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
129 memset(buf
,0,max_len
);
131 for (i
=0; i
< max_len
; i
++ )
132 buf
[i
] = rtc_read(0x14+i
);
134 /* check magic, version */
135 if ((buf
[0] != 'R') || (buf
[1] != 'b')
136 || (buf
[2] != NVRAM_CONFIG_VERSION
))
139 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
140 max_len
-NVRAM_DATA_START
-1,0xffffffff);
141 if (memcmp(&crc32
,&buf
[4],4))
143 /* all good, so read in the settings */
145 buf_pos
= NVRAM_DATA_START
;
146 for(i
=0; i
<nb_settings
; i
++)
148 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
149 >>F_NVRAM_MASK_SHIFT
;
152 if ((var_count
>0) && (buf_pos
<max_len
))
154 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
155 buf_pos
+= nvram_bytes
;
158 else /* should only happen when new items are added to the end */
160 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
166 static bool write_nvram_data(char* buf
, int max_len
)
168 unsigned crc32
= 0xffffffff;
169 int i
= 0, buf_pos
= 0;
174 memset(buf
,0,max_len
);
176 buf
[0] = 'R'; buf
[1] = 'b';
177 buf
[2] = NVRAM_CONFIG_VERSION
;
178 buf_pos
= NVRAM_DATA_START
;
179 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
181 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
182 >>F_NVRAM_MASK_SHIFT
;
185 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
186 buf_pos
+= nvram_bytes
;
190 /* count and crc32 */
192 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
193 max_len
-NVRAM_DATA_START
-1,0xffffffff);
194 memcpy(&buf
[4],&crc32
,4);
196 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
);
199 int len
= write(fd
,buf
,max_len
);
205 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
206 that it would write a number of bytes at a time since the RTC chip
207 supports that, but this will have to do for now 8-) */
208 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
209 int r
= rtc_write(0x14+i
, buf
[i
]);
217 /** Reading from a config file **/
219 * load settings from disk or RTC RAM
221 void settings_load(int which
)
223 if (which
&SETTINGS_RTC
)
224 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
225 if (which
&SETTINGS_HD
)
227 settings_load_config(CONFIGFILE
,false);
228 settings_load_config(FIXEDSETTINGSFILE
,false);
232 static bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
234 const char* start
= settings
[setting_id
].cfg_vals
;
240 end
= strchr(start
, ',');
243 if (!strcmp(str
, start
))
250 strlcpy(temp
, start
, end
-start
+1);
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
];
311 { /* atoi breaks choice settings because they
312 * don't have int-like values, and would
313 * fall back to the first value (i.e. 0)
315 if (!(settings
[i
].flags
&F_CHOICE_SETTING
))
323 if (cfg_string_to_int(i
,&temp
,value
))
324 *(bool*)settings
[i
].setting
= (temp
!=0);
325 if (settings
[i
].bool_setting
->option_callback
)
326 settings
[i
].bool_setting
->option_callback(temp
!=0);
332 char storage
[MAX_PATH
];
333 if (settings
[i
].filename_setting
->prefix
)
335 int len
= strlen(settings
[i
].filename_setting
->prefix
);
336 if (!strncasecmp(value
,
337 settings
[i
].filename_setting
->prefix
,
340 strlcpy(storage
, &value
[len
], MAX_PATH
);
342 else strlcpy(storage
, value
, MAX_PATH
);
344 else strlcpy(storage
, value
, MAX_PATH
);
345 if (settings
[i
].filename_setting
->suffix
)
347 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
350 strlcpy((char*)settings
[i
].setting
, storage
,
351 settings
[i
].filename_setting
->max_len
);
356 } /* if (!strcmp(name,settings[i].cfg_name)) */
363 settings_apply(true);
367 /** Writing to a config file and saving settings **/
369 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
371 int flags
= settings
[setting_id
].flags
;
372 const char* start
= settings
[setting_id
].cfg_vals
;
376 if ((flags
&F_T_MASK
)==F_T_INT
&&
377 flags
&F_TABLE_SETTING
)
379 const int *value
= settings
[setting_id
].table_setting
->values
;
382 end
= strchr(start
,',');
383 if (value
[count
] == val
)
386 strlcpy(buf
, start
, buf_len
);
389 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
390 strlcpy(buf
, start
, len
+1);
406 start
= strchr(start
,',');
412 end
= strchr(start
,',');
414 strlcpy(buf
, start
, buf_len
);
417 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
418 strlcpy(buf
, start
, len
+1);
423 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
425 switch (settings
[i
].flags
&F_T_MASK
)
428 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
433 #ifdef HAVE_LCD_COLOR
434 if (settings
[i
].flags
&F_RGB
)
436 int colour
= *(int*)settings
[i
].setting
;
437 snprintf(buf
,buf_len
,"%02x%02x%02x",
438 (int)RGB_UNPACK_RED(colour
),
439 (int)RGB_UNPACK_GREEN(colour
),
440 (int)RGB_UNPACK_BLUE(colour
));
444 if (settings
[i
].cfg_vals
== NULL
)
446 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
450 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
451 buf
, buf_len
) == false)
453 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
461 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
465 if (((char*)settings
[i
].setting
)[0]
466 && settings
[i
].filename_setting
->prefix
)
468 if (((char*)settings
[i
].setting
)[0] == '-')
475 snprintf(buf
,buf_len
,"%s%s%s",
476 settings
[i
].filename_setting
->prefix
,
477 (char*)settings
[i
].setting
,
478 settings
[i
].filename_setting
->suffix
);
481 else strlcpy(buf
,(char*)settings
[i
].setting
,
482 settings
[i
].filename_setting
->max_len
);
489 static bool is_changed(int setting_id
)
491 const struct settings_list
*setting
= &settings
[setting_id
];
492 switch (setting
->flags
&F_T_MASK
)
495 return setting
->custom_setting
->is_changed(setting
->setting
,
496 setting
->default_val
.custom
);
500 if (setting
->flags
&F_DEF_ISFUNC
)
502 if (*(int*)setting
->setting
== setting
->default_val
.func())
505 else if (setting
->flags
&F_T_SOUND
)
507 if (*(int*)setting
->setting
==
508 sound_default(setting
->sound_setting
->setting
))
511 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
515 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
520 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
527 static bool settings_write_config(const char* filename
, int options
)
531 char value
[MAX_PATH
];
532 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
535 fdprintf(fd
, "# .cfg file created by rockbox %s - "
536 "http://www.rockbox.org\r\n\r\n", appsversion
);
537 for(i
=0; i
<nb_settings
; i
++)
539 if (settings
[i
].cfg_name
== NULL
)
545 case SETTINGS_SAVE_CHANGED
:
549 case SETTINGS_SAVE_SOUND
:
550 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
553 case SETTINGS_SAVE_THEME
:
554 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
557 #ifdef HAVE_RECORDING
558 case SETTINGS_SAVE_RECPRESETS
:
559 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
563 #if CONFIG_CODEC == SWCODEC
564 case SETTINGS_SAVE_EQPRESET
:
565 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
571 cfg_to_string(i
, value
, MAX_PATH
);
572 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
578 static void flush_global_status_callback(void *data
)
581 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
584 static void flush_config_block_callback(void *data
)
587 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
588 settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
592 * persist all runtime user settings to disk or RTC RAM
594 static void update_runtime(void)
598 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
599 global_status
.runtime
+= elapsed_secs
;
600 lasttime
+= (elapsed_secs
* HZ
);
602 if ( global_status
.runtime
> global_status
.topruntime
)
603 global_status
.topruntime
= global_status
.runtime
;
606 void status_save(void)
610 /* this will be done in the storage_callback if
611 target doesnt have rtc ram */
612 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
614 register_storage_idle_func(flush_global_status_callback
);
618 int settings_save(void)
622 /* this will be done in the storage_callback if
623 target doesnt have rtc ram */
624 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
626 register_storage_idle_func(flush_config_block_callback
);
630 bool settings_save_config(int options
)
632 char filename
[MAX_PATH
];
633 char *folder
, *namebase
;
636 case SETTINGS_SAVE_THEME
:
640 #ifdef HAVE_RECORDING
641 case SETTINGS_SAVE_RECPRESETS
:
642 folder
= RECPRESETS_DIR
;
643 namebase
= "recording";
646 #if CONFIG_CODEC == SWCODEC
647 case SETTINGS_SAVE_EQPRESET
:
652 case SETTINGS_SAVE_SOUND
:
653 folder
= ROCKBOX_DIR
;
657 folder
= ROCKBOX_DIR
;
661 create_numbered_filename(filename
, folder
, namebase
, ".cfg", 2
662 IF_CNFN_NUM_(, NULL
));
664 /* allow user to modify filename */
666 if (!kbd_input(filename
, sizeof filename
)) {
674 if (settings_write_config(filename
, options
))
675 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
677 splash(HZ
, ID2P(LANG_FAILED
));
681 /** Apply and Reset settings **/
684 #ifdef HAVE_LCD_BITMAP
686 * Applies the range infos stored in global_settings to
689 void settings_apply_pm_range(void)
693 /* depending on the scale mode (dBfs or percent) the values
694 of global_settings.peak_meter_dbfs have different meanings */
695 if (global_settings
.peak_meter_dbfs
)
697 /* convert to dBfs * 100 */
698 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
699 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
703 /* percent is stored directly -> no conversion */
704 pm_min
= global_settings
.peak_meter_min
;
705 pm_max
= global_settings
.peak_meter_max
;
708 /* apply the range */
709 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
711 #endif /* HAVE_LCD_BITMAP */
713 void sound_settings_apply(void)
715 #if CONFIG_CODEC == SWCODEC
716 sound_set_dsp_callback(dsp_callback
);
718 sound_set(SOUND_BASS
, global_settings
.bass
);
719 sound_set(SOUND_TREBLE
, global_settings
.treble
);
720 sound_set(SOUND_BALANCE
, global_settings
.balance
);
721 sound_set(SOUND_VOLUME
, global_settings
.volume
);
722 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
723 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
724 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
725 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
726 sound_set(SOUND_AVC
, global_settings
.avc
);
727 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
728 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
729 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
730 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
731 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
732 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
736 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
737 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
743 /* call this after loading a .wps/.rwps pr other skin files, so that the
744 * skin buffer is reset properly
746 void settings_apply_skins(void)
749 /* re-initialize the skin buffer before we start reloading skins */
751 #ifdef HAVE_LCD_BITMAP
752 skin_backdrop_init();
754 if ( global_settings
.sbs_file
[0] &&
755 global_settings
.sbs_file
[0] != 0xff )
757 snprintf(buf
, sizeof buf
, SBS_DIR
"/%s.sbs",
758 global_settings
.sbs_file
);
759 sb_skin_data_load(SCREEN_MAIN
, buf
, true);
763 sb_skin_data_load(SCREEN_MAIN
, NULL
, true);
766 if ( global_settings
.wps_file
[0] &&
767 global_settings
.wps_file
[0] != 0xff )
769 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
770 global_settings
.wps_file
);
771 wps_data_load(SCREEN_MAIN
, buf
, true);
775 wps_data_load(SCREEN_MAIN
, NULL
, true);
777 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
778 if ( global_settings
.rsbs_file
[0] &&
779 global_settings
.rsbs_file
[0] != 0xff ) {
780 snprintf(buf
, sizeof buf
, SBS_DIR
"/%s.rsbs",
781 global_settings
.rsbs_file
);
782 sb_skin_data_load(SCREEN_REMOTE
, buf
, true);
786 sb_skin_data_load(SCREEN_REMOTE
, NULL
, true);
788 if ( global_settings
.rwps_file
[0])
790 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
791 global_settings
.rwps_file
);
792 wps_data_load(SCREEN_REMOTE
, buf
, true);
796 wps_data_load(SCREEN_REMOTE
, NULL
, true);
799 viewportmanager_theme_changed(THEME_STATUSBAR
);
800 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
803 screens
[i
].backdrop_show(sb_get_backdrop(i
));
807 void settings_apply(bool read_disk
)
811 #if CONFIG_CODEC == SWCODEC
814 sound_settings_apply();
816 #ifdef HAVE_DISK_STORAGE
817 audio_set_buffer_margin(global_settings
.buffer_margin
);
820 #ifdef HAVE_LCD_CONTRAST
821 lcd_set_contrast(global_settings
.contrast
);
823 lcd_scroll_speed(global_settings
.scroll_speed
);
824 #ifdef HAVE_REMOTE_LCD
825 lcd_remote_set_contrast(global_settings
.remote_contrast
);
826 lcd_remote_set_invert_display(global_settings
.remote_invert
);
829 lcd_remote_set_flip(global_settings
.remote_flip_display
);
832 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
833 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
834 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
835 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
836 #ifdef HAVE_REMOTE_LCD_TICKING
837 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
839 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
841 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
843 #ifdef HAS_REMOTE_BUTTON_HOLD
844 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
846 #endif /* HAVE_REMOTE_LCD */
847 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
848 backlight_set_brightness(global_settings
.brightness
);
850 #ifdef HAVE_BACKLIGHT
851 backlight_set_timeout(global_settings
.backlight_timeout
);
853 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
855 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
856 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
857 backlight_set_fade_in(global_settings
.backlight_fade_in
);
858 backlight_set_fade_out(global_settings
.backlight_fade_out
);
861 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
862 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
864 #ifdef HAVE_BUTTON_LIGHT
865 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
867 #ifdef HAVE_DISK_STORAGE
868 storage_spindown(global_settings
.disk_spindown
);
870 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
871 dac_line_in(global_settings
.line_in
);
873 set_poweroff_timeout(global_settings
.poweroff
);
875 set_battery_capacity(global_settings
.battery_capacity
);
876 #if BATTERY_TYPES_COUNT > 1
877 set_battery_type(global_settings
.battery_type
);
880 #ifdef HAVE_LCD_BITMAP
881 #ifdef HAVE_LCD_INVERT
882 lcd_set_invert_display(global_settings
.invert
);
885 lcd_set_flip(global_settings
.flip_display
);
886 button_set_flip(global_settings
.flip_display
);
888 lcd_update(); /* refresh after flipping the screen */
889 settings_apply_pm_range();
890 peak_meter_init_times(
891 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
892 global_settings
.peak_meter_clip_hold
);
896 audiohw_enable_speaker(global_settings
.speaker_enabled
);
901 #ifdef HAVE_LCD_BITMAP
902 /* fonts need to be loaded before the WPS */
903 if ( global_settings
.font_file
[0]) {
904 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
905 global_settings
.font_file
);
906 if (font_load(NULL
, buf
) < 0)
911 #ifdef HAVE_REMOTE_LCD
912 if ( global_settings
.remote_font_file
[0]) {
913 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
914 global_settings
.remote_font_file
);
915 if (font_load_remoteui(buf
) < 0)
916 font_load_remoteui(NULL
);
919 font_load_remoteui(NULL
);
921 if ( global_settings
.kbd_file
[0]) {
922 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
923 global_settings
.kbd_file
);
930 if ( global_settings
.lang_file
[0]) {
931 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
932 global_settings
.lang_file
);
934 talk_init(); /* use voice of same language */
938 settings_apply_skins();
940 /* load the icon set */
943 #ifdef HAVE_LCD_COLOR
944 if (global_settings
.colors_file
[0])
945 read_color_theme_file();
949 #ifdef HAVE_LCD_COLOR
950 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
951 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
952 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
953 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
954 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
957 #ifdef HAVE_LCD_BITMAP
958 lcd_scroll_step(global_settings
.scroll_step
);
959 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
960 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
962 lcd_jump_scroll(global_settings
.jump_scroll
);
963 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
965 lcd_bidir_scroll(global_settings
.bidir_limit
);
966 lcd_scroll_delay(global_settings
.scroll_delay
);
969 set_codepage(global_settings
.default_codepage
);
971 #if CONFIG_CODEC == SWCODEC
972 #ifdef HAVE_CROSSFADE
973 audio_set_crossfade(global_settings
.crossfade
);
975 dsp_set_replaygain();
976 dsp_set_crossfeed(global_settings
.crossfeed
);
977 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
978 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
979 global_settings
.crossfeed_hf_attenuation
,
980 global_settings
.crossfeed_hf_cutoff
);
982 /* Configure software equalizer, hardware eq is handled in audio_init() */
983 dsp_set_eq(global_settings
.eq_enabled
);
984 dsp_set_eq_precut(global_settings
.eq_precut
);
985 for(i
= 0; i
< 5; i
++) {
989 dsp_dither_enable(global_settings
.dithering_enabled
);
990 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
991 dsp_set_compressor(global_settings
.compressor_threshold
,
992 global_settings
.compressor_makeup_gain
,
993 global_settings
.compressor_ratio
,
994 global_settings
.compressor_knee
,
995 global_settings
.compressor_release_time
);
998 #ifdef HAVE_SPDIF_POWER
999 spdif_power_enable(global_settings
.spdif_enable
);
1002 #ifdef HAVE_BACKLIGHT
1003 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
1004 #ifdef HAVE_REMOTE_LCD
1005 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
1007 #ifdef HAS_BUTTON_HOLD
1008 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
1010 #ifdef HAVE_LCD_SLEEP_SETTING
1011 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
1013 #endif /* HAVE_BACKLIGHT */
1015 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
1016 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
1019 #ifdef HAVE_USB_CHARGING_ENABLE
1020 usb_charging_enable(global_settings
.usb_charging
);
1023 #ifdef HAVE_TOUCHSCREEN
1024 touchscreen_set_mode(global_settings
.touch_mode
);
1025 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1028 /* This should stay last */
1029 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1030 enc_global_settings_apply();
1032 #ifdef HAVE_LCD_BITMAP
1033 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1034 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
);
1040 * reset all settings to their default value
1042 void reset_setting(const struct settings_list
*setting
, void *var
)
1044 switch (setting
->flags
&F_T_MASK
)
1047 setting
->custom_setting
->set_default(setting
->setting
,
1048 setting
->default_val
.custom
);
1052 if (setting
->flags
&F_DEF_ISFUNC
)
1053 *(int*)var
= setting
->default_val
.func();
1054 else if (setting
->flags
&F_T_SOUND
)
1055 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1056 else *(int*)var
= setting
->default_val
.int_
;
1059 *(bool*)var
= setting
->default_val
.bool_
;
1063 strlcpy((char*)var
, setting
->default_val
.charptr
,
1064 setting
->filename_setting
->max_len
);
1069 void settings_reset(void)
1073 for(i
=0; i
<nb_settings
; i
++)
1074 reset_setting(&settings
[i
], settings
[i
].setting
);
1075 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1076 enc_global_settings_reset();
1080 /** Changing setting values **/
1081 const struct settings_list
* find_setting(const void* variable
, int *id
)
1084 for(i
=0;i
<nb_settings
;i
++)
1086 if (settings
[i
].setting
== variable
)
1090 return &settings
[i
];
1096 bool set_bool(const char* string
, const bool* variable
)
1098 return set_bool_options(string
, variable
,
1099 (char *)STR(LANG_SET_BOOL_YES
),
1100 (char *)STR(LANG_SET_BOOL_NO
),
1105 bool set_bool_options(const char* string
, const bool* variable
,
1106 const char* yes_str
, int yes_voice
,
1107 const char* no_str
, int no_voice
,
1108 void (*function
)(bool))
1110 struct opt_items names
[] = {
1111 {(unsigned const char *)no_str
, no_voice
},
1112 {(unsigned const char *)yes_str
, yes_voice
}
1116 result
= set_option(string
, variable
, BOOL
, names
, 2,
1117 (void (*)(int))function
);
1121 bool set_int(const unsigned char* string
,
1124 const int* variable
,
1125 void (*function
)(int),
1129 const char* (*formatter
)(char*, size_t, int, const char*) )
1131 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1132 step
, min
, max
, formatter
, NULL
);
1135 bool set_int_ex(const unsigned char* string
,
1138 const int* variable
,
1139 void (*function
)(int),
1143 const char* (*formatter
)(char*, size_t, int, const char*),
1144 int32_t (*get_talk_id
)(int, int))
1147 struct settings_list item
;
1148 struct int_setting data
= {
1149 function
, voice_unit
, min
, max
, step
,
1150 formatter
, get_talk_id
1152 item
.int_setting
= &data
;
1153 item
.flags
= F_INT_SETTING
|F_T_INT
;
1155 item
.cfg_vals
= (char*)string
;
1156 item
.setting
= (void *)variable
;
1157 return option_screen(&item
, NULL
, false, NULL
);
1161 static const struct opt_items
*set_option_options
;
1162 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1164 (void)buf
, (void)unit
, (void)size
;
1165 return P2STR(set_option_options
[item
].string
);
1168 static int32_t set_option_get_talk_id(int value
, int unit
)
1171 return set_option_options
[value
].voice_id
;
1174 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1175 const struct opt_items
* options
,
1176 int numoptions
, void (*function
)(int))
1179 struct settings_list item
;
1180 struct int_setting data
= {
1181 function
, UNIT_INT
, 0, numoptions
-1, 1,
1182 set_option_formatter
, set_option_get_talk_id
1184 set_option_options
= options
;
1185 item
.int_setting
= &data
;
1186 item
.flags
= F_INT_SETTING
|F_T_INT
;
1188 item
.cfg_vals
= (char*)string
;
1189 item
.setting
= &temp
;
1191 temp
= *(bool*)variable
? 1: 0;
1193 temp
= *(int*)variable
;
1194 if (!option_screen(&item
, NULL
, false, NULL
))
1197 *(bool*)variable
= (temp
== 1);
1199 *(int*)variable
= temp
;
1206 void set_file(const char* filename
, char* setting
, int maxlen
)
1208 const char* fptr
= strrchr(filename
,'/');
1220 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1224 if(ptr
== fptr
) extlen
= 0;
1226 if (strncasecmp(ROCKBOX_DIR
, filename
, strlen(ROCKBOX_DIR
)) ||
1227 (len
-extlen
> maxlen
))
1230 strlcpy(setting
, fptr
, len
-extlen
+1);