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
);
745 lcd_remote_set_flip(global_settings
.remote_flip_display
);
746 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
747 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
748 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
749 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
750 #ifdef HAVE_REMOTE_LCD_TICKING
751 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
753 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
755 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
757 #ifdef HAS_REMOTE_BUTTON_HOLD
758 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
760 #endif /* HAVE_REMOTE_LCD */
761 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
762 backlight_set_brightness(global_settings
.brightness
);
764 #ifdef HAVE_BACKLIGHT
765 backlight_set_timeout(global_settings
.backlight_timeout
);
767 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
769 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
770 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
771 backlight_set_fade_in(global_settings
.backlight_fade_in
);
772 backlight_set_fade_out(global_settings
.backlight_fade_out
);
775 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
776 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
778 #ifdef HAVE_BUTTON_LIGHT
779 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
781 #ifdef HAVE_DISK_STORAGE
782 storage_spindown(global_settings
.disk_spindown
);
784 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
785 dac_line_in(global_settings
.line_in
);
787 set_poweroff_timeout(global_settings
.poweroff
);
789 set_battery_capacity(global_settings
.battery_capacity
);
790 #if BATTERY_TYPES_COUNT > 1
791 set_battery_type(global_settings
.battery_type
);
794 #ifdef HAVE_LCD_BITMAP
795 #ifdef HAVE_LCD_INVERT
796 lcd_set_invert_display(global_settings
.invert
);
799 lcd_set_flip(global_settings
.flip_display
);
800 button_set_flip(global_settings
.flip_display
);
802 lcd_update(); /* refresh after flipping the screen */
803 settings_apply_pm_range();
804 peak_meter_init_times(
805 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
806 global_settings
.peak_meter_clip_hold
);
812 #ifdef HAVE_LCD_BITMAP
813 /* fonts need to be loaded before the WPS */
814 if ( global_settings
.font_file
[0]) {
815 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
816 global_settings
.font_file
);
817 if (font_load(buf
) == NULL
)
823 if ( global_settings
.kbd_file
[0]) {
824 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
825 global_settings
.kbd_file
);
832 unload_wps_backdrop();
834 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
835 unload_remote_wps_backdrop();
837 if ( global_settings
.wps_file
[0] &&
838 global_settings
.wps_file
[0] != 0xff ) {
839 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
840 global_settings
.wps_file
);
841 wps_data_load(gui_wps
[0].data
, &screens
[0], buf
, true);
845 wps_data_init(gui_wps
[0].data
);
846 #ifdef HAVE_REMOTE_LCD
847 gui_wps
[0].data
->remote_wps
= false;
852 if ( global_settings
.backdrop_file
[0] &&
853 global_settings
.backdrop_file
[0] != 0xff ) {
854 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
855 global_settings
.backdrop_file
);
856 load_main_backdrop(buf
);
858 unload_main_backdrop();
860 show_main_backdrop();
862 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
863 show_remote_main_backdrop();
866 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
867 if ( global_settings
.rwps_file
[0]) {
868 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
869 global_settings
.rwps_file
);
870 wps_data_load(gui_wps
[1].data
, &screens
[1], buf
, true);
874 wps_data_init(gui_wps
[1].data
);
875 gui_wps
[1].data
->remote_wps
= true;
878 if ( global_settings
.lang_file
[0]) {
879 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
880 global_settings
.lang_file
);
882 talk_init(); /* use voice of same language */
884 /* load the icon set */
887 #ifdef HAVE_LCD_COLOR
888 if (global_settings
.colors_file
[0])
889 read_color_theme_file();
893 #ifdef HAVE_LCD_COLOR
894 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
895 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
896 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
897 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
898 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
901 #ifdef HAVE_LCD_BITMAP
902 lcd_scroll_step(global_settings
.scroll_step
);
903 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
904 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
906 lcd_jump_scroll(global_settings
.jump_scroll
);
907 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
909 lcd_bidir_scroll(global_settings
.bidir_limit
);
910 lcd_scroll_delay(global_settings
.scroll_delay
);
913 set_codepage(global_settings
.default_codepage
);
915 #if CONFIG_CODEC == SWCODEC
916 audio_set_crossfade(global_settings
.crossfade
);
917 dsp_set_replaygain();
918 dsp_set_crossfeed(global_settings
.crossfeed
);
919 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
920 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
921 global_settings
.crossfeed_hf_attenuation
,
922 global_settings
.crossfeed_hf_cutoff
);
924 /* Configure software equalizer, hardware eq is handled in audio_init() */
925 dsp_set_eq(global_settings
.eq_enabled
);
926 dsp_set_eq_precut(global_settings
.eq_precut
);
927 for(i
= 0; i
< 5; i
++) {
931 dsp_dither_enable(global_settings
.dithering_enabled
);
934 #ifdef HAVE_SPDIF_POWER
935 spdif_power_enable(global_settings
.spdif_enable
);
938 #ifdef HAVE_BACKLIGHT
939 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
940 #ifdef HAVE_REMOTE_LCD
941 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
943 #ifdef HAS_BUTTON_HOLD
944 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
946 #ifdef HAVE_LCD_SLEEP_SETTING
947 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
949 #endif /* HAVE_BACKLIGHT */
951 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
952 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
955 #ifdef HAVE_USB_CHARGING_ENABLE
956 usb_charging_enable(global_settings
.usb_charging
);
959 /* This should stay last */
960 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
961 enc_global_settings_apply();
963 list_init_viewports(NULL
);
968 * reset all settings to their default value
970 void reset_setting(const struct settings_list
*setting
, void *var
)
972 switch (setting
->flags
&F_T_MASK
)
975 setting
->custom_setting
->set_default(setting
->setting
,
976 setting
->default_val
.custom
);
980 if (setting
->flags
&F_DEF_ISFUNC
)
981 *(int*)var
= setting
->default_val
.func();
982 else if (setting
->flags
&F_T_SOUND
)
983 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
984 else *(int*)var
= setting
->default_val
.int_
;
987 *(bool*)var
= setting
->default_val
.bool_
;
991 strncpy((char*)var
, setting
->default_val
.charptr
,
992 setting
->filename_setting
->max_len
);
997 void settings_reset(void)
1001 for(i
=0; i
<nb_settings
; i
++)
1002 reset_setting(&settings
[i
], settings
[i
].setting
);
1003 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1004 enc_global_settings_reset();
1008 /** Changing setting values **/
1009 const struct settings_list
* find_setting(const void* variable
, int *id
)
1012 for(i
=0;i
<nb_settings
;i
++)
1014 if (settings
[i
].setting
== variable
)
1018 return &settings
[i
];
1024 bool set_bool(const char* string
, const bool* variable
)
1026 return set_bool_options(string
, variable
,
1027 (char *)STR(LANG_SET_BOOL_YES
),
1028 (char *)STR(LANG_SET_BOOL_NO
),
1033 bool set_bool_options(const char* string
, const bool* variable
,
1034 const char* yes_str
, int yes_voice
,
1035 const char* no_str
, int no_voice
,
1036 void (*function
)(bool))
1038 struct opt_items names
[] = {
1039 {(unsigned const char *)no_str
, no_voice
},
1040 {(unsigned const char *)yes_str
, yes_voice
}
1044 result
= set_option(string
, variable
, BOOL
, names
, 2,
1045 (void (*)(int))function
);
1049 bool set_int(const unsigned char* string
,
1052 const int* variable
,
1053 void (*function
)(int),
1057 void (*formatter
)(char*, size_t, int, const char*) )
1059 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1060 step
, min
, max
, formatter
, NULL
);
1063 bool set_int_ex(const unsigned char* string
,
1066 const int* variable
,
1067 void (*function
)(int),
1071 void (*formatter
)(char*, size_t, int, const char*),
1072 int32_t (*get_talk_id
)(int, int))
1075 struct settings_list item
;
1076 struct int_setting data
= {
1077 function
, voice_unit
, min
, max
, step
,
1078 formatter
, get_talk_id
1080 item
.int_setting
= &data
;
1081 item
.flags
= F_INT_SETTING
|F_T_INT
;
1083 item
.cfg_vals
= (char*)string
;
1084 item
.setting
= (void *)variable
;
1085 return option_screen(&item
, NULL
, false, NULL
);
1089 static const struct opt_items
*set_option_options
;
1090 static void set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1093 const unsigned char *text
= set_option_options
[item
].string
;
1094 strncpy(buf
, P2STR(text
), size
);
1096 static int32_t set_option_get_talk_id(int value
, int unit
)
1099 return set_option_options
[value
].voice_id
;
1101 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1102 const struct opt_items
* options
,
1103 int numoptions
, void (*function
)(int))
1106 struct settings_list item
;
1107 struct int_setting data
= {
1108 function
, UNIT_INT
, 0, numoptions
-1, 1,
1109 set_option_formatter
, set_option_get_talk_id
1111 set_option_options
= options
;
1112 item
.int_setting
= &data
;
1113 item
.flags
= F_INT_SETTING
|F_T_INT
;
1115 item
.cfg_vals
= (char*)string
;
1116 item
.setting
= &temp
;
1118 temp
= *(bool*)variable
? 1: 0;
1120 temp
= *(int*)variable
;
1121 if (!option_screen(&item
, NULL
, false, NULL
))
1124 *(bool*)variable
= (temp
== 1? true: false);
1126 *(int*)variable
= temp
;
1133 void set_file(const char* filename
, char* setting
, int maxlen
)
1135 char* fptr
= strrchr(filename
,'/');
1148 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1152 if(ptr
== fptr
) extlen
= 0;
1154 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1155 (len
-extlen
> maxlen
))
1158 strncpy(setting
, fptr
, len
-extlen
);
1159 setting
[len
-extlen
]=0;