Add platform file for Ipod 1G / 2G. Now only the front image is missing for building...
[Rockbox.git] / apps / settings.c
blob0cf38266a6a0c9501452e1520fe7fdfc3a9ec1e4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
20 #include <stdio.h>
21 #include <stddef.h>
22 #include <stdlib.h>
23 #include <limits.h>
24 #include "inttypes.h"
25 #include "config.h"
26 #include "action.h"
27 #include "crc32.h"
28 #include "settings.h"
29 #include "debug.h"
30 #include "usb.h"
31 #include "backlight.h"
32 #include "audio.h"
33 #include "mpeg.h"
34 #include "talk.h"
35 #include "string.h"
36 #include "rtc.h"
37 #include "power.h"
38 #include "ata_idle_notify.h"
39 #include "atoi.h"
40 #include "screens.h"
41 #include "ctype.h"
42 #include "file.h"
43 #include "system.h"
44 #include "misc.h"
45 #ifdef HAVE_LCD_BITMAP
46 #include "icons.h"
47 #include "font.h"
48 #include "peakmeter.h"
49 #endif
50 #include "lang.h"
51 #include "language.h"
52 #include "gwps.h"
53 #include "powermgmt.h"
54 #include "sprintf.h"
55 #include "keyboard.h"
56 #include "version.h"
57 #include "sound.h"
58 #include "rbunicode.h"
59 #include "dircache.h"
60 #include "statusbar.h"
61 #include "splash.h"
62 #include "list.h"
63 #include "settings_list.h"
64 #include "filetypes.h"
66 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
67 #include "backdrop.h"
68 #endif
70 #if CONFIG_TUNER
71 #include "radio.h"
72 #endif
74 #if CONFIG_CODEC == MAS3507D
75 void dac_line_in(bool enable);
76 #endif
77 struct user_settings global_settings;
78 struct system_status global_status;
80 #if CONFIG_CODEC == SWCODEC
81 #include "pcmbuf.h"
82 #include "pcm_playback.h"
83 #include "dsp.h"
84 #ifdef HAVE_RECORDING
85 #include "enc_config.h"
86 #endif
87 #endif /* CONFIG_CODEC == SWCODEC */
89 #define NVRAM_BLOCK_SIZE 44
91 #ifdef HAVE_LCD_BITMAP
92 #define MAX_LINES 10
93 #else
94 #define MAX_LINES 2
95 #endif
97 #ifdef HAVE_REMOTE_LCD
98 #include "lcd-remote.h"
99 #endif
101 long lasttime = 0;
103 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
104 /* NVRAM is set out as
105 [0] 'R'
106 [1] 'b'
107 [2] version
108 [3] stored variable count
109 [4-7] crc32 checksum
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;
120 #ifndef HAVE_RTC_RAM
121 int fd = open(NVRAM_FILE,O_RDONLY);
122 if (fd < 0)
123 return false;
124 memset(buf,0,max_len);
125 if (read(fd,buf,max_len) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
126 return false;
127 close(fd);
128 #else
129 memset(buf,0,max_len);
130 /* read rtc block */
131 for (i=0; i < max_len; i++ )
132 buf[i] = rtc_read(0x14+i);
133 #endif
134 /* check magic, version */
135 if ((buf[0] != 'R') || (buf[1] != 'b')
136 || (buf[2] != NVRAM_CONFIG_VERSION))
137 return false;
138 /* check crc32 */
139 crc32 = crc_32(&buf[NVRAM_DATA_START],
140 max_len-NVRAM_DATA_START-1,0xffffffff);
141 if (memcmp(&crc32,&buf[4],4))
142 return false;
143 /* all good, so read in the settings */
144 var_count = buf[3];
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;
150 if (nvram_bytes)
152 memcpy(settings[i].setting,&buf[buf_pos],nvram_bytes);
153 buf_pos += nvram_bytes;
154 var_count--;
157 return true;
159 static bool write_nvram_data(char* buf, int max_len)
161 unsigned crc32 = 0xffffffff;
162 int i = 0, buf_pos = 0;
163 char var_count = 0;
164 #ifndef HAVE_RTC_RAM
165 int fd;
166 #endif
167 memset(buf,0,max_len);
168 /* magic, version */
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;
176 if (nvram_bytes)
178 memcpy(&buf[buf_pos],settings[i].setting,nvram_bytes);
179 buf_pos += nvram_bytes;
180 var_count++;
183 /* count and crc32 */
184 buf[3] = var_count;
185 crc32 = crc_32(&buf[NVRAM_DATA_START],
186 max_len-NVRAM_DATA_START-1,0xffffffff);
187 memcpy(&buf[4],&crc32,4);
188 #ifndef HAVE_RTC_RAM
189 fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY);
190 if (fd >= 0)
192 int len = write(fd,buf,max_len);
193 close(fd);
194 if (len < 8)
195 return false;
197 #else
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]);
203 if (r) {
204 DEBUGF( "save_config_buffer: rtc_write failed at addr 0x%02x: %d\n",
205 14+i, r );
206 return false;
209 #endif
210 return true;
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;
232 char* end = NULL;
233 char temp[MAX_PATH];
234 int count = 0;
235 while (1)
237 end = strchr(start, ',');
238 if (!end)
240 if (!strcmp(str, start))
242 *out = count;
243 return true;
245 else return false;
247 strncpy(temp, start, end-start);
248 temp[end-start] = '\0';
249 if (!strcmp(str, temp))
251 *out = count;
252 return true;
254 start = end +1;
255 count++;
257 return false;
260 bool settings_load_config(const char* file, bool apply)
262 int fd;
263 char line[128];
264 char* name;
265 char* value;
266 int i;
267 fd = open(file, O_RDONLY);
268 if (fd < 0)
269 return false;
271 while (read_line(fd, line, sizeof line) > 0)
273 if (!settings_parseline(line, &name, &value))
274 continue;
275 for(i=0; i<nb_settings; i++)
277 if (settings[i].cfg_name == NULL)
278 continue;
279 if (!strcasecmp(name,settings[i].cfg_name))
281 switch (settings[i].flags&F_T_MASK)
283 case F_T_INT:
284 case F_T_UINT:
285 #ifdef HAVE_LCD_COLOR
286 if (settings[i].flags&F_RGB)
287 *(int*)settings[i].setting = hex_to_rgb(value);
288 else
289 #endif
290 if (settings[i].cfg_vals == NULL)
292 *(int*)settings[i].setting = atoi(value);
294 else
296 cfg_string_to_int(i,(int*)settings[i].setting,value);
298 break;
299 case F_T_BOOL:
301 int temp;
302 if (cfg_string_to_int(i,&temp,value))
303 *(bool*)settings[i].setting = (temp==0?false:true);
304 break;
306 case F_T_CHARPTR:
307 case F_T_UCHARPTR:
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,
315 len))
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);
325 if (s) *s = '\0';
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';
331 break;
334 break;
335 } /* if (!strcmp(name,settings[i].cfg_name)) */
336 } /* for(...) */
337 } /* while(...) */
339 close(fd);
340 settings_save();
341 if (apply)
342 settings_apply();
343 return true;
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;
351 char* end = NULL;
352 int count = 0;
353 while (count < val)
355 start = strchr(start,',');
356 if (!start)
357 return false;
358 count++;
359 start++;
361 end = strchr(start,',');
362 if (end == NULL)
363 strncpy(buf, start, buf_len);
364 else
366 int len = (buf_len > (end-start))? end-start: buf_len;
367 strncpy(buf, start, len);
368 buf[len] = '\0';
370 return true;
372 static bool is_changed(int setting_id)
374 const struct settings_list *setting = &settings[setting_id];
375 switch (setting->flags&F_T_MASK)
377 case F_T_INT:
378 case F_T_UINT:
379 if (setting->flags&F_DEF_ISFUNC)
381 if (*(int*)setting->setting == setting->default_val.func())
382 return false;
384 else if (setting->flags&F_T_SOUND)
386 if (*(int*)setting->setting ==
387 sound_default(setting->sound_setting->setting))
388 return false;
390 else if (*(int*)setting->setting == setting->default_val.int_)
391 return false;
392 break;
393 case F_T_BOOL:
394 if (*(bool*)setting->setting == setting->default_val.bool_)
395 return false;
396 break;
397 case F_T_CHARPTR:
398 case F_T_UCHARPTR:
399 if (!strcmp((char*)setting->setting, setting->default_val.charptr))
400 return false;
401 break;
403 return true;
406 static bool settings_write_config(char* filename, int options)
408 int i;
409 int fd;
410 char value[MAX_PATH];
411 fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY);
412 if (fd < 0)
413 return false;
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)
419 continue;
420 value[0] = '\0';
422 if ((options == SETTINGS_SAVE_CHANGED) &&
423 !is_changed(i))
424 continue;
425 else if ((options == SETTINGS_SAVE_THEME) &&
426 ((settings[i].flags&F_THEMESETTING) == 0))
427 continue;
428 #ifdef HAVE_RECORDING
429 else if ((options == SETTINGS_SAVE_RECPRESETS) &&
430 ((settings[i].flags&F_RECSETTING) == 0))
431 continue;
432 #endif
433 switch (settings[i].flags&F_T_MASK)
435 case F_T_INT:
436 case F_T_UINT:
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));
446 else
447 #endif
448 if (settings[i].cfg_vals == NULL)
450 snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting);
452 else
454 cfg_int_to_string(i, *(int*)settings[i].setting,
455 value, MAX_PATH);
457 break;
458 case F_T_BOOL:
459 cfg_int_to_string(i,
460 *(bool*)settings[i].setting==false?0:1, value, MAX_PATH);
461 break;
462 case F_T_CHARPTR:
463 case F_T_UCHARPTR:
464 if (((char*)settings[i].setting)[0] == '\0')
465 break;
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);
475 break;
476 } /* switch () */
477 if (value[0])
478 fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value);
479 } /* for(...) */
480 close(fd);
481 return true;
483 #ifndef HAVE_RTC_RAM
484 static bool flush_global_status_callback(void)
486 return write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
488 #endif
489 static bool flush_config_block_callback(void)
491 bool r1, r2;
492 r1 = write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
493 r2 = settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED);
494 return r1 || r2;
498 * persist all runtime user settings to disk or RTC RAM
500 static void update_runtime(void)
502 int elapsed_secs;
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 )
514 update_runtime();
515 #ifdef HAVE_RTC_RAM
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);
519 #else
520 register_ata_idle_func(flush_global_status_callback);
521 #endif
524 int settings_save( void )
526 update_runtime();
527 #ifdef HAVE_RTC_RAM
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);
531 #endif
532 if(!register_ata_idle_func(flush_config_block_callback))
534 int i;
535 FOR_NB_SCREENS(i)
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));
541 #else
542 screens[i].puts(4, 2, str(LANG_SETTINGS_SAVE_RECORDER));
543 screens[i].puts(2, 4, str(LANG_SETTINGS_BATTERY_RECORDER));
544 screens[i].update();
545 #endif
547 sleep(HZ*2);
548 return -1;
550 return 0;
552 bool settings_save_config(int options)
554 char filename[MAX_PATH];
555 char *folder;
556 switch (options)
558 case SETTINGS_SAVE_THEME:
559 folder = THEME_DIR;
560 break;
561 #ifdef HAVE_RECORDING
562 case SETTINGS_SAVE_RECPRESETS:
563 folder = RECPRESETS_DIR;
564 break;
565 #endif
566 default:
567 folder = ROCKBOX_DIR;
569 create_numbered_filename(filename, folder, "config", ".cfg", 2
570 IF_CNFN_NUM_(, NULL));
572 /* allow user to modify filename */
573 while (true) {
574 if (!kbd_input(filename, sizeof filename)) {
575 break;
577 else {
578 gui_syncsplash(HZ, str(LANG_MENU_SETTING_CANCEL));
579 return false;
583 if (settings_write_config(filename, options))
584 gui_syncsplash(HZ, str(LANG_SETTINGS_SAVED));
585 else
586 gui_syncsplash(HZ, str(LANG_FAILED));
587 return true;
590 /** Apply and Reset settings **/
593 #ifdef HAVE_LCD_BITMAP
595 * Applies the range infos stored in global_settings to
596 * the peak meter.
598 void settings_apply_pm_range(void)
600 int pm_min, pm_max;
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);
610 else
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);
626 #endif
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);
642 #endif
644 #ifdef HAVE_USB_POWER
645 #if CONFIG_CHARGING
646 usb_charging_enable(global_settings.usb_charging);
647 #endif
648 #endif
651 void settings_apply(void)
653 char buf[64];
654 #if CONFIG_CODEC == SWCODEC
655 int i;
656 #endif
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);
665 #endif
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);
677 #endif
678 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
679 #if CONFIG_CHARGING
680 remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged);
681 #endif
682 #ifdef HAS_REMOTE_BUTTON_HOLD
683 remote_backlight_set_on_button_hold(global_settings.remote_backlight_on_button_hold);
684 #endif
685 #endif /* HAVE_REMOTE_LCD */
686 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
687 backlight_set_brightness(global_settings.brightness);
688 #endif
689 #ifdef HAVE_BACKLIGHT
690 backlight_set_timeout(global_settings.backlight_timeout);
691 #if CONFIG_CHARGING
692 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
693 #endif
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);
697 #endif
698 #endif
699 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
700 buttonlight_set_brightness(global_settings.buttonlight_brightness);
701 #endif
702 #ifdef HAVE_BUTTON_LIGHT
703 button_backlight_set_timeout(global_settings.button_light_timeout);
704 #endif
705 ata_spindown(global_settings.disk_spindown);
706 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
707 dac_line_in(global_settings.line_in);
708 #endif
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);
716 #endif
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);
727 #endif
729 #if LCD_DEPTH > 1
730 unload_wps_backdrop();
731 #endif
732 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
733 unload_remote_wps_backdrop();
734 #endif
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);
741 else
743 wps_data_init(gui_wps[0].data);
744 #ifdef HAVE_REMOTE_LCD
745 gui_wps[0].data->remote_wps = false;
746 #endif
749 #if LCD_DEPTH > 1
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);
755 } else {
756 unload_main_backdrop();
758 show_main_backdrop();
759 #endif
760 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
761 show_remote_main_backdrop();
762 #endif
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);
767 #endif
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);
775 else
777 wps_data_init(gui_wps[1].data);
778 gui_wps[1].data->remote_wps = true;
780 #endif
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);
786 font_load(buf);
788 else
789 font_reset();
791 if ( global_settings.kbd_file[0]) {
792 snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd",
793 global_settings.kbd_file);
794 load_kbd(buf);
796 else
797 load_kbd(NULL);
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);
802 #else
803 lcd_jump_scroll(global_settings.jump_scroll);
804 lcd_jump_scroll_delay(global_settings.jump_scroll_delay);
805 #endif
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);
812 lang_load(buf);
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++) {
831 dsp_set_eq_coefs(i);
834 dsp_dither_enable(global_settings.dithering_enabled);
835 #endif
837 #ifdef HAVE_SPDIF_POWER
838 spdif_power_enable(global_settings.spdif_enable);
839 #endif
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);
845 #endif
846 #ifdef HAS_BUTTON_HOLD
847 backlight_set_on_button_hold(global_settings.backlight_on_button_hold);
848 #endif
849 #ifdef HAVE_LCD_SLEEP
850 lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off);
851 #endif
852 #endif /* HAVE_BACKLIGHT */
854 /* This should stay last */
855 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
856 enc_global_settings_apply();
857 #endif
858 /* load the icon set */
859 icons_init();
861 #ifdef HAVE_LCD_COLOR
862 if (global_settings.colors_file)
863 read_color_theme_file();
864 #endif
872 * reset all settings to their default value
874 void settings_reset(void) {
876 int i;
877 DEBUGF( "settings_reset()\n" );
879 for(i=0; i<nb_settings; i++)
881 switch (settings[i].flags&F_T_MASK)
883 case F_T_INT:
884 case F_T_UINT:
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_;
891 break;
892 case F_T_BOOL:
893 *(bool*)settings[i].setting = settings[i].default_val.bool_;
894 break;
895 case F_T_CHARPTR:
896 case F_T_UCHARPTR:
897 strncpy((char*)settings[i].setting,
898 settings[i].default_val.charptr,MAX_FILENAME);
899 break;
901 } /* for(...) */
902 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
903 enc_global_settings_reset();
904 #endif
907 /** Changing setting values **/
908 const struct settings_list* find_setting(void* variable, int *id)
910 int i;
911 for(i=0;i<nb_settings;i++)
913 if (settings[i].setting == variable)
915 if (id)
916 *id = i;
917 return &settings[i];
920 return NULL;
923 void talk_setting(void *global_settings_variable)
925 const struct settings_list *setting;
926 if (!talk_menus_enabled())
927 return;
928 setting = find_setting(global_settings_variable, NULL);
929 if (setting == NULL)
930 return;
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),
940 NULL);
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}
953 bool result;
955 result = set_option(string, variable, BOOL, names, 2,
956 (void (*)(int))function);
957 return result;
960 bool set_int(const unsigned char* string,
961 const char* unit,
962 int voice_unit,
963 int* variable,
964 void (*function)(int),
965 int step,
966 int min,
967 int max,
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,'/');
980 int len;
981 int extlen = 0;
982 char* ptr;
984 if (!fptr)
985 return;
987 *fptr = 0;
988 fptr++;
990 len = strlen(fptr);
991 ptr = fptr + len;
992 while ((*ptr != '.') && (ptr != fptr)) {
993 extlen++;
994 ptr--;
996 if(ptr == fptr) extlen = 0;
998 if (strncasecmp(ROCKBOX_DIR, filename ,strlen(ROCKBOX_DIR)) ||
999 (len-extlen > maxlen))
1000 return;
1002 strncpy(setting, fptr, len-extlen);
1003 setting[len-extlen]=0;
1005 settings_save();