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 ****************************************************************************/
35 #include "backlight.h"
39 #include "strcasestr.h"
42 #include "ata_idle_notify.h"
50 #ifdef HAVE_LCD_BITMAP
53 #include "peakmeter.h"
57 #include "powermgmt.h"
60 #include "rbunicode.h"
64 #include "settings_list.h"
65 #include "filetypes.h"
66 #include "option_select.h"
71 #include "skin_engine/skin_engine.h"
73 #include "statusbar-skinned.h"
74 #include "bootchart.h"
76 #if CONFIG_CODEC == MAS3507D
77 void dac_line_in(bool enable
);
79 struct user_settings global_settings
;
80 struct system_status global_status
;
82 #if CONFIG_CODEC == SWCODEC
86 #include "enc_config.h"
88 #endif /* CONFIG_CODEC == SWCODEC */
90 #define NVRAM_BLOCK_SIZE 44
92 #ifdef HAVE_LCD_BITMAP
98 #ifdef HAVE_REMOTE_LCD
99 #include "lcd-remote.h"
104 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
105 /* NVRAM is set out as
109 [3] stored variable count
111 [8-NVRAM_BLOCK_SIZE] data
113 #define NVRAM_DATA_START 8
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;
122 int fd
= open(get_user_file_path(NVRAM_FILE
, IS_FILE
|NEED_WRITE
,
123 path
, sizeof(path
)), O_RDONLY
);
127 memset(buf
,0,max_len
);
128 bytes
= read(fd
,buf
,max_len
);
130 if (bytes
< 8) /* min is 8 bytes,magic, ver, vars, crc32 */
133 memset(buf
,0,max_len
);
135 for (i
=0; i
< max_len
; i
++ )
136 buf
[i
] = rtc_read(0x14+i
);
138 /* check magic, version */
139 if ((buf
[0] != 'R') || (buf
[1] != 'b')
140 || (buf
[2] != NVRAM_CONFIG_VERSION
))
143 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
144 max_len
-NVRAM_DATA_START
-1,0xffffffff);
145 if (memcmp(&crc32
,&buf
[4],4))
147 /* all good, so read in the settings */
149 buf_pos
= NVRAM_DATA_START
;
150 for(i
=0; i
<nb_settings
; i
++)
152 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
153 >>F_NVRAM_MASK_SHIFT
;
156 if ((var_count
>0) && (buf_pos
<max_len
))
158 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
159 buf_pos
+= nvram_bytes
;
162 else /* should only happen when new items are added to the end */
164 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
170 static bool write_nvram_data(char* buf
, int max_len
)
172 unsigned crc32
= 0xffffffff;
173 int i
= 0, buf_pos
= 0;
179 memset(buf
,0,max_len
);
181 buf
[0] = 'R'; buf
[1] = 'b';
182 buf
[2] = NVRAM_CONFIG_VERSION
;
183 buf_pos
= NVRAM_DATA_START
;
184 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
186 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
187 >>F_NVRAM_MASK_SHIFT
;
190 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
191 buf_pos
+= nvram_bytes
;
195 /* count and crc32 */
197 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
198 max_len
-NVRAM_DATA_START
-1,0xffffffff);
199 memcpy(&buf
[4],&crc32
,4);
201 fd
= open(get_user_file_path(NVRAM_FILE
, IS_FILE
|NEED_WRITE
,
202 path
, sizeof(path
)),O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
205 int len
= write(fd
,buf
,max_len
);
211 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
212 that it would write a number of bytes at a time since the RTC chip
213 supports that, but this will have to do for now 8-) */
214 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
215 int r
= rtc_write(0x14+i
, buf
[i
]);
223 /** Reading from a config file **/
225 * load settings from disk or RTC RAM
227 void settings_load(int which
)
229 if (which
&SETTINGS_RTC
)
230 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
231 if (which
&SETTINGS_HD
)
235 file
= get_user_file_path(CONFIGFILE
, IS_FILE
|NEED_WRITE
, path
, sizeof(path
));
236 settings_load_config(file
, false);
237 file
= get_user_file_path(FIXEDSETTINGSFILE
, IS_FILE
, path
, sizeof(path
));
238 settings_load_config(file
, false);
242 static bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
244 const char* start
= settings
[setting_id
].cfg_vals
;
250 end
= strchr(start
, ',');
253 if (!strcmp(str
, start
))
260 strlcpy(temp
, start
, end
-start
+1);
261 if (!strcmp(str
, temp
))
272 bool settings_load_config(const char* file
, bool apply
)
279 fd
= open_utf8(file
, O_RDONLY
);
283 while (read_line(fd
, line
, sizeof line
) > 0)
285 if (!settings_parseline(line
, &name
, &value
))
287 for(i
=0; i
<nb_settings
; i
++)
289 if (settings
[i
].cfg_name
== NULL
)
291 if (!strcasecmp(name
,settings
[i
].cfg_name
))
293 switch (settings
[i
].flags
&F_T_MASK
)
296 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
300 #ifdef HAVE_LCD_COLOR
301 if (settings
[i
].flags
&F_RGB
)
302 hex_to_rgb(value
, (int*)settings
[i
].setting
);
305 if (settings
[i
].cfg_vals
== NULL
)
307 *(int*)settings
[i
].setting
= atoi(value
);
311 int temp
, *v
= (int*)settings
[i
].setting
;
312 bool found
= cfg_string_to_int(i
, &temp
, value
);
315 if (settings
[i
].flags
&F_TABLE_SETTING
)
316 *v
= settings
[i
].table_setting
->values
[temp
];
321 { /* atoi breaks choice settings because they
322 * don't have int-like values, and would
323 * fall back to the first value (i.e. 0)
325 if (!(settings
[i
].flags
&F_CHOICE_SETTING
))
333 if (cfg_string_to_int(i
,&temp
,value
))
334 *(bool*)settings
[i
].setting
= (temp
!=0);
335 if (settings
[i
].bool_setting
->option_callback
)
336 settings
[i
].bool_setting
->option_callback(temp
!=0);
342 char storage
[MAX_PATH
];
343 if (settings
[i
].filename_setting
->prefix
)
345 const char *dir
= settings
[i
].filename_setting
->prefix
;
346 size_t len
= strlen(dir
);
347 if (!strncasecmp(value
, dir
, len
))
349 strlcpy(storage
, &value
[len
], MAX_PATH
);
351 else strlcpy(storage
, value
, MAX_PATH
);
353 else strlcpy(storage
, value
, MAX_PATH
);
354 if (settings
[i
].filename_setting
->suffix
)
356 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
359 strlcpy((char*)settings
[i
].setting
, storage
,
360 settings
[i
].filename_setting
->max_len
);
365 } /* if (!strcmp(name,settings[i].cfg_name)) */
372 settings_apply(true);
373 settings_apply_skins();
378 /** Writing to a config file and saving settings **/
380 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
382 int flags
= settings
[setting_id
].flags
;
383 const char* start
= settings
[setting_id
].cfg_vals
;
387 if ((flags
&F_T_MASK
)==F_T_INT
&&
388 flags
&F_TABLE_SETTING
)
390 const int *value
= settings
[setting_id
].table_setting
->values
;
393 end
= strchr(start
,',');
394 if (value
[count
] == val
)
397 strlcpy(buf
, start
, buf_len
);
400 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
401 strlcpy(buf
, start
, len
+1);
417 start
= strchr(start
,',');
423 end
= strchr(start
,',');
425 strlcpy(buf
, start
, buf_len
);
428 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
429 strlcpy(buf
, start
, len
+1);
434 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
436 switch (settings
[i
].flags
&F_T_MASK
)
439 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
444 #ifdef HAVE_LCD_COLOR
445 if (settings
[i
].flags
&F_RGB
)
447 int colour
= *(int*)settings
[i
].setting
;
448 snprintf(buf
,buf_len
,"%02x%02x%02x",
449 (int)RGB_UNPACK_RED(colour
),
450 (int)RGB_UNPACK_GREEN(colour
),
451 (int)RGB_UNPACK_BLUE(colour
));
455 if (settings
[i
].cfg_vals
== NULL
)
457 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
461 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
462 buf
, buf_len
) == false)
464 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
472 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
476 if (((char*)settings
[i
].setting
)[0]
477 && settings
[i
].filename_setting
->prefix
)
479 if (((char*)settings
[i
].setting
)[0] == '-')
486 snprintf(buf
,buf_len
,"%s%s%s",
487 settings
[i
].filename_setting
->prefix
,
488 (char*)settings
[i
].setting
,
489 settings
[i
].filename_setting
->suffix
);
492 else strlcpy(buf
,(char*)settings
[i
].setting
,
493 settings
[i
].filename_setting
->max_len
);
500 static bool is_changed(int setting_id
)
502 const struct settings_list
*setting
= &settings
[setting_id
];
503 switch (setting
->flags
&F_T_MASK
)
506 return setting
->custom_setting
->is_changed(setting
->setting
,
507 setting
->default_val
.custom
);
511 if (setting
->flags
&F_DEF_ISFUNC
)
513 if (*(int*)setting
->setting
== setting
->default_val
.func())
516 else if (setting
->flags
&F_T_SOUND
)
518 if (*(int*)setting
->setting
==
519 sound_default(setting
->sound_setting
->setting
))
522 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
526 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
531 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
538 static bool settings_write_config(const char* filename
, int options
)
542 char value
[MAX_PATH
];
543 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
546 fdprintf(fd
, "# .cfg file created by rockbox %s - "
547 "http://www.rockbox.org\r\n\r\n", rbversion
);
548 for(i
=0; i
<nb_settings
; i
++)
550 if (settings
[i
].cfg_name
== NULL
)
556 case SETTINGS_SAVE_CHANGED
:
560 case SETTINGS_SAVE_SOUND
:
561 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
564 case SETTINGS_SAVE_THEME
:
565 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
568 #ifdef HAVE_RECORDING
569 case SETTINGS_SAVE_RECPRESETS
:
570 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
574 #if CONFIG_CODEC == SWCODEC
575 case SETTINGS_SAVE_EQPRESET
:
576 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
582 cfg_to_string(i
, value
, MAX_PATH
);
583 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
589 static void flush_global_status_callback(void *data
)
592 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
595 static void flush_config_block_callback(void *data
)
599 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
600 settings_write_config(
601 get_user_file_path(CONFIGFILE
, IS_FILE
|NEED_WRITE
, path
, sizeof(path
)),
602 SETTINGS_SAVE_CHANGED
);
606 * persist all runtime user settings to disk or RTC RAM
608 static void update_runtime(void)
612 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
613 global_status
.runtime
+= elapsed_secs
;
614 lasttime
+= (elapsed_secs
* HZ
);
616 if ( global_status
.runtime
> global_status
.topruntime
)
617 global_status
.topruntime
= global_status
.runtime
;
620 void status_save(void)
624 /* this will be done in the storage_callback if
625 target doesnt have rtc ram */
626 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
628 register_storage_idle_func(flush_global_status_callback
);
632 int settings_save(void)
636 /* this will be done in the storage_callback if
637 target doesnt have rtc ram */
638 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
640 register_storage_idle_func(flush_config_block_callback
);
644 bool settings_save_config(int options
)
646 char filename
[MAX_PATH
], path
[MAX_PATH
];
647 const char *folder
, *namebase
;
650 case SETTINGS_SAVE_THEME
:
654 #ifdef HAVE_RECORDING
655 case SETTINGS_SAVE_RECPRESETS
:
656 folder
= RECPRESETS_DIR
;
657 namebase
= "recording";
660 #if CONFIG_CODEC == SWCODEC
661 case SETTINGS_SAVE_EQPRESET
:
666 case SETTINGS_SAVE_SOUND
:
667 folder
= ROCKBOX_DIR
;
671 folder
= ROCKBOX_DIR
;
676 folder
= get_user_file_path(folder
, NEED_WRITE
, path
, sizeof(path
));
677 create_numbered_filename(filename
, folder
, namebase
, ".cfg", 2
678 IF_CNFN_NUM_(, NULL
));
680 /* allow user to modify filename */
682 if (!kbd_input(filename
, sizeof filename
)) {
690 if (settings_write_config(filename
, options
))
691 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
693 splash(HZ
, ID2P(LANG_FAILED
));
697 /** Apply and Reset settings **/
700 #ifdef HAVE_LCD_BITMAP
702 * Applies the range infos stored in global_settings to
705 void settings_apply_pm_range(void)
709 /* depending on the scale mode (dBfs or percent) the values
710 of global_settings.peak_meter_dbfs have different meanings */
711 if (global_settings
.peak_meter_dbfs
)
713 /* convert to dBfs * 100 */
714 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
715 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
719 /* percent is stored directly -> no conversion */
720 pm_min
= global_settings
.peak_meter_min
;
721 pm_max
= global_settings
.peak_meter_max
;
724 /* apply the range */
725 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
727 #endif /* HAVE_LCD_BITMAP */
729 void sound_settings_apply(void)
731 #if CONFIG_CODEC == SWCODEC
732 sound_set_dsp_callback(dsp_callback
);
734 #ifdef AUDIOHW_HAVE_BASS
735 sound_set(SOUND_BASS
, global_settings
.bass
);
737 #ifdef AUDIOHW_HAVE_TREBLE
738 sound_set(SOUND_TREBLE
, global_settings
.treble
);
740 sound_set(SOUND_BALANCE
, global_settings
.balance
);
741 sound_set(SOUND_VOLUME
, global_settings
.volume
);
742 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
743 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
744 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
745 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
746 sound_set(SOUND_AVC
, global_settings
.avc
);
747 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
748 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
749 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
750 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
751 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
752 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
754 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
755 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
757 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
758 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
760 #ifdef AUDIOHW_HAVE_DEPTH_3D
761 sound_set(SOUND_DEPTH_3D
, global_settings
.depth_3d
);
763 #ifdef AUDIOHW_HAVE_EQ
766 for (b
= 0; b
< AUDIOHW_EQ_BAND_NUM
; b
++)
768 int setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_GAIN
);
769 sound_set(setting
, global_settings
.hw_eq_bands
[b
].gain
);
771 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
772 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_FREQUENCY
);
774 sound_set(setting
, global_settings
.hw_eq_bands
[b
].frequency
);
775 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
776 #ifdef AUDIOHW_HAVE_EQ_WIDTH
777 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_WIDTH
);
779 sound_set(setting
, global_settings
.hw_eq_bands
[b
].width
);
780 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
785 void settings_apply(bool read_disk
)
787 #ifdef HAVE_LCD_BITMAP
790 #if CONFIG_CODEC == SWCODEC
793 sound_settings_apply();
795 #ifdef HAVE_DISK_STORAGE
796 audio_set_buffer_margin(global_settings
.buffer_margin
);
799 #ifdef HAVE_LCD_CONTRAST
800 lcd_set_contrast(global_settings
.contrast
);
802 lcd_scroll_speed(global_settings
.scroll_speed
);
803 #ifdef HAVE_REMOTE_LCD
804 lcd_remote_set_contrast(global_settings
.remote_contrast
);
805 lcd_remote_set_invert_display(global_settings
.remote_invert
);
808 lcd_remote_set_flip(global_settings
.remote_flip_display
);
811 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
812 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
813 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
814 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
815 #ifdef HAVE_REMOTE_LCD_TICKING
816 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
818 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
820 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
822 #ifdef HAS_REMOTE_BUTTON_HOLD
823 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
825 #endif /* HAVE_REMOTE_LCD */
826 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
827 backlight_set_brightness(global_settings
.brightness
);
829 #ifdef HAVE_BACKLIGHT
830 backlight_set_timeout(global_settings
.backlight_timeout
);
832 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
834 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
835 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
836 backlight_set_fade_in(global_settings
.backlight_fade_in
);
837 backlight_set_fade_out(global_settings
.backlight_fade_out
);
840 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
841 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
843 #ifdef HAVE_BUTTON_LIGHT
844 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
846 #ifdef HAVE_DISK_STORAGE
847 storage_spindown(global_settings
.disk_spindown
);
849 #if (CONFIG_CODEC == MAS3507D) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
850 dac_line_in(global_settings
.line_in
);
852 set_poweroff_timeout(global_settings
.poweroff
);
854 #if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
855 /* only call if it's really exchangable */
856 set_battery_capacity(global_settings
.battery_capacity
);
859 #if BATTERY_TYPES_COUNT > 1
860 set_battery_type(global_settings
.battery_type
);
863 #ifdef HAVE_LCD_BITMAP
864 #ifdef HAVE_LCD_INVERT
865 lcd_set_invert_display(global_settings
.invert
);
868 lcd_set_flip(global_settings
.flip_display
);
869 button_set_flip(global_settings
.flip_display
);
871 lcd_update(); /* refresh after flipping the screen */
872 settings_apply_pm_range();
873 peak_meter_init_times(
874 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
875 global_settings
.peak_meter_clip_hold
);
879 audiohw_enable_speaker(global_settings
.speaker_enabled
);
885 #ifdef HAVE_LCD_BITMAP
887 const char *font_path
= get_user_file_path(FONT_DIR
, 0, dir
, sizeof(dir
));
888 /* fonts need to be loaded before the WPS */
889 if (global_settings
.font_file
[0]
890 && global_settings
.font_file
[0] != '-') {
892 snprintf(buf
, sizeof buf
, "%s/%s.fnt", font_path
,
893 global_settings
.font_file
);
894 CHART2(">font_load ", global_settings
.font_file
);
895 rc
= font_load(NULL
, buf
);
896 CHART2("<font_load ", global_settings
.font_file
);
902 #ifdef HAVE_REMOTE_LCD
903 if ( global_settings
.remote_font_file
[0]
904 && global_settings
.remote_font_file
[0] != '-') {
905 snprintf(buf
, sizeof buf
, "%s/%s.fnt", font_path
,
906 global_settings
.remote_font_file
);
907 CHART2(">font_load_remoteui ", global_settings
.remote_font_file
);
908 rc
= font_load_remoteui(buf
);
909 CHART2("<font_load_remoteui ", global_settings
.remote_font_file
);
911 font_load_remoteui(NULL
);
914 font_load_remoteui(NULL
);
916 if ( global_settings
.kbd_file
[0]) {
917 snprintf(buf
, sizeof buf
, "%s/%s.kbd",
918 get_user_file_path(ROCKBOX_DIR
, 0, dir
, sizeof(dir
)),
919 global_settings
.kbd_file
);
926 #endif /* HAVE_LCD_BITMAP */
927 /* no get_user_file_path() here because we don't really support
928 * langs that don't come with rockbox */
929 if ( global_settings
.lang_file
[0]) {
930 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
931 global_settings
.lang_file
);
932 CHART(">lang_core_load");
934 CHART("<lang_core_load");
936 talk_init(); /* use voice of same language */
940 /* load the icon set */
941 CHART(">icons_init");
943 CHART("<icons_init");
945 #ifdef HAVE_LCD_COLOR
946 if (global_settings
.colors_file
[0])
948 CHART(">read_color_theme_file");
949 read_color_theme_file();
950 CHART("<read_color_theme_file");
954 #ifdef HAVE_LCD_COLOR
955 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
956 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
957 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
958 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
959 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
962 #ifdef HAVE_LCD_BITMAP
963 lcd_scroll_step(global_settings
.scroll_step
);
964 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
965 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
967 lcd_bidir_scroll(global_settings
.bidir_limit
);
968 lcd_scroll_delay(global_settings
.scroll_delay
);
971 CHART(">set_codepage");
972 set_codepage(global_settings
.default_codepage
);
973 CHART("<set_codepage");
975 #if CONFIG_CODEC == SWCODEC
976 #ifdef HAVE_CROSSFADE
977 audio_set_crossfade(global_settings
.crossfade
);
979 dsp_set_replaygain();
980 dsp_set_crossfeed(global_settings
.crossfeed
);
981 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
982 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
983 global_settings
.crossfeed_hf_attenuation
,
984 global_settings
.crossfeed_hf_cutoff
);
986 /* Configure software equalizer, hardware eq is handled in audio_init() */
987 dsp_set_eq(global_settings
.eq_enabled
);
988 dsp_set_eq_precut(global_settings
.eq_precut
);
989 for(i
= 0; i
< 5; i
++) {
993 dsp_dither_enable(global_settings
.dithering_enabled
);
994 #ifdef HAVE_PITCHSCREEN
995 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
997 dsp_set_compressor(global_settings
.compressor_threshold
,
998 global_settings
.compressor_makeup_gain
,
999 global_settings
.compressor_ratio
,
1000 global_settings
.compressor_knee
,
1001 global_settings
.compressor_release_time
);
1004 #ifdef HAVE_SPDIF_POWER
1005 spdif_power_enable(global_settings
.spdif_enable
);
1008 #ifdef HAVE_BACKLIGHT
1009 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
1010 #ifdef HAVE_REMOTE_LCD
1011 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
1013 #ifdef HAS_BUTTON_HOLD
1014 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
1016 #ifdef HAVE_LCD_SLEEP_SETTING
1017 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
1019 #endif /* HAVE_BACKLIGHT */
1021 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
1022 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
1025 #ifdef HAVE_USB_CHARGING_ENABLE
1026 usb_charging_enable(global_settings
.usb_charging
);
1029 #ifdef HAVE_TOUCHSCREEN
1030 touchscreen_set_mode(global_settings
.touch_mode
);
1031 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1034 /* This should stay last */
1035 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1036 enc_global_settings_apply();
1038 #ifdef HAVE_LCD_BITMAP
1039 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1040 CHART(">viewportmanager_theme_changed");
1041 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
|THEME_BUTTONBAR
);
1042 CHART("<viewportmanager_theme_changed");
1048 * reset all settings to their default value
1050 void reset_setting(const struct settings_list
*setting
, void *var
)
1052 switch (setting
->flags
&F_T_MASK
)
1055 setting
->custom_setting
->set_default(setting
->setting
,
1056 setting
->default_val
.custom
);
1060 if (setting
->flags
&F_DEF_ISFUNC
)
1061 *(int*)var
= setting
->default_val
.func();
1062 else if (setting
->flags
&F_T_SOUND
)
1063 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1064 else *(int*)var
= setting
->default_val
.int_
;
1067 *(bool*)var
= setting
->default_val
.bool_
;
1071 strlcpy((char*)var
, setting
->default_val
.charptr
,
1072 setting
->filename_setting
->max_len
);
1077 void settings_reset(void)
1081 for(i
=0; i
<nb_settings
; i
++)
1082 reset_setting(&settings
[i
], settings
[i
].setting
);
1083 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1084 enc_global_settings_reset();
1088 /** Changing setting values **/
1089 const struct settings_list
* find_setting(const void* variable
, int *id
)
1092 for(i
=0;i
<nb_settings
;i
++)
1094 if (settings
[i
].setting
== variable
)
1098 return &settings
[i
];
1104 bool set_bool(const char* string
, const bool* variable
)
1106 return set_bool_options(string
, variable
,
1107 (char *)STR(LANG_SET_BOOL_YES
),
1108 (char *)STR(LANG_SET_BOOL_NO
),
1113 bool set_bool_options(const char* string
, const bool* variable
,
1114 const char* yes_str
, int yes_voice
,
1115 const char* no_str
, int no_voice
,
1116 void (*function
)(bool))
1118 struct opt_items names
[] = {
1119 {(unsigned const char *)no_str
, no_voice
},
1120 {(unsigned const char *)yes_str
, yes_voice
}
1124 result
= set_option(string
, variable
, BOOL
, names
, 2,
1125 (void (*)(int))function
);
1129 bool set_int(const unsigned char* string
,
1132 const int* variable
,
1133 void (*function
)(int),
1137 const char* (*formatter
)(char*, size_t, int, const char*) )
1139 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1140 step
, min
, max
, formatter
, NULL
);
1143 bool set_int_ex(const unsigned char* string
,
1146 const int* variable
,
1147 void (*function
)(int),
1151 const char* (*formatter
)(char*, size_t, int, const char*),
1152 int32_t (*get_talk_id
)(int, int))
1155 struct settings_list item
;
1156 struct int_setting data
= {
1157 function
, voice_unit
, min
, max
, step
,
1158 formatter
, get_talk_id
1160 item
.int_setting
= &data
;
1161 item
.flags
= F_INT_SETTING
|F_T_INT
;
1163 item
.cfg_vals
= (char*)string
;
1164 item
.setting
= (void *)variable
;
1165 return option_screen(&item
, NULL
, false, NULL
);
1169 static const struct opt_items
*set_option_options
;
1170 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1172 (void)buf
, (void)unit
, (void)size
;
1173 return P2STR(set_option_options
[item
].string
);
1176 static int32_t set_option_get_talk_id(int value
, int unit
)
1179 return set_option_options
[value
].voice_id
;
1182 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1183 const struct opt_items
* options
,
1184 int numoptions
, void (*function
)(int))
1187 struct settings_list item
;
1188 struct int_setting data
= {
1189 function
, UNIT_INT
, 0, numoptions
-1, 1,
1190 set_option_formatter
, set_option_get_talk_id
1192 set_option_options
= options
;
1193 item
.int_setting
= &data
;
1194 item
.flags
= F_INT_SETTING
|F_T_INT
;
1196 item
.cfg_vals
= (char*)string
;
1197 item
.setting
= &temp
;
1199 temp
= *(bool*)variable
? 1: 0;
1201 temp
= *(int*)variable
;
1202 if (!option_screen(&item
, NULL
, false, NULL
))
1206 *(bool*)variable
= (temp
== 1);
1208 *(int*)variable
= temp
;
1215 * Takes filename, removes the directory and the extension,
1216 * and then copies the basename into setting, unless the basename exceeds maxlen
1218 void set_file(const char* filename
, char* setting
, const int maxlen
)
1220 const char* fptr
= strrchr(filename
,'/');
1230 extptr
= strrchr(fptr
, '.');
1232 if (!extptr
|| extptr
< fptr
)
1235 extlen
= strlen(extptr
);
1237 len
= strlen(fptr
) - extlen
+ 1;
1239 /* error if filename isn't in ROCKBOX_DIR */
1243 strlcpy(setting
, fptr
, len
);