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
83 #include "dsp_proc_settings.h"
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;
121 int fd
= open(NVRAM_FILE
, O_RDONLY
);
125 memset(buf
,0,max_len
);
126 bytes
= read(fd
,buf
,max_len
);
128 if (bytes
< 8) /* min is 8 bytes,magic, ver, vars, crc32 */
131 memset(buf
,0,max_len
);
133 for (i
=0; i
< max_len
; i
++ )
134 buf
[i
] = rtc_read(0x14+i
);
136 /* check magic, version */
137 if ((buf
[0] != 'R') || (buf
[1] != 'b')
138 || (buf
[2] != NVRAM_CONFIG_VERSION
))
141 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
142 max_len
-NVRAM_DATA_START
-1,0xffffffff);
143 if (memcmp(&crc32
,&buf
[4],4))
145 /* all good, so read in the settings */
147 buf_pos
= NVRAM_DATA_START
;
148 for(i
=0; i
<nb_settings
; i
++)
150 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
151 >>F_NVRAM_MASK_SHIFT
;
154 if ((var_count
>0) && (buf_pos
<max_len
))
156 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
157 buf_pos
+= nvram_bytes
;
160 else /* should only happen when new items are added to the end */
162 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
168 static bool write_nvram_data(char* buf
, int max_len
)
170 unsigned crc32
= 0xffffffff;
171 int i
= 0, buf_pos
= 0;
176 memset(buf
,0,max_len
);
178 buf
[0] = 'R'; buf
[1] = 'b';
179 buf
[2] = NVRAM_CONFIG_VERSION
;
180 buf_pos
= NVRAM_DATA_START
;
181 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
183 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
184 >>F_NVRAM_MASK_SHIFT
;
187 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
188 buf_pos
+= nvram_bytes
;
192 /* count and crc32 */
194 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
195 max_len
-NVRAM_DATA_START
-1,0xffffffff);
196 memcpy(&buf
[4],&crc32
,4);
198 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
201 int len
= write(fd
,buf
,max_len
);
207 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
208 that it would write a number of bytes at a time since the RTC chip
209 supports that, but this will have to do for now 8-) */
210 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
211 int r
= rtc_write(0x14+i
, buf
[i
]);
219 /** Reading from a config file **/
221 * load settings from disk or RTC RAM
223 void settings_load(int which
)
225 if (which
&SETTINGS_RTC
)
226 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
227 if (which
&SETTINGS_HD
)
229 settings_load_config(CONFIGFILE
, false);
230 settings_load_config(FIXEDSETTINGSFILE
, false);
234 bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
236 const char* start
= settings
[setting_id
].cfg_vals
;
242 end
= strchr(start
, ',');
245 if (!strcmp(str
, start
))
252 strlcpy(temp
, start
, end
-start
+1);
253 if (!strcmp(str
, temp
))
264 bool settings_load_config(const char* file
, bool apply
)
271 bool theme_changed
= false;
272 fd
= open_utf8(file
, O_RDONLY
);
276 while (read_line(fd
, line
, sizeof line
) > 0)
278 if (!settings_parseline(line
, &name
, &value
))
280 for(i
=0; i
<nb_settings
; i
++)
282 if (settings
[i
].cfg_name
== NULL
)
284 if (!strcasecmp(name
,settings
[i
].cfg_name
))
286 if (settings
[i
].flags
&F_THEMESETTING
)
287 theme_changed
= true;
288 switch (settings
[i
].flags
&F_T_MASK
)
291 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
295 #ifdef HAVE_LCD_COLOR
296 if (settings
[i
].flags
&F_RGB
)
297 hex_to_rgb(value
, (int*)settings
[i
].setting
);
300 if (settings
[i
].cfg_vals
== NULL
)
302 *(int*)settings
[i
].setting
= atoi(value
);
306 int temp
, *v
= (int*)settings
[i
].setting
;
307 bool found
= cfg_string_to_int(i
, &temp
, value
);
310 if (settings
[i
].flags
&F_TABLE_SETTING
)
311 *v
= settings
[i
].table_setting
->values
[temp
];
316 { /* atoi breaks choice settings because they
317 * don't have int-like values, and would
318 * fall back to the first value (i.e. 0)
320 if (!(settings
[i
].flags
&F_CHOICE_SETTING
))
328 if (cfg_string_to_int(i
,&temp
,value
))
329 *(bool*)settings
[i
].setting
= (temp
!=0);
330 if (settings
[i
].bool_setting
->option_callback
)
331 settings
[i
].bool_setting
->option_callback(temp
!=0);
337 char storage
[MAX_PATH
];
338 if (settings
[i
].filename_setting
->prefix
)
340 const char *dir
= settings
[i
].filename_setting
->prefix
;
341 size_t len
= strlen(dir
);
342 if (!strncasecmp(value
, dir
, len
))
344 strlcpy(storage
, &value
[len
], MAX_PATH
);
346 else strlcpy(storage
, value
, MAX_PATH
);
348 else strlcpy(storage
, value
, MAX_PATH
);
349 if (settings
[i
].filename_setting
->suffix
)
351 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
354 strlcpy((char*)settings
[i
].setting
, storage
,
355 settings
[i
].filename_setting
->max_len
);
360 } /* if (!strcmp(name,settings[i].cfg_name)) */
368 settings_apply(true);
370 settings_apply_skins();
375 /** Writing to a config file and saving settings **/
377 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
379 int flags
= settings
[setting_id
].flags
;
380 const char* start
= settings
[setting_id
].cfg_vals
;
384 if ((flags
&F_T_MASK
)==F_T_INT
&&
385 flags
&F_TABLE_SETTING
)
387 const int *value
= settings
[setting_id
].table_setting
->values
;
390 end
= strchr(start
,',');
391 if (value
[count
] == val
)
394 strlcpy(buf
, start
, buf_len
);
397 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
398 strlcpy(buf
, start
, len
+1);
414 start
= strchr(start
,',');
420 end
= strchr(start
,',');
422 strlcpy(buf
, start
, buf_len
);
425 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
426 strlcpy(buf
, start
, len
+1);
431 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
433 switch (settings
[i
].flags
&F_T_MASK
)
436 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
441 #ifdef HAVE_LCD_COLOR
442 if (settings
[i
].flags
&F_RGB
)
444 int colour
= *(int*)settings
[i
].setting
;
445 snprintf(buf
,buf_len
,"%02x%02x%02x",
446 (int)RGB_UNPACK_RED(colour
),
447 (int)RGB_UNPACK_GREEN(colour
),
448 (int)RGB_UNPACK_BLUE(colour
));
452 if (settings
[i
].cfg_vals
== NULL
)
454 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
458 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
459 buf
, buf_len
) == false)
461 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
469 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
473 if (((char*)settings
[i
].setting
)[0]
474 && settings
[i
].filename_setting
->prefix
)
476 if (((char*)settings
[i
].setting
)[0] == '-')
483 snprintf(buf
,buf_len
,"%s%s%s",
484 settings
[i
].filename_setting
->prefix
,
485 (char*)settings
[i
].setting
,
486 settings
[i
].filename_setting
->suffix
);
489 else strlcpy(buf
,(char*)settings
[i
].setting
,
490 settings
[i
].filename_setting
->max_len
);
497 static bool is_changed(int setting_id
)
499 const struct settings_list
*setting
= &settings
[setting_id
];
500 switch (setting
->flags
&F_T_MASK
)
503 return setting
->custom_setting
->is_changed(setting
->setting
,
504 setting
->default_val
.custom
);
508 if (setting
->flags
&F_DEF_ISFUNC
)
510 if (*(int*)setting
->setting
== setting
->default_val
.func())
513 else if (setting
->flags
&F_T_SOUND
)
515 if (*(int*)setting
->setting
==
516 sound_default(setting
->sound_setting
->setting
))
519 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
523 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
528 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
535 static bool settings_write_config(const char* filename
, int options
)
539 char value
[MAX_PATH
];
540 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
543 fdprintf(fd
, "# .cfg file created by rockbox %s - "
544 "http://www.rockbox.org\r\n\r\n", rbversion
);
545 for(i
=0; i
<nb_settings
; i
++)
547 if (settings
[i
].cfg_name
== NULL
)
553 case SETTINGS_SAVE_CHANGED
:
557 case SETTINGS_SAVE_SOUND
:
558 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
561 case SETTINGS_SAVE_THEME
:
562 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
565 #ifdef HAVE_RECORDING
566 case SETTINGS_SAVE_RECPRESETS
:
567 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
571 #if CONFIG_CODEC == SWCODEC
572 case SETTINGS_SAVE_EQPRESET
:
573 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
579 cfg_to_string(i
, value
, MAX_PATH
);
580 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
586 static void flush_global_status_callback(void *data
)
589 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
592 static void flush_config_block_callback(void *data
)
595 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
596 settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
600 * persist all runtime user settings to disk or RTC RAM
602 static void update_runtime(void)
606 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
607 global_status
.runtime
+= elapsed_secs
;
608 lasttime
+= (elapsed_secs
* HZ
);
610 if ( global_status
.runtime
> global_status
.topruntime
)
611 global_status
.topruntime
= global_status
.runtime
;
614 void status_save(void)
618 /* this will be done in the storage_callback if
619 target doesnt have rtc ram */
620 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
622 register_storage_idle_func(flush_global_status_callback
);
626 int settings_save(void)
630 /* this will be done in the storage_callback if
631 target doesnt have rtc ram */
632 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
634 register_storage_idle_func(flush_config_block_callback
);
638 bool settings_save_config(int options
)
640 char filename
[MAX_PATH
];
641 const char *folder
, *namebase
;
644 case SETTINGS_SAVE_THEME
:
648 #ifdef HAVE_RECORDING
649 case SETTINGS_SAVE_RECPRESETS
:
650 folder
= RECPRESETS_DIR
;
651 namebase
= "recording";
654 #if CONFIG_CODEC == SWCODEC
655 case SETTINGS_SAVE_EQPRESET
:
660 case SETTINGS_SAVE_SOUND
:
661 folder
= ROCKBOX_DIR
;
665 folder
= ROCKBOX_DIR
;
669 create_numbered_filename(filename
, folder
, namebase
, ".cfg", 2
670 IF_CNFN_NUM_(, NULL
));
672 /* allow user to modify filename */
674 if (!kbd_input(filename
, sizeof filename
)) {
682 if (settings_write_config(filename
, options
))
683 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
685 splash(HZ
, ID2P(LANG_FAILED
));
689 /** Apply and Reset settings **/
692 #ifdef HAVE_LCD_BITMAP
694 * Applies the range infos stored in global_settings to
697 void settings_apply_pm_range(void)
701 /* depending on the scale mode (dBfs or percent) the values
702 of global_settings.peak_meter_dbfs have different meanings */
703 if (global_settings
.peak_meter_dbfs
)
705 /* convert to dBfs * 100 */
706 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
707 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
711 /* percent is stored directly -> no conversion */
712 pm_min
= global_settings
.peak_meter_min
;
713 pm_max
= global_settings
.peak_meter_max
;
716 /* apply the range */
717 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
719 #endif /* HAVE_LCD_BITMAP */
721 void sound_settings_apply(void)
723 #if CONFIG_CODEC == SWCODEC
724 sound_set_dsp_callback(dsp_callback
);
726 #ifdef AUDIOHW_HAVE_BASS
727 sound_set(SOUND_BASS
, global_settings
.bass
);
729 #ifdef AUDIOHW_HAVE_TREBLE
730 sound_set(SOUND_TREBLE
, global_settings
.treble
);
732 sound_set(SOUND_BALANCE
, global_settings
.balance
);
733 #ifndef PLATFORM_HAS_VOLUME_CHANGE
734 sound_set(SOUND_VOLUME
, global_settings
.volume
);
736 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
737 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
738 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
739 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
740 sound_set(SOUND_AVC
, global_settings
.avc
);
741 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
742 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
743 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
744 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
745 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
746 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
748 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
749 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
751 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
752 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
754 #ifdef AUDIOHW_HAVE_DEPTH_3D
755 sound_set(SOUND_DEPTH_3D
, global_settings
.depth_3d
);
757 #ifdef AUDIOHW_HAVE_EQ
760 for (b
= 0; b
< AUDIOHW_EQ_BAND_NUM
; b
++)
762 int setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_GAIN
);
763 sound_set(setting
, global_settings
.hw_eq_bands
[b
].gain
);
765 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
766 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_FREQUENCY
);
768 sound_set(setting
, global_settings
.hw_eq_bands
[b
].frequency
);
769 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
770 #ifdef AUDIOHW_HAVE_EQ_WIDTH
771 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_WIDTH
);
773 sound_set(setting
, global_settings
.hw_eq_bands
[b
].width
);
774 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
779 void settings_apply(bool read_disk
)
781 #ifdef HAVE_LCD_BITMAP
784 sound_settings_apply();
786 #ifdef HAVE_DISK_STORAGE
787 audio_set_buffer_margin(global_settings
.buffer_margin
);
790 #ifdef HAVE_LCD_CONTRAST
791 lcd_set_contrast(global_settings
.contrast
);
793 lcd_scroll_speed(global_settings
.scroll_speed
);
794 #ifdef HAVE_REMOTE_LCD
795 lcd_remote_set_contrast(global_settings
.remote_contrast
);
796 lcd_remote_set_invert_display(global_settings
.remote_invert
);
799 lcd_remote_set_flip(global_settings
.remote_flip_display
);
802 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
803 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
804 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
805 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
806 #ifdef HAVE_REMOTE_LCD_TICKING
807 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
809 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
811 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
813 #ifdef HAS_REMOTE_BUTTON_HOLD
814 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
816 #endif /* HAVE_REMOTE_LCD */
817 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
818 backlight_set_brightness(global_settings
.brightness
);
820 #ifdef HAVE_BACKLIGHT
821 backlight_set_timeout(global_settings
.backlight_timeout
);
823 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
825 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
826 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
827 backlight_set_fade_in(global_settings
.backlight_fade_in
);
828 backlight_set_fade_out(global_settings
.backlight_fade_out
);
831 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
832 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
834 #ifdef HAVE_BUTTON_LIGHT
835 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
837 #ifdef HAVE_DISK_STORAGE
838 storage_spindown(global_settings
.disk_spindown
);
840 #if (CONFIG_CODEC == MAS3507D) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
841 dac_line_in(global_settings
.line_in
);
843 set_poweroff_timeout(global_settings
.poweroff
);
844 if (global_settings
.sleeptimer_on_startup
)
845 set_sleep_timer(global_settings
.sleeptimer_duration
* 60);
846 set_keypress_restarts_sleep_timer(
847 global_settings
.keypress_restarts_sleeptimer
);
849 #if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
850 /* only call if it's really exchangable */
851 set_battery_capacity(global_settings
.battery_capacity
);
854 #if BATTERY_TYPES_COUNT > 1
855 set_battery_type(global_settings
.battery_type
);
858 #ifdef HAVE_LCD_BITMAP
859 #ifdef HAVE_LCD_INVERT
860 lcd_set_invert_display(global_settings
.invert
);
863 lcd_set_flip(global_settings
.flip_display
);
864 button_set_flip(global_settings
.flip_display
);
866 lcd_update(); /* refresh after flipping the screen */
867 settings_apply_pm_range();
868 peak_meter_init_times(
869 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
870 global_settings
.peak_meter_clip_hold
);
874 audiohw_enable_speaker(global_settings
.speaker_enabled
);
880 #ifdef HAVE_LCD_BITMAP
881 /* fonts need to be loaded before the WPS */
882 if (global_settings
.font_file
[0]
883 && global_settings
.font_file
[0] != '-') {
884 int font_ui
= screens
[SCREEN_MAIN
].getuifont();
885 const char* loaded_font
= font_filename(font_ui
);
887 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
888 global_settings
.font_file
);
889 if (!loaded_font
|| strcmp(loaded_font
, buf
))
891 CHART2(">font_load ", global_settings
.font_file
);
893 font_unload(font_ui
);
894 rc
= font_load_ex(buf
, 0, global_settings
.glyphs_to_cache
);
895 CHART2("<font_load ", global_settings
.font_file
);
896 screens
[SCREEN_MAIN
].setuifont(rc
);
897 screens
[SCREEN_MAIN
].setfont(rc
);
900 #ifdef HAVE_REMOTE_LCD
901 if ( global_settings
.remote_font_file
[0]
902 && global_settings
.remote_font_file
[0] != '-') {
903 int font_ui
= screens
[SCREEN_REMOTE
].getuifont();
904 const char* loaded_font
= font_filename(font_ui
);
905 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
906 global_settings
.remote_font_file
);
907 if (!loaded_font
|| strcmp(loaded_font
, buf
))
909 CHART2(">font_load_remoteui ", global_settings
.remote_font_file
);
911 font_unload(font_ui
);
913 CHART2("<font_load_remoteui ", global_settings
.remote_font_file
);
914 screens
[SCREEN_REMOTE
].setuifont(rc
);
915 screens
[SCREEN_REMOTE
].setfont(rc
);
919 if ( global_settings
.kbd_file
[0]
920 && global_settings
.kbd_file
[0] != '-') {
921 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
922 global_settings
.kbd_file
);
929 #endif /* HAVE_LCD_BITMAP */
930 if ( global_settings
.lang_file
[0]) {
931 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
932 global_settings
.lang_file
);
933 CHART(">lang_core_load");
935 CHART("<lang_core_load");
937 talk_init(); /* use voice of same language */
941 /* load the icon set */
942 CHART(">icons_init");
944 CHART("<icons_init");
946 #ifdef HAVE_LCD_COLOR
947 if (global_settings
.colors_file
[0]
948 && global_settings
.colors_file
[0] != '-')
950 CHART(">read_color_theme_file");
951 read_color_theme_file();
952 CHART("<read_color_theme_file");
956 #ifdef HAVE_LCD_COLOR
957 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
958 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
959 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
960 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
961 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
964 #ifdef HAVE_LCD_BITMAP
965 lcd_scroll_step(global_settings
.scroll_step
);
966 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
967 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
969 lcd_bidir_scroll(global_settings
.bidir_limit
);
970 lcd_scroll_delay(global_settings
.scroll_delay
);
973 CHART(">set_codepage");
974 set_codepage(global_settings
.default_codepage
);
975 CHART("<set_codepage");
977 #if CONFIG_CODEC == SWCODEC
978 #ifdef HAVE_CROSSFADE
979 audio_set_crossfade(global_settings
.crossfade
);
982 dsp_crossfeed_enable(global_settings
.crossfeed
);
983 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
984 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
985 global_settings
.crossfeed_hf_attenuation
,
986 global_settings
.crossfeed_hf_cutoff
);
988 /* Configure software equalizer, hardware eq is handled in audio_init() */
989 dsp_eq_enable(global_settings
.eq_enabled
);
990 dsp_set_eq_precut(global_settings
.eq_precut
);
991 for(int i
= 0; i
< EQ_NUM_BANDS
; i
++) {
992 dsp_set_eq_coefs(i
, &global_settings
.eq_band_settings
[i
]);
995 dsp_dither_enable(global_settings
.dithering_enabled
);
996 #ifdef HAVE_PITCHCONTROL
997 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
999 dsp_set_compressor(&global_settings
.compressor_settings
);
1002 #ifdef HAVE_SPDIF_POWER
1003 spdif_power_enable(global_settings
.spdif_enable
);
1006 #ifdef HAVE_BACKLIGHT
1007 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
1008 #ifdef HAVE_REMOTE_LCD
1009 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
1011 #ifdef HAS_BUTTON_HOLD
1012 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
1014 #ifdef HAVE_LCD_SLEEP_SETTING
1015 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
1017 #endif /* HAVE_BACKLIGHT */
1019 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
1020 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
1023 #ifdef HAVE_USB_CHARGING_ENABLE
1024 usb_charging_enable(global_settings
.usb_charging
);
1027 #ifdef HAVE_TOUCHSCREEN
1028 touchscreen_set_mode(global_settings
.touch_mode
);
1029 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1032 /* This should stay last */
1033 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1034 enc_global_settings_apply();
1036 #ifdef HAVE_LCD_BITMAP
1037 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1038 CHART(">viewportmanager_theme_changed");
1039 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
|THEME_BUTTONBAR
);
1040 CHART("<viewportmanager_theme_changed");
1046 * reset all settings to their default value
1048 void reset_setting(const struct settings_list
*setting
, void *var
)
1050 switch (setting
->flags
&F_T_MASK
)
1053 setting
->custom_setting
->set_default(setting
->setting
,
1054 setting
->default_val
.custom
);
1058 if (setting
->flags
&F_DEF_ISFUNC
)
1059 *(int*)var
= setting
->default_val
.func();
1060 else if (setting
->flags
&F_T_SOUND
)
1061 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1062 else *(int*)var
= setting
->default_val
.int_
;
1065 *(bool*)var
= setting
->default_val
.bool_
;
1069 strlcpy((char*)var
, setting
->default_val
.charptr
,
1070 setting
->filename_setting
->max_len
);
1075 void settings_reset(void)
1077 for(int i
=0; i
<nb_settings
; i
++)
1078 reset_setting(&settings
[i
], settings
[i
].setting
);
1079 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1080 enc_global_settings_reset();
1082 #ifdef HAVE_LCD_BITMAP
1085 if (screens
[i
].getuifont() > FONT_SYSFIXED
)
1087 font_unload(screens
[i
].getuifont());
1088 screens
[i
].setuifont(FONT_SYSFIXED
);
1089 screens
[i
].setfont(FONT_SYSFIXED
);
1095 /** Changing setting values **/
1096 const struct settings_list
* find_setting(const void* variable
, int *id
)
1099 for(i
=0;i
<nb_settings
;i
++)
1101 if (settings
[i
].setting
== variable
)
1105 return &settings
[i
];
1110 const struct settings_list
* find_setting_by_cfgname(const char* name
, int *id
)
1113 for (i
=0; i
<nb_settings
; i
++)
1115 if (settings
[i
].cfg_name
&&
1116 !strcmp(settings
[i
].cfg_name
, name
))
1119 return &settings
[i
];
1125 bool set_bool(const char* string
, const bool* variable
)
1127 return set_bool_options(string
, variable
,
1128 (char *)STR(LANG_SET_BOOL_YES
),
1129 (char *)STR(LANG_SET_BOOL_NO
),
1134 bool set_bool_options(const char* string
, const bool* variable
,
1135 const char* yes_str
, int yes_voice
,
1136 const char* no_str
, int no_voice
,
1137 void (*function
)(bool))
1139 struct opt_items names
[] = {
1140 {(unsigned const char *)no_str
, no_voice
},
1141 {(unsigned const char *)yes_str
, yes_voice
}
1145 result
= set_option(string
, variable
, BOOL
, names
, 2,
1146 (void (*)(int))function
);
1150 bool set_int(const unsigned char* string
,
1153 const int* variable
,
1154 void (*function
)(int),
1158 const char* (*formatter
)(char*, size_t, int, const char*) )
1160 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1161 step
, min
, max
, formatter
, NULL
);
1164 bool set_int_ex(const unsigned char* string
,
1167 const int* variable
,
1168 void (*function
)(int),
1172 const char* (*formatter
)(char*, size_t, int, const char*),
1173 int32_t (*get_talk_id
)(int, int))
1176 struct settings_list item
;
1177 struct int_setting data
= {
1178 function
, voice_unit
, min
, max
, step
,
1179 formatter
, get_talk_id
1181 item
.int_setting
= &data
;
1182 item
.flags
= F_INT_SETTING
|F_T_INT
;
1184 item
.cfg_vals
= (char*)string
;
1185 item
.setting
= (void *)variable
;
1186 return option_screen(&item
, NULL
, false, NULL
);
1190 static const struct opt_items
*set_option_options
;
1191 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1193 (void)buf
, (void)unit
, (void)size
;
1194 return P2STR(set_option_options
[item
].string
);
1197 static int32_t set_option_get_talk_id(int value
, int unit
)
1200 return set_option_options
[value
].voice_id
;
1203 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1204 const struct opt_items
* options
,
1205 int numoptions
, void (*function
)(int))
1208 struct settings_list item
;
1209 struct int_setting data
= {
1210 function
, UNIT_INT
, 0, numoptions
-1, 1,
1211 set_option_formatter
, set_option_get_talk_id
1213 set_option_options
= options
;
1214 item
.int_setting
= &data
;
1215 item
.flags
= F_INT_SETTING
|F_T_INT
;
1217 item
.cfg_vals
= (char*)string
;
1218 item
.setting
= &temp
;
1220 temp
= *(bool*)variable
? 1: 0;
1222 temp
= *(int*)variable
;
1223 if (!option_screen(&item
, NULL
, false, NULL
))
1227 *(bool*)variable
= (temp
== 1);
1229 *(int*)variable
= temp
;
1236 * Takes filename, removes the directory and the extension,
1237 * and then copies the basename into setting, unless the basename exceeds maxlen
1239 void set_file(const char* filename
, char* setting
, const int maxlen
)
1241 const char* fptr
= strrchr(filename
,'/');
1251 extptr
= strrchr(fptr
, '.');
1253 if (!extptr
|| extptr
< fptr
)
1256 extlen
= strlen(extptr
);
1258 len
= strlen(fptr
) - extlen
+ 1;
1260 /* error if filename isn't in ROCKBOX_DIR */
1264 strlcpy(setting
, fptr
, len
);