1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by wavey@wavey.org
11 * RTC config saving code (C) 2002 by hessu@hes.iki.fi
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
31 #include "backlight.h"
38 #include "ata_idle_notify.h"
45 #ifdef HAVE_LCD_BITMAP
48 #include "peakmeter.h"
53 #include "powermgmt.h"
58 #include "rbunicode.h"
60 #include "statusbar.h"
63 #include "settings_list.h"
64 #include "filetypes.h"
66 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
74 #if CONFIG_CODEC == MAS3507D
75 void dac_line_in(bool enable
);
77 struct user_settings global_settings
;
78 struct system_status global_status
;
80 #if CONFIG_CODEC == SWCODEC
82 #include "pcm_playback.h"
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
) && (var_count
>0) && (buf_pos
<max_len
); i
++)
148 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
149 >>F_NVRAM_MASK_SHIFT
;
152 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
153 buf_pos
+= nvram_bytes
;
159 static bool write_nvram_data(char* buf
, int max_len
)
161 unsigned crc32
= 0xffffffff;
162 int i
= 0, buf_pos
= 0;
167 memset(buf
,0,max_len
);
169 buf
[0] = 'R'; buf
[1] = 'b';
170 buf
[2] = NVRAM_CONFIG_VERSION
;
171 buf_pos
= NVRAM_DATA_START
;
172 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
174 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
175 >>F_NVRAM_MASK_SHIFT
;
178 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
179 buf_pos
+= nvram_bytes
;
183 /* count and crc32 */
185 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
186 max_len
-NVRAM_DATA_START
-1,0xffffffff);
187 memcpy(&buf
[4],&crc32
,4);
189 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
);
192 int len
= write(fd
,buf
,max_len
);
198 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
199 that it would write a number of bytes at a time since the RTC chip
200 supports that, but this will have to do for now 8-) */
201 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
202 int r
= rtc_write(0x14+i
, buf
[i
]);
204 DEBUGF( "save_config_buffer: rtc_write failed at addr 0x%02x: %d\n",
213 /** Reading from a config file **/
215 * load settings from disk or RTC RAM
217 void settings_load(int which
)
219 DEBUGF( "reload_all_settings()\n" );
220 if (which
&SETTINGS_RTC
)
221 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
222 if (which
&SETTINGS_HD
)
224 settings_load_config(CONFIGFILE
,false);
225 settings_load_config(FIXEDSETTINGSFILE
,false);
229 static bool cfg_string_to_int(int setting_id
, int* out
, char* str
)
231 const char* start
= settings
[setting_id
].cfg_vals
;
237 end
= strchr(start
, ',');
240 if (!strcmp(str
, start
))
247 strncpy(temp
, start
, end
-start
);
248 temp
[end
-start
] = '\0';
249 if (!strcmp(str
, temp
))
260 bool settings_load_config(const char* file
, bool apply
)
267 fd
= open(file
, O_RDONLY
);
271 while (read_line(fd
, line
, sizeof line
) > 0)
273 if (!settings_parseline(line
, &name
, &value
))
275 for(i
=0; i
<nb_settings
; i
++)
277 if (settings
[i
].cfg_name
== NULL
)
279 if (!strcasecmp(name
,settings
[i
].cfg_name
))
281 switch (settings
[i
].flags
&F_T_MASK
)
285 #ifdef HAVE_LCD_COLOR
286 if (settings
[i
].flags
&F_RGB
)
287 *(int*)settings
[i
].setting
= hex_to_rgb(value
);
290 if (settings
[i
].cfg_vals
== NULL
)
292 *(int*)settings
[i
].setting
= atoi(value
);
296 cfg_string_to_int(i
,(int*)settings
[i
].setting
,value
);
302 if (cfg_string_to_int(i
,&temp
,value
))
303 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
309 char storage
[MAX_PATH
];
310 if (settings
[i
].filename_setting
->prefix
)
312 int len
= strlen(settings
[i
].filename_setting
->prefix
);
313 if (!strncasecmp(value
,
314 settings
[i
].filename_setting
->prefix
,
317 strncpy(storage
,&value
[len
],MAX_PATH
);
319 else strncpy(storage
,value
,MAX_PATH
);
321 else strncpy(storage
,value
,MAX_PATH
);
322 if (settings
[i
].filename_setting
->suffix
)
324 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
327 strncpy((char*)settings
[i
].setting
,storage
,
328 settings
[i
].filename_setting
->max_len
);
329 ((char*)settings
[i
].setting
)
330 [settings
[i
].filename_setting
->max_len
-1] = '\0';
335 } /* if (!strcmp(name,settings[i].cfg_name)) */
346 /** Writing to a config file and saving settings **/
348 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
350 const char* start
= settings
[setting_id
].cfg_vals
;
355 start
= strchr(start
,',');
361 end
= strchr(start
,',');
363 strncpy(buf
, start
, buf_len
);
366 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
367 strncpy(buf
, start
, len
);
372 static bool is_changed(int setting_id
)
374 const struct settings_list
*setting
= &settings
[setting_id
];
375 switch (setting
->flags
&F_T_MASK
)
379 if (setting
->flags
&F_DEF_ISFUNC
)
381 if (*(int*)setting
->setting
== setting
->default_val
.func())
384 else if (setting
->flags
&F_T_SOUND
)
386 if (*(int*)setting
->setting
==
387 sound_default(setting
->sound_setting
->setting
))
390 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
394 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
399 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
406 static bool settings_write_config(char* filename
, int options
)
410 char value
[MAX_PATH
];
411 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
414 fdprintf(fd
, "# .cfg file created by rockbox %s - "
415 "http://www.rockbox.org\r\n\r\n", appsversion
);
416 for(i
=0; i
<nb_settings
; i
++)
418 if (settings
[i
].cfg_name
== NULL
)
422 if ((options
== SETTINGS_SAVE_CHANGED
) &&
425 else if ((options
== SETTINGS_SAVE_THEME
) &&
426 ((settings
[i
].flags
&F_THEMESETTING
) == 0))
428 #ifdef HAVE_RECORDING
429 else if ((options
== SETTINGS_SAVE_RECPRESETS
) &&
430 ((settings
[i
].flags
&F_RECSETTING
) == 0))
433 switch (settings
[i
].flags
&F_T_MASK
)
437 #ifdef HAVE_LCD_COLOR
438 if (settings
[i
].flags
&F_RGB
)
440 int colour
= *(int*)settings
[i
].setting
;
441 snprintf(value
,MAX_PATH
,"%02x%02x%02x",
442 (int)RGB_UNPACK_RED(colour
),
443 (int)RGB_UNPACK_GREEN(colour
),
444 (int)RGB_UNPACK_BLUE(colour
));
448 if (settings
[i
].cfg_vals
== NULL
)
450 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
454 cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
460 *(bool*)settings
[i
].setting
==false?0:1, value
, MAX_PATH
);
464 if (((char*)settings
[i
].setting
)[0] == '\0')
466 if (settings
[i
].filename_setting
->prefix
)
468 snprintf(value
,MAX_PATH
,"%s%s%s",
469 settings
[i
].filename_setting
->prefix
,
470 (char*)settings
[i
].setting
,
471 settings
[i
].filename_setting
->suffix
);
473 else strncpy(value
,(char*)settings
[i
].setting
,
474 settings
[i
].filename_setting
->max_len
);
478 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
484 static bool flush_global_status_callback(void)
486 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
489 static bool flush_config_block_callback(void)
492 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
493 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
498 * persist all runtime user settings to disk or RTC RAM
500 static void update_runtime(void)
504 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
505 global_status
.runtime
+= elapsed_secs
;
506 lasttime
+= (elapsed_secs
* HZ
);
508 if ( global_status
.runtime
> global_status
.topruntime
)
509 global_status
.topruntime
= global_status
.runtime
;
512 void status_save( void )
516 /* this will be done in the ata_callback if
517 target doesnt have rtc ram */
518 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
520 register_ata_idle_func(flush_global_status_callback
);
524 int settings_save( void )
528 /* this will be done in the ata_callback if
529 target doesnt have rtc ram */
530 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
532 if(!register_ata_idle_func(flush_config_block_callback
))
537 screens
[i
].clear_display();
538 #ifdef HAVE_LCD_CHARCELLS
539 screens
[i
].puts(0, 0, str(LANG_SETTINGS_SAVE_PLAYER
));
540 screens
[i
].puts(0, 1, str(LANG_SETTINGS_BATTERY_PLAYER
));
542 screens
[i
].puts(4, 2, str(LANG_SETTINGS_SAVE_RECORDER
));
543 screens
[i
].puts(2, 4, str(LANG_SETTINGS_BATTERY_RECORDER
));
552 bool settings_save_config(int options
)
554 char filename
[MAX_PATH
];
558 case SETTINGS_SAVE_THEME
:
561 #ifdef HAVE_RECORDING
562 case SETTINGS_SAVE_RECPRESETS
:
563 folder
= RECPRESETS_DIR
;
567 folder
= ROCKBOX_DIR
;
569 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
570 IF_CNFN_NUM_(, NULL
));
572 /* allow user to modify filename */
574 if (!kbd_input(filename
, sizeof filename
)) {
578 gui_syncsplash(HZ
, str(LANG_MENU_SETTING_CANCEL
));
583 if (settings_write_config(filename
, options
))
584 gui_syncsplash(HZ
, str(LANG_SETTINGS_SAVED
));
586 gui_syncsplash(HZ
, str(LANG_FAILED
));
590 /** Apply and Reset settings **/
593 #ifdef HAVE_LCD_BITMAP
595 * Applies the range infos stored in global_settings to
598 void settings_apply_pm_range(void)
602 /* depending on the scale mode (dBfs or percent) the values
603 of global_settings.peak_meter_dbfs have different meanings */
604 if (global_settings
.peak_meter_dbfs
)
606 /* convert to dBfs * 100 */
607 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
608 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
612 /* percent is stored directly -> no conversion */
613 pm_min
= global_settings
.peak_meter_min
;
614 pm_max
= global_settings
.peak_meter_max
;
617 /* apply the range */
618 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
620 #endif /* HAVE_LCD_BITMAP */
622 void sound_settings_apply(void)
624 #if CONFIG_CODEC == SWCODEC
625 sound_set_dsp_callback(dsp_callback
);
627 sound_set(SOUND_BASS
, global_settings
.bass
);
628 sound_set(SOUND_TREBLE
, global_settings
.treble
);
629 sound_set(SOUND_BALANCE
, global_settings
.balance
);
630 sound_set(SOUND_VOLUME
, global_settings
.volume
);
631 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
632 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
633 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
634 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
635 sound_set(SOUND_AVC
, global_settings
.avc
);
636 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
637 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
638 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
639 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
640 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
641 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
644 #ifdef HAVE_USB_POWER
646 usb_charging_enable(global_settings
.usb_charging
);
651 void settings_apply(void)
654 #if CONFIG_CODEC == SWCODEC
658 DEBUGF( "settings_apply()\n" );
659 sound_settings_apply();
661 audio_set_buffer_margin(global_settings
.buffer_margin
);
663 #ifdef HAVE_LCD_CONTRAST
664 lcd_set_contrast(global_settings
.contrast
);
666 lcd_scroll_speed(global_settings
.scroll_speed
);
667 #ifdef HAVE_REMOTE_LCD
668 lcd_remote_set_contrast(global_settings
.remote_contrast
);
669 lcd_remote_set_invert_display(global_settings
.remote_invert
);
670 lcd_remote_set_flip(global_settings
.remote_flip_display
);
671 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
672 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
673 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
674 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
675 #ifdef HAVE_REMOTE_LCD_TICKING
676 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
678 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
680 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
682 #ifdef HAS_REMOTE_BUTTON_HOLD
683 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
685 #endif /* HAVE_REMOTE_LCD */
686 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
687 backlight_set_brightness(global_settings
.brightness
);
689 #ifdef HAVE_BACKLIGHT
690 backlight_set_timeout(global_settings
.backlight_timeout
);
692 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
694 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
695 backlight_set_fade_in(global_settings
.backlight_fade_in
);
696 backlight_set_fade_out(global_settings
.backlight_fade_out
);
699 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
700 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
702 #ifdef HAVE_BUTTON_LIGHT
703 button_backlight_set_timeout(global_settings
.button_light_timeout
);
705 ata_spindown(global_settings
.disk_spindown
);
706 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
707 dac_line_in(global_settings
.line_in
);
709 mpeg_id3_options(global_settings
.id3_v1_first
);
711 set_poweroff_timeout(global_settings
.poweroff
);
713 set_battery_capacity(global_settings
.battery_capacity
);
714 #if BATTERY_TYPES_COUNT > 1
715 set_battery_type(global_settings
.battery_type
);
718 #ifdef HAVE_LCD_BITMAP
719 lcd_set_invert_display(global_settings
.invert
);
720 lcd_set_flip(global_settings
.flip_display
);
721 button_set_flip(global_settings
.flip_display
);
722 lcd_update(); /* refresh after flipping the screen */
723 settings_apply_pm_range();
724 peak_meter_init_times(
725 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
726 global_settings
.peak_meter_clip_hold
);
730 unload_wps_backdrop();
732 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
733 unload_remote_wps_backdrop();
735 if ( global_settings
.wps_file
[0] &&
736 global_settings
.wps_file
[0] != 0xff ) {
737 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
738 global_settings
.wps_file
);
739 wps_data_load(gui_wps
[0].data
, buf
, true);
743 wps_data_init(gui_wps
[0].data
);
744 #ifdef HAVE_REMOTE_LCD
745 gui_wps
[0].data
->remote_wps
= false;
750 if ( global_settings
.backdrop_file
[0] &&
751 global_settings
.backdrop_file
[0] != 0xff ) {
752 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
753 global_settings
.backdrop_file
);
754 load_main_backdrop(buf
);
756 unload_main_backdrop();
758 show_main_backdrop();
760 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
761 show_remote_main_backdrop();
764 #ifdef HAVE_LCD_COLOR
765 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
766 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
769 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
770 if ( global_settings
.rwps_file
[0]) {
771 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
772 global_settings
.rwps_file
);
773 wps_data_load(gui_wps
[1].data
, buf
, true);
777 wps_data_init(gui_wps
[1].data
);
778 gui_wps
[1].data
->remote_wps
= true;
782 #ifdef HAVE_LCD_BITMAP
783 if ( global_settings
.font_file
[0]) {
784 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
785 global_settings
.font_file
);
791 if ( global_settings
.kbd_file
[0]) {
792 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
793 global_settings
.kbd_file
);
799 lcd_scroll_step(global_settings
.scroll_step
);
800 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
801 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
803 lcd_jump_scroll(global_settings
.jump_scroll
);
804 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
806 lcd_bidir_scroll(global_settings
.bidir_limit
);
807 lcd_scroll_delay(global_settings
.scroll_delay
);
809 if ( global_settings
.lang_file
[0]) {
810 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
811 global_settings
.lang_file
);
813 talk_init(); /* use voice of same language */
816 set_codepage(global_settings
.default_codepage
);
818 #if CONFIG_CODEC == SWCODEC
819 audio_set_crossfade(global_settings
.crossfade
);
820 dsp_set_replaygain();
821 dsp_set_crossfeed(global_settings
.crossfeed
);
822 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
823 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
824 global_settings
.crossfeed_hf_attenuation
,
825 global_settings
.crossfeed_hf_cutoff
);
827 /* Configure software equalizer, hardware eq is handled in audio_init() */
828 dsp_set_eq(global_settings
.eq_enabled
);
829 dsp_set_eq_precut(global_settings
.eq_precut
);
830 for(i
= 0; i
< 5; i
++) {
834 dsp_dither_enable(global_settings
.dithering_enabled
);
837 #ifdef HAVE_SPDIF_POWER
838 spdif_power_enable(global_settings
.spdif_enable
);
841 #ifdef HAVE_BACKLIGHT
842 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
843 #ifdef HAVE_REMOTE_LCD
844 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
846 #ifdef HAS_BUTTON_HOLD
847 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
849 #ifdef HAVE_LCD_SLEEP
850 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
852 #endif /* HAVE_BACKLIGHT */
854 /* This should stay last */
855 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
856 enc_global_settings_apply();
858 /* load the icon set */
861 #ifdef HAVE_LCD_COLOR
862 if (global_settings
.colors_file
)
863 read_color_theme_file();
872 * reset all settings to their default value
874 void settings_reset(void) {
877 DEBUGF( "settings_reset()\n" );
879 for(i
=0; i
<nb_settings
; i
++)
881 switch (settings
[i
].flags
&F_T_MASK
)
885 if (settings
[i
].flags
&F_DEF_ISFUNC
)
886 *(int*)settings
[i
].setting
= settings
[i
].default_val
.func();
887 else if (settings
[i
].flags
&F_T_SOUND
)
888 *(int*)settings
[i
].setting
=
889 sound_default(settings
[i
].sound_setting
->setting
);
890 else *(int*)settings
[i
].setting
= settings
[i
].default_val
.int_
;
893 *(bool*)settings
[i
].setting
= settings
[i
].default_val
.bool_
;
897 strncpy((char*)settings
[i
].setting
,
898 settings
[i
].default_val
.charptr
,MAX_FILENAME
);
902 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
903 enc_global_settings_reset();
907 /** Changing setting values **/
908 const struct settings_list
* find_setting(void* variable
, int *id
)
911 for(i
=0;i
<nb_settings
;i
++)
913 if (settings
[i
].setting
== variable
)
923 void talk_setting(void *global_settings_variable
)
925 const struct settings_list
*setting
;
926 if (!talk_menus_enabled())
928 setting
= find_setting(global_settings_variable
, NULL
);
931 if (setting
->lang_id
)
932 talk_id(setting
->lang_id
,false);
935 bool set_bool(const char* string
, bool* variable
)
937 return set_bool_options(string
, variable
,
938 (char *)STR(LANG_SET_BOOL_YES
),
939 (char *)STR(LANG_SET_BOOL_NO
),
944 bool set_bool_options(const char* string
, bool* variable
,
945 const char* yes_str
, int yes_voice
,
946 const char* no_str
, int no_voice
,
947 void (*function
)(bool))
949 struct opt_items names
[] = {
950 {(unsigned char *)no_str
, no_voice
},
951 {(unsigned char *)yes_str
, yes_voice
}
955 result
= set_option(string
, variable
, BOOL
, names
, 2,
956 (void (*)(int))function
);
960 bool set_int(const unsigned char* string
,
964 void (*function
)(int),
968 void (*formatter
)(char*, int, int, const char*) )
970 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
971 step
, min
, max
, formatter
, NULL
);
975 /** extra stuff which is probably misplaced **/
977 void set_file(char* filename
, char* setting
, int maxlen
)
979 char* fptr
= strrchr(filename
,'/');
992 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
996 if(ptr
== fptr
) extlen
= 0;
998 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
999 (len
-extlen
> maxlen
))
1002 strncpy(setting
, fptr
, len
-extlen
);
1003 setting
[len
-extlen
]=0;