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
; 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
]);
211 DEBUGF( "save_config_buffer: rtc_write failed at addr 0x%02x: %d\n",
220 /** Reading from a config file **/
222 * load settings from disk or RTC RAM
224 void settings_load(int which
)
226 DEBUGF( "reload_all_settings()\n" );
227 if (which
&SETTINGS_RTC
)
228 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
229 if (which
&SETTINGS_HD
)
231 settings_load_config(CONFIGFILE
,false);
232 settings_load_config(FIXEDSETTINGSFILE
,false);
236 static bool cfg_string_to_int(int setting_id
, int* out
, char* str
)
238 const char* start
= settings
[setting_id
].cfg_vals
;
244 end
= strchr(start
, ',');
247 if (!strcmp(str
, start
))
254 strncpy(temp
, start
, end
-start
);
255 temp
[end
-start
] = '\0';
256 if (!strcmp(str
, temp
))
267 bool settings_load_config(const char* file
, bool apply
)
274 fd
= open(file
, O_RDONLY
);
278 while (read_line(fd
, line
, sizeof line
) > 0)
280 if (!settings_parseline(line
, &name
, &value
))
282 for(i
=0; i
<nb_settings
; i
++)
284 if (settings
[i
].cfg_name
== NULL
)
286 if (!strcasecmp(name
,settings
[i
].cfg_name
))
288 switch (settings
[i
].flags
&F_T_MASK
)
292 #ifdef HAVE_LCD_COLOR
293 if (settings
[i
].flags
&F_RGB
)
294 *(int*)settings
[i
].setting
= hex_to_rgb(value
);
297 if (settings
[i
].cfg_vals
== NULL
)
299 *(int*)settings
[i
].setting
= atoi(value
);
303 cfg_string_to_int(i
,(int*)settings
[i
].setting
,value
);
309 if (cfg_string_to_int(i
,&temp
,value
))
310 *(bool*)settings
[i
].setting
= (temp
==0?false:true);
316 char storage
[MAX_PATH
];
317 if (settings
[i
].filename_setting
->prefix
)
319 int len
= strlen(settings
[i
].filename_setting
->prefix
);
320 if (!strncasecmp(value
,
321 settings
[i
].filename_setting
->prefix
,
324 strncpy(storage
,&value
[len
],MAX_PATH
);
326 else strncpy(storage
,value
,MAX_PATH
);
328 else strncpy(storage
,value
,MAX_PATH
);
329 if (settings
[i
].filename_setting
->suffix
)
331 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
334 strncpy((char*)settings
[i
].setting
,storage
,
335 settings
[i
].filename_setting
->max_len
);
336 ((char*)settings
[i
].setting
)
337 [settings
[i
].filename_setting
->max_len
-1] = '\0';
342 } /* if (!strcmp(name,settings[i].cfg_name)) */
353 /** Writing to a config file and saving settings **/
355 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
357 const char* start
= settings
[setting_id
].cfg_vals
;
362 start
= strchr(start
,',');
368 end
= strchr(start
,',');
370 strncpy(buf
, start
, buf_len
);
373 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
374 strncpy(buf
, start
, len
);
379 static bool is_changed(int setting_id
)
381 const struct settings_list
*setting
= &settings
[setting_id
];
382 switch (setting
->flags
&F_T_MASK
)
386 if (setting
->flags
&F_DEF_ISFUNC
)
388 if (*(int*)setting
->setting
== setting
->default_val
.func())
391 else if (setting
->flags
&F_T_SOUND
)
393 if (*(int*)setting
->setting
==
394 sound_default(setting
->sound_setting
->setting
))
397 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
401 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
406 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
413 static bool settings_write_config(char* filename
, int options
)
417 char value
[MAX_PATH
];
418 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
);
421 fdprintf(fd
, "# .cfg file created by rockbox %s - "
422 "http://www.rockbox.org\r\n\r\n", appsversion
);
423 for(i
=0; i
<nb_settings
; i
++)
425 if (settings
[i
].cfg_name
== NULL
)
429 if ((options
== SETTINGS_SAVE_CHANGED
) &&
432 else if ((options
== SETTINGS_SAVE_THEME
) &&
433 ((settings
[i
].flags
&F_THEMESETTING
) == 0))
435 #ifdef HAVE_RECORDING
436 else if ((options
== SETTINGS_SAVE_RECPRESETS
) &&
437 ((settings
[i
].flags
&F_RECSETTING
) == 0))
440 switch (settings
[i
].flags
&F_T_MASK
)
444 #ifdef HAVE_LCD_COLOR
445 if (settings
[i
].flags
&F_RGB
)
447 int colour
= *(int*)settings
[i
].setting
;
448 snprintf(value
,MAX_PATH
,"%02x%02x%02x",
449 (int)RGB_UNPACK_RED(colour
),
450 (int)RGB_UNPACK_GREEN(colour
),
451 (int)RGB_UNPACK_BLUE(colour
));
455 if (settings
[i
].cfg_vals
== NULL
)
457 snprintf(value
,MAX_PATH
,"%d",*(int*)settings
[i
].setting
);
461 cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
467 *(bool*)settings
[i
].setting
==false?0:1, value
, MAX_PATH
);
471 if (((char*)settings
[i
].setting
)[0] == '\0')
473 if (settings
[i
].filename_setting
->prefix
)
475 snprintf(value
,MAX_PATH
,"%s%s%s",
476 settings
[i
].filename_setting
->prefix
,
477 (char*)settings
[i
].setting
,
478 settings
[i
].filename_setting
->suffix
);
480 else strncpy(value
,(char*)settings
[i
].setting
,
481 settings
[i
].filename_setting
->max_len
);
485 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
491 static bool flush_global_status_callback(void)
493 return write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
496 static bool flush_config_block_callback(void)
499 r1
= write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
500 r2
= settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
505 * persist all runtime user settings to disk or RTC RAM
507 static void update_runtime(void)
511 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
512 global_status
.runtime
+= elapsed_secs
;
513 lasttime
+= (elapsed_secs
* HZ
);
515 if ( global_status
.runtime
> global_status
.topruntime
)
516 global_status
.topruntime
= global_status
.runtime
;
519 void status_save( void )
523 /* this will be done in the ata_callback if
524 target doesnt have rtc ram */
525 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
527 register_ata_idle_func(flush_global_status_callback
);
531 int settings_save( void )
535 /* this will be done in the ata_callback if
536 target doesnt have rtc ram */
537 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
539 if(!register_ata_idle_func(flush_config_block_callback
))
544 screens
[i
].clear_display();
545 #ifdef HAVE_LCD_CHARCELLS
546 screens
[i
].puts(0, 0, str(LANG_SETTINGS_SAVE_FAILED
));
547 screens
[i
].puts(0, 1, str(LANG_SETTINGS_PARTITION
));
549 screens
[i
].puts(4, 2, str(LANG_SETTINGS_SAVE_FAILED
));
550 screens
[i
].puts(2, 4, str(LANG_SETTINGS_PARTITION
));
554 cond_talk_ids_fq(LANG_SETTINGS_SAVE_FAILED
);
560 bool settings_save_config(int options
)
562 char filename
[MAX_PATH
];
566 case SETTINGS_SAVE_THEME
:
569 #ifdef HAVE_RECORDING
570 case SETTINGS_SAVE_RECPRESETS
:
571 folder
= RECPRESETS_DIR
;
575 folder
= ROCKBOX_DIR
;
577 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
578 IF_CNFN_NUM_(, NULL
));
580 /* allow user to modify filename */
582 if (!kbd_input(filename
, sizeof filename
)) {
586 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
591 if (settings_write_config(filename
, options
))
592 gui_syncsplash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
594 gui_syncsplash(HZ
, ID2P(LANG_FAILED
));
598 /** Apply and Reset settings **/
601 #ifdef HAVE_LCD_BITMAP
603 * Applies the range infos stored in global_settings to
606 void settings_apply_pm_range(void)
610 /* depending on the scale mode (dBfs or percent) the values
611 of global_settings.peak_meter_dbfs have different meanings */
612 if (global_settings
.peak_meter_dbfs
)
614 /* convert to dBfs * 100 */
615 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
616 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
620 /* percent is stored directly -> no conversion */
621 pm_min
= global_settings
.peak_meter_min
;
622 pm_max
= global_settings
.peak_meter_max
;
625 /* apply the range */
626 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
628 #endif /* HAVE_LCD_BITMAP */
630 void sound_settings_apply(void)
632 #if CONFIG_CODEC == SWCODEC
633 sound_set_dsp_callback(dsp_callback
);
635 sound_set(SOUND_BASS
, global_settings
.bass
);
636 sound_set(SOUND_TREBLE
, global_settings
.treble
);
637 sound_set(SOUND_BALANCE
, global_settings
.balance
);
638 sound_set(SOUND_VOLUME
, global_settings
.volume
);
639 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
640 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
641 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
642 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
643 sound_set(SOUND_AVC
, global_settings
.avc
);
644 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
645 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
646 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
647 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
648 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
649 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
652 #ifdef HAVE_USB_POWER
654 usb_charging_enable(global_settings
.usb_charging
);
659 void settings_apply(void)
662 #if CONFIG_CODEC == SWCODEC
666 DEBUGF( "settings_apply()\n" );
667 sound_settings_apply();
669 #ifndef HAVE_FLASH_STORAGE
670 audio_set_buffer_margin(global_settings
.buffer_margin
);
673 #ifdef HAVE_LCD_CONTRAST
674 lcd_set_contrast(global_settings
.contrast
);
676 lcd_scroll_speed(global_settings
.scroll_speed
);
677 #ifdef HAVE_REMOTE_LCD
678 lcd_remote_set_contrast(global_settings
.remote_contrast
);
679 lcd_remote_set_invert_display(global_settings
.remote_invert
);
680 lcd_remote_set_flip(global_settings
.remote_flip_display
);
681 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
682 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
683 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
684 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
685 #ifdef HAVE_REMOTE_LCD_TICKING
686 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
688 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
690 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
692 #ifdef HAS_REMOTE_BUTTON_HOLD
693 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
695 #endif /* HAVE_REMOTE_LCD */
696 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
697 backlight_set_brightness(global_settings
.brightness
);
699 #ifdef HAVE_BACKLIGHT
700 backlight_set_timeout(global_settings
.backlight_timeout
);
702 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
704 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
705 backlight_set_fade_in(global_settings
.backlight_fade_in
);
706 backlight_set_fade_out(global_settings
.backlight_fade_out
);
709 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
710 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
712 #ifdef HAVE_BUTTON_LIGHT
713 button_backlight_set_timeout(global_settings
.button_light_timeout
);
715 #ifndef HAVE_FLASH_STORAGE
716 ata_spindown(global_settings
.disk_spindown
);
718 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
719 dac_line_in(global_settings
.line_in
);
721 mpeg_id3_options(global_settings
.id3_v1_first
);
723 set_poweroff_timeout(global_settings
.poweroff
);
725 set_battery_capacity(global_settings
.battery_capacity
);
726 #if BATTERY_TYPES_COUNT > 1
727 set_battery_type(global_settings
.battery_type
);
730 #ifdef HAVE_LCD_BITMAP
731 lcd_set_invert_display(global_settings
.invert
);
732 lcd_set_flip(global_settings
.flip_display
);
733 button_set_flip(global_settings
.flip_display
);
734 lcd_update(); /* refresh after flipping the screen */
735 settings_apply_pm_range();
736 peak_meter_init_times(
737 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
738 global_settings
.peak_meter_clip_hold
);
742 unload_wps_backdrop();
744 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
745 unload_remote_wps_backdrop();
747 if ( global_settings
.wps_file
[0] &&
748 global_settings
.wps_file
[0] != 0xff ) {
749 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
750 global_settings
.wps_file
);
751 wps_data_load(gui_wps
[0].data
, buf
, true);
755 wps_data_init(gui_wps
[0].data
);
756 #ifdef HAVE_REMOTE_LCD
757 gui_wps
[0].data
->remote_wps
= false;
762 if ( global_settings
.backdrop_file
[0] &&
763 global_settings
.backdrop_file
[0] != 0xff ) {
764 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
765 global_settings
.backdrop_file
);
766 load_main_backdrop(buf
);
768 unload_main_backdrop();
770 show_main_backdrop();
772 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
773 show_remote_main_backdrop();
776 #ifdef HAVE_LCD_COLOR
777 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
778 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
781 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
782 if ( global_settings
.rwps_file
[0]) {
783 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
784 global_settings
.rwps_file
);
785 wps_data_load(gui_wps
[1].data
, buf
, true);
789 wps_data_init(gui_wps
[1].data
);
790 gui_wps
[1].data
->remote_wps
= true;
794 #ifdef HAVE_LCD_BITMAP
795 if ( global_settings
.font_file
[0]) {
796 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
797 global_settings
.font_file
);
803 if ( global_settings
.kbd_file
[0]) {
804 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
805 global_settings
.kbd_file
);
811 lcd_scroll_step(global_settings
.scroll_step
);
812 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
813 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
815 lcd_jump_scroll(global_settings
.jump_scroll
);
816 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
818 lcd_bidir_scroll(global_settings
.bidir_limit
);
819 lcd_scroll_delay(global_settings
.scroll_delay
);
821 if ( global_settings
.lang_file
[0]) {
822 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
823 global_settings
.lang_file
);
825 talk_init(); /* use voice of same language */
828 set_codepage(global_settings
.default_codepage
);
830 #if CONFIG_CODEC == SWCODEC
831 audio_set_crossfade(global_settings
.crossfade
);
832 dsp_set_replaygain();
833 dsp_set_crossfeed(global_settings
.crossfeed
);
834 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
835 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
836 global_settings
.crossfeed_hf_attenuation
,
837 global_settings
.crossfeed_hf_cutoff
);
839 /* Configure software equalizer, hardware eq is handled in audio_init() */
840 dsp_set_eq(global_settings
.eq_enabled
);
841 dsp_set_eq_precut(global_settings
.eq_precut
);
842 for(i
= 0; i
< 5; i
++) {
846 dsp_dither_enable(global_settings
.dithering_enabled
);
849 #ifdef HAVE_SPDIF_POWER
850 spdif_power_enable(global_settings
.spdif_enable
);
853 #ifdef HAVE_BACKLIGHT
854 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
855 #ifdef HAVE_REMOTE_LCD
856 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
858 #ifdef HAS_BUTTON_HOLD
859 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
861 #ifdef HAVE_LCD_SLEEP
862 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
864 #endif /* HAVE_BACKLIGHT */
866 /* This should stay last */
867 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
868 enc_global_settings_apply();
870 /* load the icon set */
873 #ifdef HAVE_LCD_COLOR
874 if (global_settings
.colors_file
)
875 read_color_theme_file();
884 * reset all settings to their default value
886 void settings_reset(void) {
889 DEBUGF( "settings_reset()\n" );
891 for(i
=0; i
<nb_settings
; i
++)
893 switch (settings
[i
].flags
&F_T_MASK
)
897 if (settings
[i
].flags
&F_DEF_ISFUNC
)
898 *(int*)settings
[i
].setting
= settings
[i
].default_val
.func();
899 else if (settings
[i
].flags
&F_T_SOUND
)
900 *(int*)settings
[i
].setting
=
901 sound_default(settings
[i
].sound_setting
->setting
);
902 else *(int*)settings
[i
].setting
= settings
[i
].default_val
.int_
;
905 *(bool*)settings
[i
].setting
= settings
[i
].default_val
.bool_
;
909 strncpy((char*)settings
[i
].setting
,
910 settings
[i
].default_val
.charptr
,MAX_FILENAME
);
914 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
915 enc_global_settings_reset();
919 /** Changing setting values **/
920 const struct settings_list
* find_setting(void* variable
, int *id
)
923 for(i
=0;i
<nb_settings
;i
++)
925 if (settings
[i
].setting
== variable
)
935 void talk_setting(void *global_settings_variable
)
937 const struct settings_list
*setting
;
938 if (!talk_menus_enabled())
940 setting
= find_setting(global_settings_variable
, NULL
);
943 if (setting
->lang_id
)
944 talk_id(setting
->lang_id
,false);
947 bool set_bool(const char* string
, bool* variable
)
949 return set_bool_options(string
, variable
,
950 (char *)STR(LANG_SET_BOOL_YES
),
951 (char *)STR(LANG_SET_BOOL_NO
),
956 bool set_bool_options(const char* string
, bool* variable
,
957 const char* yes_str
, int yes_voice
,
958 const char* no_str
, int no_voice
,
959 void (*function
)(bool))
961 struct opt_items names
[] = {
962 {(unsigned char *)no_str
, no_voice
},
963 {(unsigned char *)yes_str
, yes_voice
}
967 result
= set_option(string
, variable
, BOOL
, names
, 2,
968 (void (*)(int))function
);
972 bool set_int(const unsigned char* string
,
976 void (*function
)(int),
980 void (*formatter
)(char*, size_t, int, const char*) )
982 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
983 step
, min
, max
, formatter
, NULL
);
987 /** extra stuff which is probably misplaced **/
989 void set_file(char* filename
, char* setting
, int maxlen
)
991 char* fptr
= strrchr(filename
,'/');
1004 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1008 if(ptr
== fptr
) extlen
= 0;
1010 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1011 (len
-extlen
> maxlen
))
1014 strncpy(setting
, fptr
, len
-extlen
);
1015 setting
[len
-extlen
]=0;