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_FAILED
));
540 screens
[i
].puts(0, 1, str(LANG_SETTINGS_PARTITION
));
542 screens
[i
].puts(4, 2, str(LANG_SETTINGS_SAVE_FAILED
));
543 screens
[i
].puts(2, 4, str(LANG_SETTINGS_PARTITION
));
547 cond_talk_ids_fq(LANG_SETTINGS_SAVE_FAILED
);
553 bool settings_save_config(int options
)
555 char filename
[MAX_PATH
];
559 case SETTINGS_SAVE_THEME
:
562 #ifdef HAVE_RECORDING
563 case SETTINGS_SAVE_RECPRESETS
:
564 folder
= RECPRESETS_DIR
;
568 folder
= ROCKBOX_DIR
;
570 create_numbered_filename(filename
, folder
, "config", ".cfg", 2
571 IF_CNFN_NUM_(, NULL
));
573 /* allow user to modify filename */
575 if (!kbd_input(filename
, sizeof filename
)) {
579 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
584 if (settings_write_config(filename
, options
))
585 gui_syncsplash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
587 gui_syncsplash(HZ
, ID2P(LANG_FAILED
));
591 /** Apply and Reset settings **/
594 #ifdef HAVE_LCD_BITMAP
596 * Applies the range infos stored in global_settings to
599 void settings_apply_pm_range(void)
603 /* depending on the scale mode (dBfs or percent) the values
604 of global_settings.peak_meter_dbfs have different meanings */
605 if (global_settings
.peak_meter_dbfs
)
607 /* convert to dBfs * 100 */
608 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
609 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
613 /* percent is stored directly -> no conversion */
614 pm_min
= global_settings
.peak_meter_min
;
615 pm_max
= global_settings
.peak_meter_max
;
618 /* apply the range */
619 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
621 #endif /* HAVE_LCD_BITMAP */
623 void sound_settings_apply(void)
625 #if CONFIG_CODEC == SWCODEC
626 sound_set_dsp_callback(dsp_callback
);
628 sound_set(SOUND_BASS
, global_settings
.bass
);
629 sound_set(SOUND_TREBLE
, global_settings
.treble
);
630 sound_set(SOUND_BALANCE
, global_settings
.balance
);
631 sound_set(SOUND_VOLUME
, global_settings
.volume
);
632 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
633 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
634 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
635 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
636 sound_set(SOUND_AVC
, global_settings
.avc
);
637 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
638 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
639 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
640 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
641 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
642 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
645 #ifdef HAVE_USB_POWER
647 usb_charging_enable(global_settings
.usb_charging
);
652 void settings_apply(void)
655 #if CONFIG_CODEC == SWCODEC
659 DEBUGF( "settings_apply()\n" );
660 sound_settings_apply();
662 #ifndef HAVE_FLASH_STORAGE
663 audio_set_buffer_margin(global_settings
.buffer_margin
);
666 #ifdef HAVE_LCD_CONTRAST
667 lcd_set_contrast(global_settings
.contrast
);
669 lcd_scroll_speed(global_settings
.scroll_speed
);
670 #ifdef HAVE_REMOTE_LCD
671 lcd_remote_set_contrast(global_settings
.remote_contrast
);
672 lcd_remote_set_invert_display(global_settings
.remote_invert
);
673 lcd_remote_set_flip(global_settings
.remote_flip_display
);
674 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
675 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
676 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
677 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
678 #ifdef HAVE_REMOTE_LCD_TICKING
679 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
681 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
683 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
685 #ifdef HAS_REMOTE_BUTTON_HOLD
686 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
688 #endif /* HAVE_REMOTE_LCD */
689 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
690 backlight_set_brightness(global_settings
.brightness
);
692 #ifdef HAVE_BACKLIGHT
693 backlight_set_timeout(global_settings
.backlight_timeout
);
695 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
697 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
698 backlight_set_fade_in(global_settings
.backlight_fade_in
);
699 backlight_set_fade_out(global_settings
.backlight_fade_out
);
702 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
703 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
705 #ifdef HAVE_BUTTON_LIGHT
706 button_backlight_set_timeout(global_settings
.button_light_timeout
);
708 #ifndef HAVE_FLASH_STORAGE
709 ata_spindown(global_settings
.disk_spindown
);
711 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
712 dac_line_in(global_settings
.line_in
);
714 mpeg_id3_options(global_settings
.id3_v1_first
);
716 set_poweroff_timeout(global_settings
.poweroff
);
718 set_battery_capacity(global_settings
.battery_capacity
);
719 #if BATTERY_TYPES_COUNT > 1
720 set_battery_type(global_settings
.battery_type
);
723 #ifdef HAVE_LCD_BITMAP
724 lcd_set_invert_display(global_settings
.invert
);
725 lcd_set_flip(global_settings
.flip_display
);
726 button_set_flip(global_settings
.flip_display
);
727 lcd_update(); /* refresh after flipping the screen */
728 settings_apply_pm_range();
729 peak_meter_init_times(
730 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
731 global_settings
.peak_meter_clip_hold
);
735 unload_wps_backdrop();
737 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
738 unload_remote_wps_backdrop();
740 if ( global_settings
.wps_file
[0] &&
741 global_settings
.wps_file
[0] != 0xff ) {
742 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.wps",
743 global_settings
.wps_file
);
744 wps_data_load(gui_wps
[0].data
, buf
, true);
748 wps_data_init(gui_wps
[0].data
);
749 #ifdef HAVE_REMOTE_LCD
750 gui_wps
[0].data
->remote_wps
= false;
755 if ( global_settings
.backdrop_file
[0] &&
756 global_settings
.backdrop_file
[0] != 0xff ) {
757 snprintf(buf
, sizeof buf
, BACKDROP_DIR
"/%s.bmp",
758 global_settings
.backdrop_file
);
759 load_main_backdrop(buf
);
761 unload_main_backdrop();
763 show_main_backdrop();
765 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
766 show_remote_main_backdrop();
769 #ifdef HAVE_LCD_COLOR
770 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
771 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
774 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
775 if ( global_settings
.rwps_file
[0]) {
776 snprintf(buf
, sizeof buf
, WPS_DIR
"/%s.rwps",
777 global_settings
.rwps_file
);
778 wps_data_load(gui_wps
[1].data
, buf
, true);
782 wps_data_init(gui_wps
[1].data
);
783 gui_wps
[1].data
->remote_wps
= true;
787 #ifdef HAVE_LCD_BITMAP
788 if ( global_settings
.font_file
[0]) {
789 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
790 global_settings
.font_file
);
796 if ( global_settings
.kbd_file
[0]) {
797 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
798 global_settings
.kbd_file
);
804 lcd_scroll_step(global_settings
.scroll_step
);
805 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
806 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
808 lcd_jump_scroll(global_settings
.jump_scroll
);
809 lcd_jump_scroll_delay(global_settings
.jump_scroll_delay
);
811 lcd_bidir_scroll(global_settings
.bidir_limit
);
812 lcd_scroll_delay(global_settings
.scroll_delay
);
814 if ( global_settings
.lang_file
[0]) {
815 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
816 global_settings
.lang_file
);
818 talk_init(); /* use voice of same language */
821 set_codepage(global_settings
.default_codepage
);
823 #if CONFIG_CODEC == SWCODEC
824 audio_set_crossfade(global_settings
.crossfade
);
825 dsp_set_replaygain();
826 dsp_set_crossfeed(global_settings
.crossfeed
);
827 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
828 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
829 global_settings
.crossfeed_hf_attenuation
,
830 global_settings
.crossfeed_hf_cutoff
);
832 /* Configure software equalizer, hardware eq is handled in audio_init() */
833 dsp_set_eq(global_settings
.eq_enabled
);
834 dsp_set_eq_precut(global_settings
.eq_precut
);
835 for(i
= 0; i
< 5; i
++) {
839 dsp_dither_enable(global_settings
.dithering_enabled
);
842 #ifdef HAVE_SPDIF_POWER
843 spdif_power_enable(global_settings
.spdif_enable
);
846 #ifdef HAVE_BACKLIGHT
847 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
848 #ifdef HAVE_REMOTE_LCD
849 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
851 #ifdef HAS_BUTTON_HOLD
852 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
854 #ifdef HAVE_LCD_SLEEP
855 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
857 #endif /* HAVE_BACKLIGHT */
859 /* This should stay last */
860 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
861 enc_global_settings_apply();
863 /* load the icon set */
866 #ifdef HAVE_LCD_COLOR
867 if (global_settings
.colors_file
)
868 read_color_theme_file();
877 * reset all settings to their default value
879 void settings_reset(void) {
882 DEBUGF( "settings_reset()\n" );
884 for(i
=0; i
<nb_settings
; i
++)
886 switch (settings
[i
].flags
&F_T_MASK
)
890 if (settings
[i
].flags
&F_DEF_ISFUNC
)
891 *(int*)settings
[i
].setting
= settings
[i
].default_val
.func();
892 else if (settings
[i
].flags
&F_T_SOUND
)
893 *(int*)settings
[i
].setting
=
894 sound_default(settings
[i
].sound_setting
->setting
);
895 else *(int*)settings
[i
].setting
= settings
[i
].default_val
.int_
;
898 *(bool*)settings
[i
].setting
= settings
[i
].default_val
.bool_
;
902 strncpy((char*)settings
[i
].setting
,
903 settings
[i
].default_val
.charptr
,MAX_FILENAME
);
907 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
908 enc_global_settings_reset();
912 /** Changing setting values **/
913 const struct settings_list
* find_setting(void* variable
, int *id
)
916 for(i
=0;i
<nb_settings
;i
++)
918 if (settings
[i
].setting
== variable
)
928 void talk_setting(void *global_settings_variable
)
930 const struct settings_list
*setting
;
931 if (!talk_menus_enabled())
933 setting
= find_setting(global_settings_variable
, NULL
);
936 if (setting
->lang_id
)
937 talk_id(setting
->lang_id
,false);
940 bool set_bool(const char* string
, bool* variable
)
942 return set_bool_options(string
, variable
,
943 (char *)STR(LANG_SET_BOOL_YES
),
944 (char *)STR(LANG_SET_BOOL_NO
),
949 bool set_bool_options(const char* string
, bool* variable
,
950 const char* yes_str
, int yes_voice
,
951 const char* no_str
, int no_voice
,
952 void (*function
)(bool))
954 struct opt_items names
[] = {
955 {(unsigned char *)no_str
, no_voice
},
956 {(unsigned char *)yes_str
, yes_voice
}
960 result
= set_option(string
, variable
, BOOL
, names
, 2,
961 (void (*)(int))function
);
965 bool set_int(const unsigned char* string
,
969 void (*function
)(int),
973 void (*formatter
)(char*, int, int, const char*) )
975 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
976 step
, min
, max
, formatter
, NULL
);
980 /** extra stuff which is probably misplaced **/
982 void set_file(char* filename
, char* setting
, int maxlen
)
984 char* fptr
= strrchr(filename
,'/');
997 while ((*ptr
!= '.') && (ptr
!= fptr
)) {
1001 if(ptr
== fptr
) extlen
= 0;
1003 if (strncasecmp(ROCKBOX_DIR
, filename
,strlen(ROCKBOX_DIR
)) ||
1004 (len
-extlen
> maxlen
))
1007 strncpy(setting
, fptr
, len
-extlen
);
1008 setting
[len
-extlen
]=0;