1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Stuart Martin
11 * RTC config saving code (C) 2002 by hessu@hes.iki.fi
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
33 #include "backlight.h"
40 #include "ata_idle_notify.h"
48 #ifdef HAVE_LCD_BITMAP
51 #include "peakmeter.h"
56 #include "powermgmt.h"
61 #include "rbunicode.h"
63 #include "statusbar.h"
66 #include "settings_list.h"
67 #include "filetypes.h"
68 #include "option_select.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 strncpy(temp
, start
, end
-start
);
251 temp
[end
-start
] = '\0';
252 if (!strcmp(str
, temp
))
263 bool settings_load_config(const char* file
, bool apply
)
270 fd
= open_utf8(file
, O_RDONLY
);
274 while (read_line(fd
, line
, sizeof line
) > 0)
276 if (!settings_parseline(line
, &name
, &value
))
278 for(i
=0; i
<nb_settings
; i
++)
280 if (settings
[i
].cfg_name
== NULL
)
282 if (!strcasecmp(name
,settings
[i
].cfg_name
))
284 switch (settings
[i
].flags
&F_T_MASK
)
287 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
291 #ifdef HAVE_LCD_COLOR
292 if (settings
[i
].flags
&F_RGB
)
293 hex_to_rgb(value
, (int*)settings
[i
].setting
);
296 if (settings
[i
].cfg_vals
== NULL
)
298 *(int*)settings
[i
].setting
= atoi(value
);
302 int temp
, *v
= (int*)settings
[i
].setting
;
303 bool found
= cfg_string_to_int(i
, &temp
, value
);
306 if (settings
[i
].flags
&F_TABLE_SETTING
)
307 *v
= settings
[i
].table_setting
->values
[temp
];
318 if (cfg_string_to_int(i
,&temp
,value
))
319 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
320 if (settings
[i
].bool_setting
->option_callback
)
321 settings
[i
].bool_setting
->option_callback(temp
==0?false:true);
327 char storage
[MAX_PATH
];
328 if (settings
[i
].filename_setting
->prefix
)
330 int len
= strlen(settings
[i
].filename_setting
->prefix
);
331 if (!strncasecmp(value
,
332 settings
[i
].filename_setting
->prefix
,
335 strncpy(storage
,&value
[len
],MAX_PATH
);
337 else strncpy(storage
,value
,MAX_PATH
);
339 else strncpy(storage
,value
,MAX_PATH
);
340 if (settings
[i
].filename_setting
->suffix
)
342 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
345 strncpy((char*)settings
[i
].setting
,storage
,
346 settings
[i
].filename_setting
->max_len
);
347 ((char*)settings
[i
].setting
)
348 [settings
[i
].filename_setting
->max_len
-1] = '\0';
353 } /* if (!strcmp(name,settings[i].cfg_name)) */
360 settings_apply(true);
364 /** Writing to a config file and saving settings **/
366 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
368 int flags
= settings
[setting_id
].flags
;
369 const char* start
= settings
[setting_id
].cfg_vals
;
373 if ((flags
&F_T_MASK
)==F_T_INT
&&
374 flags
&F_TABLE_SETTING
)
376 const int *value
= settings
[setting_id
].table_setting
->values
;
379 end
= strchr(start
,',');
380 if (value
[count
] == val
)
383 strncpy(buf
, start
, buf_len
);
386 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
387 strncpy(buf
, start
, len
);
404 start
= strchr(start
,',');
410 end
= strchr(start
,',');
412 strncpy(buf
, start
, buf_len
);
415 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
416 strncpy(buf
, start
, len
);
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 strncpy(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 bool flush_global_status_callback(void)
571 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
574 static bool flush_config_block_callback(void)
577 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
578 r2
= 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
];
627 case SETTINGS_SAVE_THEME
:
630 #ifdef HAVE_RECORDING
631 case SETTINGS_SAVE_RECPRESETS
:
632 folder
= RECPRESETS_DIR
;
635 #if CONFIG_CODEC == SWCODEC
636 case SETTINGS_SAVE_EQPRESET
:
640 case SETTINGS_SAVE_SOUND
:
642 folder
= ROCKBOX_DIR
;
644 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
645 IF_CNFN_NUM_(, NULL
));
647 /* allow user to modify filename */
649 if (!kbd_input(filename
, sizeof filename
)) {
653 splash(HZ
, ID2P(LANG_CANCEL
));
658 if (settings_write_config(filename
, options
))
659 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
661 splash(HZ
, ID2P(LANG_FAILED
));
665 /** Apply and Reset settings **/
668 #ifdef HAVE_LCD_BITMAP
670 * Applies the range infos stored in global_settings to
673 void settings_apply_pm_range(void)
677 /* depending on the scale mode (dBfs or percent) the values
678 of global_settings.peak_meter_dbfs have different meanings */
679 if (global_settings
.peak_meter_dbfs
)
681 /* convert to dBfs * 100 */
682 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
683 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
687 /* percent is stored directly -> no conversion */
688 pm_min
= global_settings
.peak_meter_min
;
689 pm_max
= global_settings
.peak_meter_max
;
692 /* apply the range */
693 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
695 #endif /* HAVE_LCD_BITMAP */
697 void sound_settings_apply(void)
699 #if CONFIG_CODEC == SWCODEC
700 sound_set_dsp_callback(dsp_callback
);
702 sound_set(SOUND_BASS
, global_settings
.bass
);
703 sound_set(SOUND_TREBLE
, global_settings
.treble
);
704 sound_set(SOUND_BALANCE
, global_settings
.balance
);
705 sound_set(SOUND_VOLUME
, global_settings
.volume
);
706 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
707 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
708 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
709 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
710 sound_set(SOUND_AVC
, global_settings
.avc
);
711 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
712 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
713 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
714 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
715 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
716 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
720 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
721 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
725 void settings_apply(bool read_disk
)
728 #if CONFIG_CODEC == SWCODEC
732 sound_settings_apply();
734 #ifdef HAVE_DISK_STORAGE
735 audio_set_buffer_margin(global_settings
.buffer_margin
);
738 #ifdef HAVE_LCD_CONTRAST
739 lcd_set_contrast(global_settings
.contrast
);
741 lcd_scroll_speed(global_settings
.scroll_speed
);
742 #ifdef HAVE_REMOTE_LCD
743 lcd_remote_set_contrast(global_settings
.remote_contrast
);
744 lcd_remote_set_invert_display(global_settings
.remote_invert
);
747 lcd_remote_set_flip(global_settings
.remote_flip_display
);
750 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
751 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
752 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
753 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
754 #ifdef HAVE_REMOTE_LCD_TICKING
755 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
757 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
759 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
761 #ifdef HAS_REMOTE_BUTTON_HOLD
762 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
764 #endif /* HAVE_REMOTE_LCD */
765 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
766 backlight_set_brightness(global_settings
.brightness
);
768 #ifdef HAVE_BACKLIGHT
769 backlight_set_timeout(global_settings
.backlight_timeout
);
771 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
773 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
774 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
775 backlight_set_fade_in(global_settings
.backlight_fade_in
);
776 backlight_set_fade_out(global_settings
.backlight_fade_out
);
779 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
780 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
782 #ifdef HAVE_BUTTON_LIGHT
783 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
785 #ifdef HAVE_DISK_STORAGE
786 storage_spindown(global_settings
.disk_spindown
);
788 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
789 dac_line_in(global_settings
.line_in
);
791 set_poweroff_timeout(global_settings
.poweroff
);
793 set_battery_capacity(global_settings
.battery_capacity
);
794 #if BATTERY_TYPES_COUNT > 1
795 set_battery_type(global_settings
.battery_type
);
798 #ifdef HAVE_LCD_BITMAP
799 #ifdef HAVE_LCD_INVERT
800 lcd_set_invert_display(global_settings
.invert
);
803 lcd_set_flip(global_settings
.flip_display
);
804 button_set_flip(global_settings
.flip_display
);
806 lcd_update(); /* refresh after flipping the screen */
807 settings_apply_pm_range();
808 peak_meter_init_times(
809 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
810 global_settings
.peak_meter_clip_hold
);
814 audiohw_enable_speaker(global_settings
.speaker_enabled
);
820 #ifdef HAVE_LCD_BITMAP
821 /* fonts need to be loaded before the WPS */
822 if ( global_settings
.font_file
[0]) {
823 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
824 global_settings
.font_file
);
825 if (font_load(buf
) == NULL
)
831 if ( global_settings
.kbd_file
[0]) {
832 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
833 global_settings
.kbd_file
);
840 unload_wps_backdrop();
842 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
843 unload_remote_wps_backdrop();
845 if ( global_settings
.wps_file
[0] &&
846 global_settings
.wps_file
[0] != 0xff ) {
847 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
848 global_settings
.wps_file
);
849 wps_data_load(gui_wps
[0].data
, &screens
[0], buf
, true);
853 wps_data_init(gui_wps
[0].data
);
854 #ifdef HAVE_REMOTE_LCD
855 gui_wps
[0].data
->remote_wps
= false;
860 if ( global_settings
.backdrop_file
[0] &&
861 global_settings
.backdrop_file
[0] != 0xff ) {
862 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
863 global_settings
.backdrop_file
);
864 load_main_backdrop(buf
);
866 unload_main_backdrop();
868 show_main_backdrop();
870 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
871 show_remote_main_backdrop();
874 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
875 if ( global_settings
.rwps_file
[0]) {
876 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
877 global_settings
.rwps_file
);
878 wps_data_load(gui_wps
[1].data
, &screens
[1], buf
, true);
882 wps_data_init(gui_wps
[1].data
);
883 gui_wps
[1].data
->remote_wps
= true;
886 if ( global_settings
.lang_file
[0]) {
887 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
888 global_settings
.lang_file
);
890 talk_init(); /* use voice of same language */
892 /* load the icon set */
895 #ifdef HAVE_LCD_COLOR
896 if (global_settings
.colors_file
[0])
897 read_color_theme_file();
901 #ifdef HAVE_LCD_COLOR
902 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
903 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
904 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
905 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
906 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
909 #ifdef HAVE_LCD_BITMAP
910 lcd_scroll_step(global_settings
.scroll_step
);
911 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
912 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
914 lcd_jump_scroll(global_settings
.jump_scroll
);
915 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
917 lcd_bidir_scroll(global_settings
.bidir_limit
);
918 lcd_scroll_delay(global_settings
.scroll_delay
);
921 set_codepage(global_settings
.default_codepage
);
923 #if CONFIG_CODEC == SWCODEC
924 audio_set_crossfade(global_settings
.crossfade
);
925 dsp_set_replaygain();
926 dsp_set_crossfeed(global_settings
.crossfeed
);
927 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
928 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
929 global_settings
.crossfeed_hf_attenuation
,
930 global_settings
.crossfeed_hf_cutoff
);
932 /* Configure software equalizer, hardware eq is handled in audio_init() */
933 dsp_set_eq(global_settings
.eq_enabled
);
934 dsp_set_eq_precut(global_settings
.eq_precut
);
935 for(i
= 0; i
< 5; i
++) {
939 dsp_dither_enable(global_settings
.dithering_enabled
);
942 #ifdef HAVE_SPDIF_POWER
943 spdif_power_enable(global_settings
.spdif_enable
);
946 #ifdef HAVE_BACKLIGHT
947 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
948 #ifdef HAVE_REMOTE_LCD
949 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
951 #ifdef HAS_BUTTON_HOLD
952 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
954 #ifdef HAVE_LCD_SLEEP_SETTING
955 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
957 #endif /* HAVE_BACKLIGHT */
959 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
960 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
963 #ifdef HAVE_USB_CHARGING_ENABLE
964 usb_charging_enable(global_settings
.usb_charging
);
967 #ifdef HAVE_TOUCHSCREEN
968 touchscreen_set_mode(global_settings
.touch_mode
);
971 /* This should stay last */
972 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
973 enc_global_settings_apply();
975 list_init_viewports(NULL
);
980 * reset all settings to their default value
982 void reset_setting(const struct settings_list
*setting
, void *var
)
984 switch (setting
->flags
&F_T_MASK
)
987 setting
->custom_setting
->set_default(setting
->setting
,
988 setting
->default_val
.custom
);
992 if (setting
->flags
&F_DEF_ISFUNC
)
993 *(int*)var
= setting
->default_val
.func();
994 else if (setting
->flags
&F_T_SOUND
)
995 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
996 else *(int*)var
= setting
->default_val
.int_
;
999 *(bool*)var
= setting
->default_val
.bool_
;
1003 strncpy((char*)var
, setting
->default_val
.charptr
,
1004 setting
->filename_setting
->max_len
);
1009 void settings_reset(void)
1013 for(i
=0; i
<nb_settings
; i
++)
1014 reset_setting(&settings
[i
], settings
[i
].setting
);
1015 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1016 enc_global_settings_reset();
1020 /** Changing setting values **/
1021 const struct settings_list
* find_setting(const void* variable
, int *id
)
1024 for(i
=0;i
<nb_settings
;i
++)
1026 if (settings
[i
].setting
== variable
)
1030 return &settings
[i
];
1036 bool set_bool(const char* string
, const bool* variable
)
1038 return set_bool_options(string
, variable
,
1039 (char *)STR(LANG_SET_BOOL_YES
),
1040 (char *)STR(LANG_SET_BOOL_NO
),
1045 bool set_bool_options(const char* string
, const bool* variable
,
1046 const char* yes_str
, int yes_voice
,
1047 const char* no_str
, int no_voice
,
1048 void (*function
)(bool))
1050 struct opt_items names
[] = {
1051 {(unsigned const char *)no_str
, no_voice
},
1052 {(unsigned const char *)yes_str
, yes_voice
}
1056 result
= set_option(string
, variable
, BOOL
, names
, 2,
1057 (void (*)(int))function
);
1061 bool set_int(const unsigned char* string
,
1064 const int* variable
,
1065 void (*function
)(int),
1069 void (*formatter
)(char*, size_t, int, const char*) )
1071 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1072 step
, min
, max
, formatter
, NULL
);
1075 bool set_int_ex(const unsigned char* string
,
1078 const int* variable
,
1079 void (*function
)(int),
1083 void (*formatter
)(char*, size_t, int, const char*),
1084 int32_t (*get_talk_id
)(int, int))
1087 struct settings_list item
;
1088 struct int_setting data
= {
1089 function
, voice_unit
, min
, max
, step
,
1090 formatter
, get_talk_id
1092 item
.int_setting
= &data
;
1093 item
.flags
= F_INT_SETTING
|F_T_INT
;
1095 item
.cfg_vals
= (char*)string
;
1096 item
.setting
= (void *)variable
;
1097 return option_screen(&item
, NULL
, false, NULL
);
1101 static const struct opt_items
*set_option_options
;
1102 static void set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1105 const unsigned char *text
= set_option_options
[item
].string
;
1106 strncpy(buf
, P2STR(text
), size
);
1108 static int32_t set_option_get_talk_id(int value
, int unit
)
1111 return set_option_options
[value
].voice_id
;
1113 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1114 const struct opt_items
* options
,
1115 int numoptions
, void (*function
)(int))
1118 struct settings_list item
;
1119 struct int_setting data
= {
1120 function
, UNIT_INT
, 0, numoptions
-1, 1,
1121 set_option_formatter
, set_option_get_talk_id
1123 set_option_options
= options
;
1124 item
.int_setting
= &data
;
1125 item
.flags
= F_INT_SETTING
|F_T_INT
;
1127 item
.cfg_vals
= (char*)string
;
1128 item
.setting
= &temp
;
1130 temp
= *(bool*)variable
? 1: 0;
1132 temp
= *(int*)variable
;
1133 if (!option_screen(&item
, NULL
, false, NULL
))
1136 *(bool*)variable
= (temp
== 1? true: false);
1138 *(int*)variable
= temp
;
1145 void set_file(const char* filename
, char* setting
, int maxlen
)
1147 char* fptr
= strrchr(filename
,'/');
1160 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1164 if(ptr
== fptr
) extlen
= 0;
1166 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1167 (len
-extlen
> maxlen
))
1170 strncpy(setting
, fptr
, len
-extlen
);
1171 setting
[len
-extlen
]=0;