Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 10 | * Copyright (C) 2002 by Stuart Martin |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 11 | * RTC config saving code (C) 2002 by hessu@hes.iki.fi |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 12 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 22 | #include <stdio.h> |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 23 | #include <stddef.h> |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Jean-Philippe Bernardy | 00cf0da | 2005-02-15 15:30:19 +0000 | [diff] [blame] | 25 | #include <limits.h> |
Jens Arnold | fb7368e | 2006-03-03 01:12:50 +0000 | [diff] [blame] | 26 | #include "inttypes.h" |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 27 | #include "config.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 28 | #include "action.h" |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 29 | #include "crc32.h" |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 30 | #include "settings.h" |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 31 | #include "debug.h" |
Justin Heiner | b5025a8 | 2002-08-31 04:58:35 +0000 | [diff] [blame] | 32 | #include "usb.h" |
| 33 | #include "backlight.h" |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 34 | #include "audio.h" |
Jens Arnold | 61a2550 | 2005-09-11 12:07:13 +0000 | [diff] [blame] | 35 | #include "mpeg.h" |
Jörg Hohensohn | 42ffbf9 | 2004-03-15 08:27:51 +0000 | [diff] [blame] | 36 | #include "talk.h" |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 37 | #include "string.h" |
Jonathan Gordon | 2062f63 | 2007-01-29 13:44:22 +0000 | [diff] [blame] | 38 | #include "rtc.h" |
Jonathan Gordon | 7bb8b30 | 2007-01-29 13:58:35 +0000 | [diff] [blame] | 39 | #include "power.h" |
Jonathan Gordon | f184152 | 2006-11-08 01:55:26 +0000 | [diff] [blame] | 40 | #include "ata_idle_notify.h" |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 41 | #include "screens.h" |
Björn Stenberg | 0e6088f | 2002-10-02 16:33:26 +0000 | [diff] [blame] | 42 | #include "ctype.h" |
| 43 | #include "file.h" |
Linus Nielsen Feltzing | c843ba4 | 2002-10-29 12:16:36 +0000 | [diff] [blame] | 44 | #include "system.h" |
Linus Nielsen Feltzing | 75b41a8 | 2003-05-04 02:04:31 +0000 | [diff] [blame] | 45 | #include "misc.h" |
Markus Braun | 5e4c1d2 | 2002-08-20 19:37:00 +0000 | [diff] [blame] | 46 | #ifdef HAVE_LCD_BITMAP |
| 47 | #include "icons.h" |
Daniel Stenberg | 93b231c | 2002-09-12 13:33:59 +0000 | [diff] [blame] | 48 | #include "font.h" |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 49 | #include "peakmeter.h" |
Markus Braun | 5e4c1d2 | 2002-08-20 19:37:00 +0000 | [diff] [blame] | 50 | #endif |
Björn Stenberg | 505eca7 | 2002-09-18 14:08:05 +0000 | [diff] [blame] | 51 | #include "lang.h" |
Björn Stenberg | dea3122 | 2002-10-08 15:42:40 +0000 | [diff] [blame] | 52 | #include "language.h" |
Christi Scarborough | 4c0b83f | 2005-11-17 20:14:59 +0000 | [diff] [blame] | 53 | #include "gwps.h" |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 54 | #include "powermgmt.h" |
Daniel Stenberg | 79a6cb6 | 2003-02-15 00:03:23 +0000 | [diff] [blame] | 55 | #include "sprintf.h" |
Björn Stenberg | c5aaab4 | 2003-03-10 16:31:02 +0000 | [diff] [blame] | 56 | #include "keyboard.h" |
Björn Stenberg | a6b8bdf | 2003-04-25 10:33:38 +0000 | [diff] [blame] | 57 | #include "version.h" |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 58 | #include "sound.h" |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame] | 59 | #include "rbunicode.h" |
Miika Pekkarinen | ab78b04 | 2005-10-07 17:38:05 +0000 | [diff] [blame] | 60 | #include "dircache.h" |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 61 | #include "statusbar.h" |
Kevin Ferrare | 9ccca4a | 2005-11-04 17:25:29 +0000 | [diff] [blame] | 62 | #include "splash.h" |
Tomas Salfischberger | 7fa39df | 2006-01-22 01:42:05 +0000 | [diff] [blame] | 63 | #include "list.h" |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 64 | #include "settings_list.h" |
Brandon Low | 488de5e | 2007-06-17 21:29:24 +0000 | [diff] [blame] | 65 | #include "filetypes.h" |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 66 | #include "option_select.h" |
Dave Chapman | d9e5b67 | 2006-02-02 20:42:56 +0000 | [diff] [blame] | 67 | #include "backdrop.h" |
Miika Pekkarinen | ab78b04 | 2005-10-07 17:38:05 +0000 | [diff] [blame] | 68 | |
Jonathan Gordon | 844583c | 2007-02-18 02:16:03 +0000 | [diff] [blame] | 69 | #if CONFIG_TUNER |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 70 | #include "radio.h" |
| 71 | #endif |
| 72 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 73 | #if CONFIG_CODEC == MAS3507D |
Linus Nielsen Feltzing | 54a7e20 | 2003-11-04 00:18:19 +0000 | [diff] [blame] | 74 | void dac_line_in(bool enable); |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 75 | #endif |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 76 | struct user_settings global_settings; |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 77 | struct system_status global_status; |
Michael Sevakis | eed62f1 | 2007-02-07 04:24:21 +0000 | [diff] [blame] | 78 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 79 | #if CONFIG_CODEC == SWCODEC |
Magnus Holmgren | 4b711c2 | 2005-09-24 15:22:48 +0000 | [diff] [blame] | 80 | #include "dsp.h" |
Steve Bavin | c9df8fd | 2008-03-28 11:24:24 +0000 | [diff] [blame] | 81 | #include "playback.h" |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 82 | #ifdef HAVE_RECORDING |
| 83 | #include "enc_config.h" |
Linus Nielsen Feltzing | 6271b2b | 2005-06-09 09:47:00 +0000 | [diff] [blame] | 84 | #endif |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 85 | #endif /* CONFIG_CODEC == SWCODEC */ |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 86 | |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 87 | #define NVRAM_BLOCK_SIZE 44 |
Björn Stenberg | cd7691d | 2002-08-13 17:16:09 +0000 | [diff] [blame] | 88 | |
Linus Nielsen Feltzing | bb572c4 | 2002-09-27 09:31:31 +0000 | [diff] [blame] | 89 | #ifdef HAVE_LCD_BITMAP |
| 90 | #define MAX_LINES 10 |
| 91 | #else |
| 92 | #define MAX_LINES 2 |
| 93 | #endif |
| 94 | |
Christian Gmeiner | 7c1879b | 2005-04-15 12:08:49 +0000 | [diff] [blame] | 95 | #ifdef HAVE_REMOTE_LCD |
| 96 | #include "lcd-remote.h" |
| 97 | #endif |
| 98 | |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 99 | long lasttime = 0; |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 100 | |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 101 | /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 102 | /* NVRAM is set out as |
| 103 | [0] 'R' |
| 104 | [1] 'b' |
| 105 | [2] version |
| 106 | [3] stored variable count |
| 107 | [4-7] crc32 checksum |
| 108 | [8-NVRAM_BLOCK_SIZE] data |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 109 | */ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 110 | #define NVRAM_DATA_START 8 |
| 111 | #define NVRAM_FILE ROCKBOX_DIR "/nvram.bin" |
| 112 | static char nvram_buffer[NVRAM_BLOCK_SIZE]; |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 113 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 114 | static bool read_nvram_data(char* buf, int max_len) |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 115 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 116 | unsigned crc32 = 0xffffffff; |
| 117 | int var_count = 0, i = 0, buf_pos = 0; |
| 118 | #ifndef HAVE_RTC_RAM |
| 119 | int fd = open(NVRAM_FILE,O_RDONLY); |
| 120 | if (fd < 0) |
| 121 | return false; |
| 122 | memset(buf,0,max_len); |
| 123 | if (read(fd,buf,max_len) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */ |
| 124 | return false; |
| 125 | close(fd); |
Zakk Roberts | 8bdd92b | 2006-03-30 05:56:19 +0000 | [diff] [blame] | 126 | #else |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 127 | memset(buf,0,max_len); |
| 128 | /* read rtc block */ |
| 129 | for (i=0; i < max_len; i++ ) |
| 130 | buf[i] = rtc_read(0x14+i); |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 131 | #endif |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 132 | /* check magic, version */ |
| 133 | if ((buf[0] != 'R') || (buf[1] != 'b') |
| 134 | || (buf[2] != NVRAM_CONFIG_VERSION)) |
| 135 | return false; |
| 136 | /* check crc32 */ |
| 137 | crc32 = crc_32(&buf[NVRAM_DATA_START], |
| 138 | max_len-NVRAM_DATA_START-1,0xffffffff); |
| 139 | if (memcmp(&crc32,&buf[4],4)) |
| 140 | return false; |
| 141 | /* all good, so read in the settings */ |
| 142 | var_count = buf[3]; |
| 143 | buf_pos = NVRAM_DATA_START; |
Jonathan Gordon | 7cb80a2 | 2007-08-12 07:22:38 +0000 | [diff] [blame] | 144 | for(i=0; i<nb_settings; i++) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 145 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 146 | int nvram_bytes = (settings[i].flags&F_NVRAM_BYTES_MASK) |
| 147 | >>F_NVRAM_MASK_SHIFT; |
| 148 | if (nvram_bytes) |
| 149 | { |
Jonathan Gordon | 7cb80a2 | 2007-08-12 07:22:38 +0000 | [diff] [blame] | 150 | if ((var_count>0) && (buf_pos<max_len)) |
| 151 | { |
| 152 | memcpy(settings[i].setting,&buf[buf_pos],nvram_bytes); |
| 153 | buf_pos += nvram_bytes; |
| 154 | var_count--; |
| 155 | } |
| 156 | else /* should only happen when new items are added to the end */ |
| 157 | { |
| 158 | memcpy(settings[i].setting, &settings[i].default_val, nvram_bytes); |
| 159 | } |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | return true; |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 163 | } |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 164 | static bool write_nvram_data(char* buf, int max_len) |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 165 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 166 | unsigned crc32 = 0xffffffff; |
| 167 | int i = 0, buf_pos = 0; |
| 168 | char var_count = 0; |
| 169 | #ifndef HAVE_RTC_RAM |
| 170 | int fd; |
| 171 | #endif |
| 172 | memset(buf,0,max_len); |
| 173 | /* magic, version */ |
| 174 | buf[0] = 'R'; buf[1] = 'b'; |
| 175 | buf[2] = NVRAM_CONFIG_VERSION; |
| 176 | buf_pos = NVRAM_DATA_START; |
| 177 | for(i=0; (i<nb_settings) && (buf_pos<max_len); i++) |
| 178 | { |
| 179 | int nvram_bytes = (settings[i].flags&F_NVRAM_BYTES_MASK) |
| 180 | >>F_NVRAM_MASK_SHIFT; |
| 181 | if (nvram_bytes) |
| 182 | { |
| 183 | memcpy(&buf[buf_pos],settings[i].setting,nvram_bytes); |
| 184 | buf_pos += nvram_bytes; |
| 185 | var_count++; |
| 186 | } |
| 187 | } |
| 188 | /* count and crc32 */ |
| 189 | buf[3] = var_count; |
| 190 | crc32 = crc_32(&buf[NVRAM_DATA_START], |
| 191 | max_len-NVRAM_DATA_START-1,0xffffffff); |
| 192 | memcpy(&buf[4],&crc32,4); |
| 193 | #ifndef HAVE_RTC_RAM |
| 194 | fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY); |
| 195 | if (fd >= 0) |
| 196 | { |
| 197 | int len = write(fd,buf,max_len); |
| 198 | close(fd); |
| 199 | if (len < 8) |
| 200 | return false; |
| 201 | } |
| 202 | #else |
| 203 | /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so |
| 204 | that it would write a number of bytes at a time since the RTC chip |
| 205 | supports that, but this will have to do for now 8-) */ |
| 206 | for (i=0; i < NVRAM_BLOCK_SIZE; i++ ) { |
| 207 | int r = rtc_write(0x14+i, buf[i]); |
Steve Bavin | 799e948 | 2008-04-07 17:19:53 +0000 | [diff] [blame] | 208 | if (r) |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 209 | return false; |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 210 | } |
| 211 | #endif |
| 212 | return true; |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 213 | } |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 214 | |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 215 | /** Reading from a config file **/ |
| 216 | /* |
| 217 | * load settings from disk or RTC RAM |
| 218 | */ |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 219 | void settings_load(int which) |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 220 | { |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 221 | if (which&SETTINGS_RTC) |
| 222 | read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
| 223 | if (which&SETTINGS_HD) |
| 224 | { |
| 225 | settings_load_config(CONFIGFILE,false); |
| 226 | settings_load_config(FIXEDSETTINGSFILE,false); |
| 227 | } |
| 228 | } |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 229 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 230 | static bool cfg_string_to_int(int setting_id, int* out, const char* str) |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 231 | { |
| 232 | const char* start = settings[setting_id].cfg_vals; |
| 233 | char* end = NULL; |
| 234 | char temp[MAX_PATH]; |
| 235 | int count = 0; |
| 236 | while (1) |
| 237 | { |
| 238 | end = strchr(start, ','); |
| 239 | if (!end) |
| 240 | { |
| 241 | if (!strcmp(str, start)) |
| 242 | { |
| 243 | *out = count; |
| 244 | return true; |
| 245 | } |
| 246 | else return false; |
| 247 | } |
| 248 | strncpy(temp, start, end-start); |
| 249 | temp[end-start] = '\0'; |
| 250 | if (!strcmp(str, temp)) |
| 251 | { |
| 252 | *out = count; |
| 253 | return true; |
| 254 | } |
| 255 | start = end +1; |
| 256 | count++; |
| 257 | } |
| 258 | return false; |
| 259 | } |
| 260 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 261 | bool settings_load_config(const char* file, bool apply) |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 262 | { |
| 263 | int fd; |
| 264 | char line[128]; |
| 265 | char* name; |
| 266 | char* value; |
| 267 | int i; |
| 268 | fd = open(file, O_RDONLY); |
| 269 | if (fd < 0) |
| 270 | return false; |
Jonathan Gordon | 0158336 | 2008-03-25 12:42:47 +0000 | [diff] [blame] | 271 | |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 272 | while (read_line(fd, line, sizeof line) > 0) |
| 273 | { |
| 274 | if (!settings_parseline(line, &name, &value)) |
| 275 | continue; |
| 276 | for(i=0; i<nb_settings; i++) |
| 277 | { |
| 278 | if (settings[i].cfg_name == NULL) |
| 279 | continue; |
| 280 | if (!strcasecmp(name,settings[i].cfg_name)) |
| 281 | { |
| 282 | switch (settings[i].flags&F_T_MASK) |
| 283 | { |
| 284 | case F_T_INT: |
| 285 | case F_T_UINT: |
| 286 | #ifdef HAVE_LCD_COLOR |
| 287 | if (settings[i].flags&F_RGB) |
Dave Chapman | e92d2c5 | 2008-03-21 13:41:35 +0000 | [diff] [blame] | 288 | hex_to_rgb(value, (int*)settings[i].setting); |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 289 | else |
| 290 | #endif |
| 291 | if (settings[i].cfg_vals == NULL) |
| 292 | { |
| 293 | *(int*)settings[i].setting = atoi(value); |
| 294 | } |
| 295 | else |
| 296 | { |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 297 | int temp, *v = (int*)settings[i].setting; |
| 298 | bool found = cfg_string_to_int(i, &temp, value); |
| 299 | if (found) |
| 300 | { |
| 301 | if (settings[i].flags&F_TABLE_SETTING) |
| 302 | *v = settings[i].table_setting->values[temp]; |
| 303 | else |
| 304 | *v = temp; |
| 305 | } |
| 306 | else |
| 307 | *v = atoi(value); |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 308 | } |
| 309 | break; |
| 310 | case F_T_BOOL: |
| 311 | { |
| 312 | int temp; |
| 313 | if (cfg_string_to_int(i,&temp,value)) |
| 314 | *(bool*)settings[i].setting = (temp==0?false:true); |
| 315 | break; |
| 316 | } |
| 317 | case F_T_CHARPTR: |
| 318 | case F_T_UCHARPTR: |
| 319 | { |
| 320 | char storage[MAX_PATH]; |
| 321 | if (settings[i].filename_setting->prefix) |
| 322 | { |
| 323 | int len = strlen(settings[i].filename_setting->prefix); |
Jonathan Gordon | 332b324 | 2007-02-12 02:36:32 +0000 | [diff] [blame] | 324 | if (!strncasecmp(value, |
| 325 | settings[i].filename_setting->prefix, |
| 326 | len)) |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 327 | { |
| 328 | strncpy(storage,&value[len],MAX_PATH); |
| 329 | } |
| 330 | else strncpy(storage,value,MAX_PATH); |
| 331 | } |
| 332 | else strncpy(storage,value,MAX_PATH); |
| 333 | if (settings[i].filename_setting->suffix) |
| 334 | { |
| 335 | char *s = strcasestr(storage,settings[i].filename_setting->suffix); |
| 336 | if (s) *s = '\0'; |
| 337 | } |
| 338 | strncpy((char*)settings[i].setting,storage, |
| 339 | settings[i].filename_setting->max_len); |
| 340 | ((char*)settings[i].setting) |
| 341 | [settings[i].filename_setting->max_len-1] = '\0'; |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | break; |
| 346 | } /* if (!strcmp(name,settings[i].cfg_name)) */ |
| 347 | } /* for(...) */ |
| 348 | } /* while(...) */ |
| 349 | |
| 350 | close(fd); |
| 351 | settings_save(); |
| 352 | if (apply) |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 353 | settings_apply(true); |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 354 | return true; |
| 355 | } |
| 356 | |
| 357 | /** Writing to a config file and saving settings **/ |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 358 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 359 | bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 360 | { |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 361 | int flags = settings[setting_id].flags; |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 362 | const char* start = settings[setting_id].cfg_vals; |
| 363 | char* end = NULL; |
| 364 | int count = 0; |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 365 | |
| 366 | if ((flags&F_T_MASK)==F_T_INT && |
| 367 | flags&F_TABLE_SETTING) |
| 368 | { |
| 369 | const int *value = settings[setting_id].table_setting->values; |
| 370 | while (start) |
| 371 | { |
| 372 | end = strchr(start,','); |
| 373 | if (value[count] == val) |
| 374 | { |
| 375 | if (end == NULL) |
| 376 | strncpy(buf, start, buf_len); |
| 377 | else |
| 378 | { |
| 379 | int len = (buf_len > (end-start))? end-start: buf_len; |
| 380 | strncpy(buf, start, len); |
| 381 | buf[len] = '\0'; |
| 382 | } |
| 383 | return true; |
| 384 | } |
| 385 | count++; |
| 386 | |
| 387 | if (end) |
| 388 | start = end+1; |
| 389 | else |
| 390 | break; |
| 391 | } |
| 392 | return false; |
| 393 | } |
| 394 | |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 395 | while (count < val) |
| 396 | { |
| 397 | start = strchr(start,','); |
| 398 | if (!start) |
| 399 | return false; |
| 400 | count++; |
| 401 | start++; |
| 402 | } |
| 403 | end = strchr(start,','); |
| 404 | if (end == NULL) |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 405 | strncpy(buf, start, buf_len); |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 406 | else |
| 407 | { |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 408 | int len = (buf_len > (end-start))? end-start: buf_len; |
| 409 | strncpy(buf, start, len); |
| 410 | buf[len] = '\0'; |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 411 | } |
| 412 | return true; |
| 413 | } |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 414 | |
| 415 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 416 | static bool is_changed(int setting_id) |
Jonathan Gordon | f0d2861 | 2007-02-01 13:57:14 +0000 | [diff] [blame] | 417 | { |
Linus Nielsen Feltzing | 750fa4a | 2007-02-16 10:20:30 +0000 | [diff] [blame] | 418 | const struct settings_list *setting = &settings[setting_id]; |
| 419 | switch (setting->flags&F_T_MASK) |
| 420 | { |
| 421 | case F_T_INT: |
| 422 | case F_T_UINT: |
| 423 | if (setting->flags&F_DEF_ISFUNC) |
| 424 | { |
| 425 | if (*(int*)setting->setting == setting->default_val.func()) |
| 426 | return false; |
| 427 | } |
| 428 | else if (setting->flags&F_T_SOUND) |
| 429 | { |
| 430 | if (*(int*)setting->setting == |
| 431 | sound_default(setting->sound_setting->setting)) |
| 432 | return false; |
| 433 | } |
| 434 | else if (*(int*)setting->setting == setting->default_val.int_) |
| 435 | return false; |
| 436 | break; |
| 437 | case F_T_BOOL: |
| 438 | if (*(bool*)setting->setting == setting->default_val.bool_) |
| 439 | return false; |
| 440 | break; |
| 441 | case F_T_CHARPTR: |
| 442 | case F_T_UCHARPTR: |
| 443 | if (!strcmp((char*)setting->setting, setting->default_val.charptr)) |
| 444 | return false; |
| 445 | break; |
| 446 | } |
| 447 | return true; |
Jonathan Gordon | f0d2861 | 2007-02-01 13:57:14 +0000 | [diff] [blame] | 448 | } |
Jonathan Gordon | b758883 | 2007-01-25 07:19:45 +0000 | [diff] [blame] | 449 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 450 | static bool settings_write_config(const char* filename, int options) |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 451 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 452 | int i; |
| 453 | int fd; |
Jonathan Gordon | 46f7f7d | 2007-01-24 03:47:25 +0000 | [diff] [blame] | 454 | char value[MAX_PATH]; |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 455 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); |
| 456 | if (fd < 0) |
| 457 | return false; |
Jonathan Gordon | 4d238c1 | 2008-01-10 06:46:04 +0000 | [diff] [blame] | 458 | #if CONFIG_TUNER |
| 459 | bool statusbar = global_settings.statusbar; |
| 460 | if (global_status.statusbar_forced != 0 && statusbar) |
| 461 | global_settings.statusbar = false; |
| 462 | #endif |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 463 | fdprintf(fd, "# .cfg file created by rockbox %s - " |
| 464 | "http://www.rockbox.org\r\n\r\n", appsversion); |
| 465 | for(i=0; i<nb_settings; i++) |
| 466 | { |
| 467 | if (settings[i].cfg_name == NULL) |
| 468 | continue; |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 469 | value[0] = '\0'; |
Linus Nielsen Feltzing | 750fa4a | 2007-02-16 10:20:30 +0000 | [diff] [blame] | 470 | |
Jens Arnold | fcd52cf | 2008-02-23 11:06:19 +0000 | [diff] [blame] | 471 | switch (options) |
| 472 | { |
| 473 | case SETTINGS_SAVE_CHANGED: |
| 474 | if (!is_changed(i)) |
| 475 | continue; |
| 476 | break; |
| 477 | case SETTINGS_SAVE_SOUND: |
| 478 | if ((settings[i].flags&F_SOUNDSETTING) == 0) |
| 479 | continue; |
| 480 | break; |
| 481 | case SETTINGS_SAVE_THEME: |
| 482 | if ((settings[i].flags&F_THEMESETTING) == 0) |
| 483 | continue; |
| 484 | break; |
Jonathan Gordon | 9adf056 | 2007-05-29 04:39:11 +0000 | [diff] [blame] | 485 | #ifdef HAVE_RECORDING |
Jens Arnold | fcd52cf | 2008-02-23 11:06:19 +0000 | [diff] [blame] | 486 | case SETTINGS_SAVE_RECPRESETS: |
| 487 | if ((settings[i].flags&F_RECSETTING) == 0) |
| 488 | continue; |
| 489 | break; |
Jonathan Gordon | 9adf056 | 2007-05-29 04:39:11 +0000 | [diff] [blame] | 490 | #endif |
Dan Everton | 5886efa | 2007-12-07 10:59:07 +0000 | [diff] [blame] | 491 | #if CONFIG_CODEC == SWCODEC |
Jens Arnold | fcd52cf | 2008-02-23 11:06:19 +0000 | [diff] [blame] | 492 | case SETTINGS_SAVE_EQPRESET: |
| 493 | if ((settings[i].flags&F_EQSETTING) == 0) |
| 494 | continue; |
| 495 | break; |
Dan Everton | 5886efa | 2007-12-07 10:59:07 +0000 | [diff] [blame] | 496 | #endif |
Jens Arnold | fcd52cf | 2008-02-23 11:06:19 +0000 | [diff] [blame] | 497 | } |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 498 | switch (settings[i].flags&F_T_MASK) |
| 499 | { |
| 500 | case F_T_INT: |
| 501 | case F_T_UINT: |
| 502 | #ifdef HAVE_LCD_COLOR |
| 503 | if (settings[i].flags&F_RGB) |
| 504 | { |
| 505 | int colour = *(int*)settings[i].setting; |
| 506 | snprintf(value,MAX_PATH,"%02x%02x%02x", |
| 507 | (int)RGB_UNPACK_RED(colour), |
| 508 | (int)RGB_UNPACK_GREEN(colour), |
| 509 | (int)RGB_UNPACK_BLUE(colour)); |
| 510 | } |
| 511 | else |
| 512 | #endif |
Magnus Holmgren | c23f565 | 2007-01-23 19:54:09 +0000 | [diff] [blame] | 513 | if (settings[i].cfg_vals == NULL) |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 514 | { |
| 515 | snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting); |
| 516 | } |
| 517 | else |
| 518 | { |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 519 | if (cfg_int_to_string(i, *(int*)settings[i].setting, |
| 520 | value, MAX_PATH) == false) |
| 521 | { |
| 522 | snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting); |
| 523 | } |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 524 | } |
| 525 | break; |
| 526 | case F_T_BOOL: |
Jonathan Gordon | bc60af1 | 2007-01-29 12:32:56 +0000 | [diff] [blame] | 527 | cfg_int_to_string(i, |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 528 | *(bool*)settings[i].setting==false?0:1, value, MAX_PATH); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 529 | break; |
| 530 | case F_T_CHARPTR: |
| 531 | case F_T_UCHARPTR: |
Jens Arnold | db70f8d | 2008-02-23 10:17:31 +0000 | [diff] [blame] | 532 | if (((char*)settings[i].setting)[0] |
| 533 | && settings[i].filename_setting->prefix) |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 534 | { |
| 535 | snprintf(value,MAX_PATH,"%s%s%s", |
| 536 | settings[i].filename_setting->prefix, |
| 537 | (char*)settings[i].setting, |
| 538 | settings[i].filename_setting->suffix); |
| 539 | } |
| 540 | else strncpy(value,(char*)settings[i].setting, |
| 541 | settings[i].filename_setting->max_len); |
| 542 | break; |
| 543 | } /* switch () */ |
Jens Arnold | db70f8d | 2008-02-23 10:17:31 +0000 | [diff] [blame] | 544 | fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 545 | } /* for(...) */ |
| 546 | close(fd); |
Jonathan Gordon | 4d238c1 | 2008-01-10 06:46:04 +0000 | [diff] [blame] | 547 | #if CONFIG_TUNER |
| 548 | global_settings.statusbar = statusbar; |
| 549 | #endif |
Jonathan Gordon | f184152 | 2006-11-08 01:55:26 +0000 | [diff] [blame] | 550 | return true; |
| 551 | } |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 552 | #ifndef HAVE_RTC_RAM |
| 553 | static bool flush_global_status_callback(void) |
| 554 | { |
| 555 | return write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
| 556 | } |
| 557 | #endif |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 558 | static bool flush_config_block_callback(void) |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 559 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 560 | bool r1, r2; |
| 561 | r1 = write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
Jonathan Gordon | f0d2861 | 2007-02-01 13:57:14 +0000 | [diff] [blame] | 562 | r2 = settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 563 | return r1 || r2; |
Jens Arnold | c12e87d | 2004-09-28 18:09:10 +0000 | [diff] [blame] | 564 | } |
Jörg Hohensohn | 44171b9 | 2004-06-18 20:41:59 +0000 | [diff] [blame] | 565 | |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 566 | /* |
| 567 | * persist all runtime user settings to disk or RTC RAM |
| 568 | */ |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 569 | static void update_runtime(void) |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 570 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 571 | int elapsed_secs; |
Dave Chapman | d9e5b67 | 2006-02-02 20:42:56 +0000 | [diff] [blame] | 572 | |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 573 | elapsed_secs = (current_tick - lasttime) / HZ; |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 574 | global_status.runtime += elapsed_secs; |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 575 | lasttime += (elapsed_secs * HZ); |
| 576 | |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 577 | if ( global_status.runtime > global_status.topruntime ) |
| 578 | global_status.topruntime = global_status.runtime; |
| 579 | } |
| 580 | |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 581 | void status_save(void) |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 582 | { |
| 583 | update_runtime(); |
| 584 | #ifdef HAVE_RTC_RAM |
| 585 | /* this will be done in the ata_callback if |
| 586 | target doesnt have rtc ram */ |
| 587 | write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
| 588 | #else |
| 589 | register_ata_idle_func(flush_global_status_callback); |
| 590 | #endif |
| 591 | } |
| 592 | |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 593 | int settings_save(void) |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 594 | { |
| 595 | update_runtime(); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 596 | #ifdef HAVE_RTC_RAM |
| 597 | /* this will be done in the ata_callback if |
| 598 | target doesnt have rtc ram */ |
| 599 | write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
| 600 | #endif |
Miika Pekkarinen | 19c6e66 | 2008-03-16 13:55:16 +0000 | [diff] [blame] | 601 | register_ata_idle_func(flush_config_block_callback); |
Linus Nielsen Feltzing | d0abfe8 | 2002-07-28 16:09:44 +0000 | [diff] [blame] | 602 | return 0; |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 603 | } |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 604 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 605 | bool settings_save_config(int options) |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 606 | { |
| 607 | char filename[MAX_PATH]; |
Jonathan Gordon | 9adf056 | 2007-05-29 04:39:11 +0000 | [diff] [blame] | 608 | char *folder; |
| 609 | switch (options) |
| 610 | { |
| 611 | case SETTINGS_SAVE_THEME: |
| 612 | folder = THEME_DIR; |
| 613 | break; |
| 614 | #ifdef HAVE_RECORDING |
| 615 | case SETTINGS_SAVE_RECPRESETS: |
| 616 | folder = RECPRESETS_DIR; |
| 617 | break; |
| 618 | #endif |
Dan Everton | 5886efa | 2007-12-07 10:59:07 +0000 | [diff] [blame] | 619 | #if CONFIG_CODEC == SWCODEC |
| 620 | case SETTINGS_SAVE_EQPRESET: |
| 621 | folder = EQS_DIR; |
| 622 | break; |
| 623 | #endif |
Jonathan Gordon | b8bc45d | 2007-12-24 22:35:31 +0000 | [diff] [blame] | 624 | case SETTINGS_SAVE_SOUND: |
Jonathan Gordon | 9adf056 | 2007-05-29 04:39:11 +0000 | [diff] [blame] | 625 | default: |
| 626 | folder = ROCKBOX_DIR; |
| 627 | } |
| 628 | create_numbered_filename(filename, folder, "config", ".cfg", 2 |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 629 | IF_CNFN_NUM_(, NULL)); |
| 630 | |
| 631 | /* allow user to modify filename */ |
| 632 | while (true) { |
| 633 | if (!kbd_input(filename, sizeof filename)) { |
| 634 | break; |
| 635 | } |
| 636 | else { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 637 | gui_syncsplash(HZ, ID2P(LANG_CANCEL)); |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 638 | return false; |
| 639 | } |
| 640 | } |
| 641 | |
Jonathan Gordon | f0d2861 | 2007-02-01 13:57:14 +0000 | [diff] [blame] | 642 | if (settings_write_config(filename, options)) |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 643 | gui_syncsplash(HZ, ID2P(LANG_SETTINGS_SAVED)); |
Linus Nielsen Feltzing | 750fa4a | 2007-02-16 10:20:30 +0000 | [diff] [blame] | 644 | else |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 645 | gui_syncsplash(HZ, ID2P(LANG_FAILED)); |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 646 | return true; |
| 647 | } |
| 648 | |
| 649 | /** Apply and Reset settings **/ |
| 650 | |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 651 | |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 652 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 653 | /* |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 654 | * Applies the range infos stored in global_settings to |
| 655 | * the peak meter. |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 656 | */ |
| 657 | void settings_apply_pm_range(void) |
| 658 | { |
| 659 | int pm_min, pm_max; |
| 660 | |
| 661 | /* depending on the scale mode (dBfs or percent) the values |
| 662 | of global_settings.peak_meter_dbfs have different meanings */ |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 663 | if (global_settings.peak_meter_dbfs) |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 664 | { |
| 665 | /* convert to dBfs * 100 */ |
| 666 | pm_min = -(((int)global_settings.peak_meter_min) * 100); |
| 667 | pm_max = -(((int)global_settings.peak_meter_max) * 100); |
| 668 | } |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 669 | else |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 670 | { |
| 671 | /* percent is stored directly -> no conversion */ |
| 672 | pm_min = global_settings.peak_meter_min; |
| 673 | pm_max = global_settings.peak_meter_max; |
| 674 | } |
| 675 | |
| 676 | /* apply the range */ |
| 677 | peak_meter_init_range(global_settings.peak_meter_dbfs, pm_min, pm_max); |
| 678 | } |
| 679 | #endif /* HAVE_LCD_BITMAP */ |
| 680 | |
Linus Nielsen Feltzing | 7bade1a | 2004-07-06 12:17:14 +0000 | [diff] [blame] | 681 | void sound_settings_apply(void) |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 682 | { |
Thom Johansen | 99b2742 | 2007-03-07 19:11:16 +0000 | [diff] [blame] | 683 | #if CONFIG_CODEC == SWCODEC |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 684 | sound_set_dsp_callback(dsp_callback); |
| 685 | #endif |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 686 | sound_set(SOUND_BASS, global_settings.bass); |
| 687 | sound_set(SOUND_TREBLE, global_settings.treble); |
| 688 | sound_set(SOUND_BALANCE, global_settings.balance); |
| 689 | sound_set(SOUND_VOLUME, global_settings.volume); |
| 690 | sound_set(SOUND_CHANNELS, global_settings.channel_config); |
| 691 | sound_set(SOUND_STEREO_WIDTH, global_settings.stereo_width); |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 692 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 693 | sound_set(SOUND_LOUDNESS, global_settings.loudness); |
| 694 | sound_set(SOUND_AVC, global_settings.avc); |
| 695 | sound_set(SOUND_MDB_STRENGTH, global_settings.mdb_strength); |
| 696 | sound_set(SOUND_MDB_HARMONICS, global_settings.mdb_harmonics); |
| 697 | sound_set(SOUND_MDB_CENTER, global_settings.mdb_center); |
| 698 | sound_set(SOUND_MDB_SHAPE, global_settings.mdb_shape); |
| 699 | sound_set(SOUND_MDB_ENABLE, global_settings.mdb_enable); |
| 700 | sound_set(SOUND_SUPERBASS, global_settings.superbass); |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 701 | #endif |
Steve Bavin | c47172a | 2007-02-01 11:08:35 +0000 | [diff] [blame] | 702 | |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 703 | #ifdef HAVE_WM8758 |
| 704 | sound_set(SOUND_BASS_CUTOFF, global_settings.bass_cutoff); |
| 705 | sound_set(SOUND_TREBLE_CUTOFF, global_settings.treble_cutoff); |
| 706 | #endif |
| 707 | |
Steve Bavin | c47172a | 2007-02-01 11:08:35 +0000 | [diff] [blame] | 708 | #ifdef HAVE_USB_POWER |
Jonathan Gordon | 9a6f419 | 2007-02-18 05:32:06 +0000 | [diff] [blame] | 709 | #if CONFIG_CHARGING |
Steve Bavin | c47172a | 2007-02-01 11:08:35 +0000 | [diff] [blame] | 710 | usb_charging_enable(global_settings.usb_charging); |
| 711 | #endif |
| 712 | #endif |
Linus Nielsen Feltzing | 7bade1a | 2004-07-06 12:17:14 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 715 | void settings_apply(bool read_disk) |
Linus Nielsen Feltzing | 7bade1a | 2004-07-06 12:17:14 +0000 | [diff] [blame] | 716 | { |
| 717 | char buf[64]; |
Dan Everton | 5519d82 | 2006-02-17 21:55:11 +0000 | [diff] [blame] | 718 | #if CONFIG_CODEC == SWCODEC |
Dan Everton | 5a1d77d | 2006-02-17 19:56:22 +0000 | [diff] [blame] | 719 | int i; |
Dan Everton | 5519d82 | 2006-02-17 21:55:11 +0000 | [diff] [blame] | 720 | #endif |
Linus Nielsen Feltzing | 7bade1a | 2004-07-06 12:17:14 +0000 | [diff] [blame] | 721 | |
| 722 | sound_settings_apply(); |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 723 | |
Nils Wallménius | 0bfa3e7 | 2007-08-01 08:50:44 +0000 | [diff] [blame] | 724 | #ifndef HAVE_FLASH_STORAGE |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 725 | audio_set_buffer_margin(global_settings.buffer_margin); |
Nils Wallménius | 0bfa3e7 | 2007-08-01 08:50:44 +0000 | [diff] [blame] | 726 | #endif |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 727 | |
Rani Hod | cc839a2 | 2006-07-31 19:13:21 +0000 | [diff] [blame] | 728 | #ifdef HAVE_LCD_CONTRAST |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 729 | lcd_set_contrast(global_settings.contrast); |
Jens Arnold | 9051afa | 2006-07-25 11:15:50 +0000 | [diff] [blame] | 730 | #endif |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 731 | lcd_scroll_speed(global_settings.scroll_speed); |
Christian Gmeiner | 7c1879b | 2005-04-15 12:08:49 +0000 | [diff] [blame] | 732 | #ifdef HAVE_REMOTE_LCD |
Jens Arnold | bd1bb5f | 2005-06-17 21:43:00 +0000 | [diff] [blame] | 733 | lcd_remote_set_contrast(global_settings.remote_contrast); |
| 734 | lcd_remote_set_invert_display(global_settings.remote_invert); |
| 735 | lcd_remote_set_flip(global_settings.remote_flip_display); |
Marcoen Hirschberg | a86919a | 2006-05-22 16:40:41 +0000 | [diff] [blame] | 736 | lcd_remote_scroll_speed(global_settings.remote_scroll_speed); |
| 737 | lcd_remote_scroll_step(global_settings.remote_scroll_step); |
Jonathan Gordon | 282b390 | 2007-02-21 13:34:45 +0000 | [diff] [blame] | 738 | lcd_remote_scroll_delay(global_settings.remote_scroll_delay); |
Dave Chapman | e5ee9a2 | 2006-07-22 13:47:11 +0000 | [diff] [blame] | 739 | lcd_remote_bidir_scroll(global_settings.remote_bidir_limit); |
Miika Pekkarinen | 93d8ca5 | 2005-11-19 09:26:02 +0000 | [diff] [blame] | 740 | #ifdef HAVE_REMOTE_LCD_TICKING |
Miika Pekkarinen | f9234b3 | 2005-11-19 08:05:03 +0000 | [diff] [blame] | 741 | lcd_remote_emireduce(global_settings.remote_reduce_ticking); |
Miika Pekkarinen | 93d8ca5 | 2005-11-19 09:26:02 +0000 | [diff] [blame] | 742 | #endif |
Christian Gmeiner | 7477c09 | 2005-05-30 00:00:22 +0000 | [diff] [blame] | 743 | remote_backlight_set_timeout(global_settings.remote_backlight_timeout); |
Jonathan Gordon | 9a6f419 | 2007-02-18 05:32:06 +0000 | [diff] [blame] | 744 | #if CONFIG_CHARGING |
Jens Arnold | a6d409d | 2005-11-23 20:12:33 +0000 | [diff] [blame] | 745 | remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged); |
| 746 | #endif |
Michael Sevakis | 3d2e10b | 2006-09-10 02:00:40 +0000 | [diff] [blame] | 747 | #ifdef HAS_REMOTE_BUTTON_HOLD |
| 748 | remote_backlight_set_on_button_hold(global_settings.remote_backlight_on_button_hold); |
Jens Arnold | bd1bb5f | 2005-06-17 21:43:00 +0000 | [diff] [blame] | 749 | #endif |
Michael Sevakis | 3d2e10b | 2006-09-10 02:00:40 +0000 | [diff] [blame] | 750 | #endif /* HAVE_REMOTE_LCD */ |
Karl Kurbjun | 2ac037d | 2007-05-14 04:44:55 +0000 | [diff] [blame] | 751 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS |
| 752 | backlight_set_brightness(global_settings.brightness); |
| 753 | #endif |
Jens Arnold | 47bf6c5 | 2007-04-12 22:12:13 +0000 | [diff] [blame] | 754 | #ifdef HAVE_BACKLIGHT |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 755 | backlight_set_timeout(global_settings.backlight_timeout); |
Jonathan Gordon | 9a6f419 | 2007-02-18 05:32:06 +0000 | [diff] [blame] | 756 | #if CONFIG_CHARGING |
Jens Arnold | a6d409d | 2005-11-23 20:12:33 +0000 | [diff] [blame] | 757 | backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged); |
Jens Arnold | b51f7df | 2005-11-21 23:55:39 +0000 | [diff] [blame] | 758 | #endif |
Thom Johansen | 3c7278f | 2006-03-19 17:42:58 +0000 | [diff] [blame] | 759 | #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) |
Jens Arnold | 61b9d34 | 2005-06-20 17:03:09 +0000 | [diff] [blame] | 760 | backlight_set_fade_in(global_settings.backlight_fade_in); |
| 761 | backlight_set_fade_out(global_settings.backlight_fade_out); |
| 762 | #endif |
Jens Arnold | b51f7df | 2005-11-21 23:55:39 +0000 | [diff] [blame] | 763 | #endif |
Karl Kurbjun | 6f95ab7 | 2007-05-08 06:45:38 +0000 | [diff] [blame] | 764 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS |
| 765 | buttonlight_set_brightness(global_settings.buttonlight_brightness); |
| 766 | #endif |
Karl Kurbjun | 2ac037d | 2007-05-14 04:44:55 +0000 | [diff] [blame] | 767 | #ifdef HAVE_BUTTON_LIGHT |
Jens Arnold | 5f1ec30 | 2007-10-07 15:02:02 +0000 | [diff] [blame] | 768 | buttonlight_set_timeout(global_settings.buttonlight_timeout); |
Hristo Kovachev | 9b83c6c | 2005-12-22 10:43:36 +0000 | [diff] [blame] | 769 | #endif |
Nils Wallménius | 0bfa3e7 | 2007-08-01 08:50:44 +0000 | [diff] [blame] | 770 | #ifndef HAVE_FLASH_STORAGE |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 771 | ata_spindown(global_settings.disk_spindown); |
Nils Wallménius | 0bfa3e7 | 2007-08-01 08:50:44 +0000 | [diff] [blame] | 772 | #endif |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 773 | #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR) |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 774 | dac_line_in(global_settings.line_in); |
| 775 | #endif |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 776 | set_poweroff_timeout(global_settings.poweroff); |
Björn Stenberg | dea3122 | 2002-10-08 15:42:40 +0000 | [diff] [blame] | 777 | |
Uwe Freese | 0bf70e6 | 2002-12-16 22:58:48 +0000 | [diff] [blame] | 778 | set_battery_capacity(global_settings.battery_capacity); |
Jens Arnold | 91846a1 | 2005-01-30 16:25:46 +0000 | [diff] [blame] | 779 | #if BATTERY_TYPES_COUNT > 1 |
| 780 | set_battery_type(global_settings.battery_type); |
| 781 | #endif |
Uwe Freese | 0bf70e6 | 2002-12-16 22:58:48 +0000 | [diff] [blame] | 782 | |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 783 | #ifdef HAVE_LCD_BITMAP |
Björn Stenberg | b107920 | 2003-02-27 14:22:30 +0000 | [diff] [blame] | 784 | lcd_set_invert_display(global_settings.invert); |
Jörg Hohensohn | a5e1d06 | 2003-12-20 10:00:37 +0000 | [diff] [blame] | 785 | lcd_set_flip(global_settings.flip_display); |
| 786 | button_set_flip(global_settings.flip_display); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 787 | lcd_update(); /* refresh after flipping the screen */ |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 788 | settings_apply_pm_range(); |
| 789 | peak_meter_init_times( |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 790 | global_settings.peak_meter_release, global_settings.peak_meter_hold, |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 791 | global_settings.peak_meter_clip_hold); |
| 792 | #endif |
| 793 | |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 794 | if (read_disk) |
| 795 | { |
Jonathan Gordon | 5a169bb | 2008-06-23 06:04:17 +0000 | [diff] [blame] | 796 | |
| 797 | #ifdef HAVE_LCD_BITMAP |
| 798 | /* fonts need to be loaded before the WPS */ |
| 799 | if ( global_settings.font_file[0]) { |
| 800 | snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", |
| 801 | global_settings.font_file); |
| 802 | font_load(buf); |
| 803 | } |
| 804 | else |
| 805 | font_reset(); |
| 806 | |
| 807 | if ( global_settings.kbd_file[0]) { |
| 808 | snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd", |
| 809 | global_settings.kbd_file); |
| 810 | load_kbd(buf); |
| 811 | } |
| 812 | else |
| 813 | load_kbd(NULL); |
| 814 | #endif |
Jens Arnold | 0297873 | 2006-11-13 00:45:21 +0000 | [diff] [blame] | 815 | #if LCD_DEPTH > 1 |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 816 | unload_wps_backdrop(); |
Peter D'Hoye | 93b899d | 2006-05-21 11:00:02 +0000 | [diff] [blame] | 817 | #endif |
Nicolas Pennequin | 7fdfa56 | 2007-04-25 21:44:56 +0000 | [diff] [blame] | 818 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 819 | unload_remote_wps_backdrop(); |
Nicolas Pennequin | 7fdfa56 | 2007-04-25 21:44:56 +0000 | [diff] [blame] | 820 | #endif |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 821 | if ( global_settings.wps_file[0] && |
| 822 | global_settings.wps_file[0] != 0xff ) { |
| 823 | snprintf(buf, sizeof buf, WPS_DIR "/%s.wps", |
| 824 | global_settings.wps_file); |
Dave Chapman | d02c79c | 2008-03-21 19:38:00 +0000 | [diff] [blame] | 825 | wps_data_load(gui_wps[0].data, &screens[0], buf, true); |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 826 | } |
| 827 | else |
| 828 | { |
| 829 | wps_data_init(gui_wps[0].data); |
Nicolas Pennequin | 2a2b8d8 | 2007-04-25 13:09:56 +0000 | [diff] [blame] | 830 | #ifdef HAVE_REMOTE_LCD |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 831 | gui_wps[0].data->remote_wps = false; |
Nicolas Pennequin | 2a2b8d8 | 2007-04-25 13:09:56 +0000 | [diff] [blame] | 832 | #endif |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 833 | } |
Christi Scarborough | 4c0b83f | 2005-11-17 20:14:59 +0000 | [diff] [blame] | 834 | |
Jens Arnold | 0297873 | 2006-11-13 00:45:21 +0000 | [diff] [blame] | 835 | #if LCD_DEPTH > 1 |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 836 | if ( global_settings.backdrop_file[0] && |
| 837 | global_settings.backdrop_file[0] != 0xff ) { |
| 838 | snprintf(buf, sizeof buf, BACKDROP_DIR "/%s.bmp", |
| 839 | global_settings.backdrop_file); |
| 840 | load_main_backdrop(buf); |
| 841 | } else { |
| 842 | unload_main_backdrop(); |
| 843 | } |
| 844 | show_main_backdrop(); |
Greg White | e4ef26c | 2007-01-17 09:49:42 +0000 | [diff] [blame] | 845 | #endif |
Nicolas Pennequin | 7fdfa56 | 2007-04-25 21:44:56 +0000 | [diff] [blame] | 846 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 847 | show_remote_main_backdrop(); |
Nicolas Pennequin | 7fdfa56 | 2007-04-25 21:44:56 +0000 | [diff] [blame] | 848 | #endif |
Greg White | e4ef26c | 2007-01-17 09:49:42 +0000 | [diff] [blame] | 849 | |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 850 | #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) |
| 851 | if ( global_settings.rwps_file[0]) { |
| 852 | snprintf(buf, sizeof buf, WPS_DIR "/%s.rwps", |
| 853 | global_settings.rwps_file); |
Dave Chapman | d02c79c | 2008-03-21 19:38:00 +0000 | [diff] [blame] | 854 | wps_data_load(gui_wps[1].data, &screens[1], buf, true); |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 855 | } |
| 856 | else |
| 857 | { |
| 858 | wps_data_init(gui_wps[1].data); |
| 859 | gui_wps[1].data->remote_wps = true; |
| 860 | } |
| 861 | #endif |
Jonathan Gordon | e1ba7f7 | 2008-03-06 07:03:14 +0000 | [diff] [blame] | 862 | if ( global_settings.lang_file[0]) { |
| 863 | snprintf(buf, sizeof buf, LANG_DIR "/%s.lng", |
| 864 | global_settings.lang_file); |
| 865 | lang_load(buf); |
| 866 | talk_init(); /* use voice of same language */ |
| 867 | } |
| 868 | /* load the icon set */ |
| 869 | icons_init(); |
| 870 | |
| 871 | #ifdef HAVE_LCD_COLOR |
| 872 | if (global_settings.colors_file[0]) |
| 873 | read_color_theme_file(); |
| 874 | #endif |
| 875 | } |
| 876 | |
Jens Arnold | 0297873 | 2006-11-13 00:45:21 +0000 | [diff] [blame] | 877 | #ifdef HAVE_LCD_COLOR |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 878 | screens[SCREEN_MAIN].set_foreground(global_settings.fg_color); |
| 879 | screens[SCREEN_MAIN].set_background(global_settings.bg_color); |
Nicolas Pennequin | f3b015f | 2007-09-27 15:42:55 +0000 | [diff] [blame] | 880 | screens[SCREEN_MAIN].set_selector_start(global_settings.lss_color); |
| 881 | screens[SCREEN_MAIN].set_selector_end(global_settings.lse_color); |
| 882 | screens[SCREEN_MAIN].set_selector_text(global_settings.lst_color); |
Dave Chapman | d9e5b67 | 2006-02-02 20:42:56 +0000 | [diff] [blame] | 883 | #endif |
| 884 | |
Jonathan Gordon | d6a5f62 | 2008-03-06 07:54:19 +0000 | [diff] [blame] | 885 | #ifdef HAVE_LCD_BITMAP |
Björn Stenberg | a2e98c1 | 2002-12-12 15:20:37 +0000 | [diff] [blame] | 886 | lcd_scroll_step(global_settings.scroll_step); |
Tomas Salfischberger | 7fa39df | 2006-01-22 01:42:05 +0000 | [diff] [blame] | 887 | gui_list_screen_scroll_step(global_settings.screen_scroll_step); |
| 888 | gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view); |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 889 | #else |
| 890 | lcd_jump_scroll(global_settings.jump_scroll); |
Jonathan Gordon | 282b390 | 2007-02-21 13:34:45 +0000 | [diff] [blame] | 891 | lcd_jump_scroll_delay(global_settings.jump_scroll_delay); |
Björn Stenberg | dea3122 | 2002-10-08 15:42:40 +0000 | [diff] [blame] | 892 | #endif |
Björn Stenberg | f0d02aa | 2003-02-12 09:07:48 +0000 | [diff] [blame] | 893 | lcd_bidir_scroll(global_settings.bidir_limit); |
Jonathan Gordon | 282b390 | 2007-02-21 13:34:45 +0000 | [diff] [blame] | 894 | lcd_scroll_delay(global_settings.scroll_delay); |
Björn Stenberg | 227253c | 2002-10-09 23:13:25 +0000 | [diff] [blame] | 895 | |
Linus Nielsen Feltzing | 6271b2b | 2005-06-09 09:47:00 +0000 | [diff] [blame] | 896 | |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame] | 897 | set_codepage(global_settings.default_codepage); |
| 898 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 899 | #if CONFIG_CODEC == SWCODEC |
Miika Pekkarinen | 90161c9 | 2005-07-22 16:46:27 +0000 | [diff] [blame] | 900 | audio_set_crossfade(global_settings.crossfade); |
Michael Sevakis | d4e904b | 2007-02-24 17:06:36 +0000 | [diff] [blame] | 901 | dsp_set_replaygain(); |
Marcoen Hirschberg | e13fad3 | 2005-11-14 21:56:56 +0000 | [diff] [blame] | 902 | dsp_set_crossfeed(global_settings.crossfeed); |
Thom Johansen | 8238b49 | 2006-04-11 13:49:05 +0000 | [diff] [blame] | 903 | dsp_set_crossfeed_direct_gain(global_settings.crossfeed_direct_gain); |
| 904 | dsp_set_crossfeed_cross_params(global_settings.crossfeed_cross_gain, |
Thom Johansen | 8e6e290 | 2007-03-07 15:06:33 +0000 | [diff] [blame] | 905 | global_settings.crossfeed_hf_attenuation, |
Thom Johansen | 8238b49 | 2006-04-11 13:49:05 +0000 | [diff] [blame] | 906 | global_settings.crossfeed_hf_cutoff); |
Dan Everton | 91db368 | 2006-03-27 21:20:35 +0000 | [diff] [blame] | 907 | |
Dan Everton | fc47f14 | 2007-04-11 09:13:13 +0000 | [diff] [blame] | 908 | /* Configure software equalizer, hardware eq is handled in audio_init() */ |
Dan Everton | daebff8 | 2006-03-28 21:19:30 +0000 | [diff] [blame] | 909 | dsp_set_eq(global_settings.eq_enabled); |
Zakk Roberts | 8bdd92b | 2006-03-30 05:56:19 +0000 | [diff] [blame] | 910 | dsp_set_eq_precut(global_settings.eq_precut); |
Dan Everton | 5a1d77d | 2006-02-17 19:56:22 +0000 | [diff] [blame] | 911 | for(i = 0; i < 5; i++) { |
Dan Everton | daebff8 | 2006-03-28 21:19:30 +0000 | [diff] [blame] | 912 | dsp_set_eq_coefs(i); |
Dan Everton | 5a1d77d | 2006-02-17 19:56:22 +0000 | [diff] [blame] | 913 | } |
Thom Johansen | 3547700 | 2006-10-27 20:41:33 +0000 | [diff] [blame] | 914 | |
| 915 | dsp_dither_enable(global_settings.dithering_enabled); |
Linus Nielsen Feltzing | 6271b2b | 2005-06-09 09:47:00 +0000 | [diff] [blame] | 916 | #endif |
Linus Nielsen Feltzing | 8782bc8 | 2005-07-01 09:42:39 +0000 | [diff] [blame] | 917 | |
| 918 | #ifdef HAVE_SPDIF_POWER |
| 919 | spdif_power_enable(global_settings.spdif_enable); |
| 920 | #endif |
Björn Stenberg | da5fb18 | 2006-03-24 13:47:24 +0000 | [diff] [blame] | 921 | |
Jens Arnold | 47bf6c5 | 2007-04-12 22:12:13 +0000 | [diff] [blame] | 922 | #ifdef HAVE_BACKLIGHT |
Björn Stenberg | da5fb18 | 2006-03-24 13:47:24 +0000 | [diff] [blame] | 923 | set_backlight_filter_keypress(global_settings.bl_filter_first_keypress); |
Hristo Kovachev | a70c6b9 | 2006-03-25 19:16:45 +0000 | [diff] [blame] | 924 | #ifdef HAVE_REMOTE_LCD |
| 925 | set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress); |
| 926 | #endif |
Rani Hod | c9f59e6 | 2006-08-08 22:03:56 +0000 | [diff] [blame] | 927 | #ifdef HAS_BUTTON_HOLD |
| 928 | backlight_set_on_button_hold(global_settings.backlight_on_button_hold); |
Björn Stenberg | da5fb18 | 2006-03-24 13:47:24 +0000 | [diff] [blame] | 929 | #endif |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 930 | #ifdef HAVE_LCD_SLEEP_SETTING |
Rani Hod | c9f59e6 | 2006-08-08 22:03:56 +0000 | [diff] [blame] | 931 | lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off); |
| 932 | #endif |
Jens Arnold | 47bf6c5 | 2007-04-12 22:12:13 +0000 | [diff] [blame] | 933 | #endif /* HAVE_BACKLIGHT */ |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 934 | |
Michael Sevakis | c541e04 | 2008-05-29 21:27:44 +0000 | [diff] [blame] | 935 | #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING |
| 936 | touchpad_set_sensitivity(global_settings.touchpad_sensitivity); |
| 937 | #endif |
| 938 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 939 | /* This should stay last */ |
| 940 | #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC |
| 941 | enc_global_settings_apply(); |
| 942 | #endif |
Jonathan Gordon | be185a1 | 2008-03-26 09:05:42 +0000 | [diff] [blame] | 943 | list_init_viewports(NULL); |
Linus Nielsen Feltzing | 40ffbb1 | 2002-10-03 09:31:01 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Björn Stenberg | c5aaab4 | 2003-03-10 16:31:02 +0000 | [diff] [blame] | 946 | |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 947 | /* |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 948 | * reset all settings to their default value |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 949 | */ |
Stéphane Doyon | b2aa86a | 2008-04-20 14:12:28 +0000 | [diff] [blame] | 950 | void reset_setting(const struct settings_list *setting, void *var) |
| 951 | { |
| 952 | switch (setting->flags&F_T_MASK) |
| 953 | { |
| 954 | case F_T_INT: |
| 955 | case F_T_UINT: |
| 956 | if (setting->flags&F_DEF_ISFUNC) |
| 957 | *(int*)var = setting->default_val.func(); |
| 958 | else if (setting->flags&F_T_SOUND) |
| 959 | *(int*)var = sound_default(setting->sound_setting->setting); |
| 960 | else *(int*)var = setting->default_val.int_; |
| 961 | break; |
| 962 | case F_T_BOOL: |
| 963 | *(bool*)var = setting->default_val.bool_; |
| 964 | break; |
| 965 | case F_T_CHARPTR: |
| 966 | case F_T_UCHARPTR: |
| 967 | strncpy((char*)var, setting->default_val.charptr, |
| 968 | setting->filename_setting->max_len); |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | void settings_reset(void) |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 974 | { |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 975 | int i; |
Jonathan Gordon | 0158336 | 2008-03-25 12:42:47 +0000 | [diff] [blame] | 976 | |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 977 | for(i=0; i<nb_settings; i++) |
Stéphane Doyon | b2aa86a | 2008-04-20 14:12:28 +0000 | [diff] [blame] | 978 | reset_setting(&settings[i], settings[i].setting); |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 979 | #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC |
| 980 | enc_global_settings_reset(); |
| 981 | #endif |
Björn Stenberg | f80d8a70 | 2002-06-27 00:20:00 +0000 | [diff] [blame] | 982 | } |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 983 | |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 984 | /** Changing setting values **/ |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 985 | const struct settings_list* find_setting(const void* variable, int *id) |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 986 | { |
| 987 | int i; |
| 988 | for(i=0;i<nb_settings;i++) |
| 989 | { |
| 990 | if (settings[i].setting == variable) |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 991 | { |
| 992 | if (id) |
| 993 | *id = i; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 994 | return &settings[i]; |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 995 | } |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 996 | } |
| 997 | return NULL; |
| 998 | } |
Paul Louden | f7c938a | 2008-02-05 09:09:38 +0000 | [diff] [blame] | 999 | |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1000 | bool set_bool(const char* string, const bool* variable ) |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 1001 | { |
Jens Arnold | 4960808 | 2005-10-16 11:15:51 +0000 | [diff] [blame] | 1002 | return set_bool_options(string, variable, |
Daniel Stenberg | f981ea9 | 2005-12-05 22:44:42 +0000 | [diff] [blame] | 1003 | (char *)STR(LANG_SET_BOOL_YES), |
| 1004 | (char *)STR(LANG_SET_BOOL_NO), |
| 1005 | NULL); |
Björn Stenberg | 26712d5 | 2003-06-05 11:11:10 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 1008 | |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1009 | bool set_bool_options(const char* string, const bool* variable, |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1010 | const char* yes_str, int yes_voice, |
| 1011 | const char* no_str, int no_voice, |
Jörg Hohensohn | 42ffbf9 | 2004-03-15 08:27:51 +0000 | [diff] [blame] | 1012 | void (*function)(bool)) |
Eric Linenberg | c5b645b | 2002-09-05 04:42:12 +0000 | [diff] [blame] | 1013 | { |
Daniel Stenberg | f981ea9 | 2005-12-05 22:44:42 +0000 | [diff] [blame] | 1014 | struct opt_items names[] = { |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1015 | {(unsigned const char *)no_str, no_voice}, |
| 1016 | {(unsigned const char *)yes_str, yes_voice} |
Daniel Stenberg | f981ea9 | 2005-12-05 22:44:42 +0000 | [diff] [blame] | 1017 | }; |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1018 | bool result; |
| 1019 | |
Kevin Ferrare | cbbdc95 | 2005-11-04 07:18:36 +0000 | [diff] [blame] | 1020 | result = set_option(string, variable, BOOL, names, 2, |
Jonathan Gordon | a5278fa | 2007-07-11 05:41:23 +0000 | [diff] [blame] | 1021 | (void (*)(int))function); |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1022 | return result; |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Daniel Stenberg | f981ea9 | 2005-12-05 22:44:42 +0000 | [diff] [blame] | 1025 | bool set_int(const unsigned char* string, |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 1026 | const char* unit, |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1027 | int voice_unit, |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1028 | const int* variable, |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 1029 | void (*function)(int), |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1030 | int step, |
| 1031 | int min, |
| 1032 | int max, |
Nils Wallménius | 9b59183 | 2007-08-19 10:22:46 +0000 | [diff] [blame] | 1033 | void (*formatter)(char*, size_t, int, const char*) ) |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 1034 | { |
Jonathan Gordon | fb62831 | 2007-02-12 14:22:35 +0000 | [diff] [blame] | 1035 | return set_int_ex(string, unit, voice_unit, variable, function, |
| 1036 | step, min, max, formatter, NULL); |
Björn Stenberg | 60b356e | 2002-06-27 01:08:11 +0000 | [diff] [blame] | 1037 | } |
Björn Stenberg | 26712d5 | 2003-06-05 11:11:10 +0000 | [diff] [blame] | 1038 | |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1039 | bool set_int_ex(const unsigned char* string, |
| 1040 | const char* unit, |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1041 | int voice_unit, |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1042 | const int* variable, |
| 1043 | void (*function)(int), |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1044 | int step, |
| 1045 | int min, |
| 1046 | int max, |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1047 | void (*formatter)(char*, size_t, int, const char*), |
| 1048 | int32_t (*get_talk_id)(int, int)) |
| 1049 | { |
| 1050 | (void)unit; |
| 1051 | struct settings_list item; |
| 1052 | struct int_setting data = { |
| 1053 | function, voice_unit, min, max, step, |
| 1054 | formatter, get_talk_id |
| 1055 | }; |
| 1056 | item.int_setting = &data; |
| 1057 | item.flags = F_INT_SETTING|F_T_INT; |
| 1058 | item.lang_id = -1; |
| 1059 | item.cfg_vals = (char*)string; |
| 1060 | item.setting = (void *)variable; |
Jonathan Gordon | fe9dca3 | 2008-04-23 11:07:40 +0000 | [diff] [blame] | 1061 | return option_screen(&item, NULL, false, NULL); |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1062 | } |
Markus Braun | 3181f68 | 2002-08-09 12:38:45 +0000 | [diff] [blame] | 1063 | |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 1064 | |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1065 | static const struct opt_items *set_option_options; |
| 1066 | static void set_option_formatter(char* buf, size_t size, int item, const char* unit) |
| 1067 | { |
| 1068 | (void)unit; |
| 1069 | const unsigned char *text = set_option_options[item].string; |
| 1070 | snprintf(buf, size, "%s", P2STR(text)); |
| 1071 | } |
| 1072 | static int32_t set_option_get_talk_id(int value, int unit) |
| 1073 | { |
| 1074 | (void)unit; |
| 1075 | return set_option_options[value].voice_id; |
| 1076 | } |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1077 | bool set_option(const char* string, const void* variable, enum optiontype type, |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1078 | const struct opt_items* options, |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1079 | int numoptions, void (*function)(int)) |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1080 | { |
| 1081 | int temp; |
| 1082 | struct settings_list item; |
| 1083 | struct int_setting data = { |
| 1084 | function, UNIT_INT, 0, numoptions-1, 1, |
| 1085 | set_option_formatter, set_option_get_talk_id |
| 1086 | }; |
| 1087 | set_option_options = options; |
| 1088 | item.int_setting = &data; |
| 1089 | item.flags = F_INT_SETTING|F_T_INT; |
| 1090 | item.lang_id = -1; |
| 1091 | item.cfg_vals = (char*)string; |
| 1092 | item.setting = &temp; |
| 1093 | if (type == BOOL) |
| 1094 | temp = *(bool*)variable? 1: 0; |
| 1095 | else |
| 1096 | temp = *(int*)variable; |
Jonathan Gordon | fe9dca3 | 2008-04-23 11:07:40 +0000 | [diff] [blame] | 1097 | if (!option_screen(&item, NULL, false, NULL)) |
Steve Bavin | cd88e2a | 2008-03-25 15:24:03 +0000 | [diff] [blame] | 1098 | { |
| 1099 | if (type == BOOL) |
| 1100 | *(bool*)variable = (temp == 1? true: false); |
| 1101 | else |
| 1102 | *(int*)variable = temp; |
| 1103 | return false; |
| 1104 | } |
| 1105 | return true; |
| 1106 | } |
| 1107 | |
| 1108 | |
Steve Bavin | 135cc75 | 2008-03-28 12:51:33 +0000 | [diff] [blame] | 1109 | void set_file(const char* filename, char* setting, int maxlen) |
Jonathan Gordon | 41bd24e | 2007-01-29 13:18:57 +0000 | [diff] [blame] | 1110 | { |
| 1111 | char* fptr = strrchr(filename,'/'); |
| 1112 | int len; |
| 1113 | int extlen = 0; |
| 1114 | char* ptr; |
| 1115 | |
| 1116 | if (!fptr) |
| 1117 | return; |
| 1118 | |
| 1119 | *fptr = 0; |
| 1120 | fptr++; |
| 1121 | |
| 1122 | len = strlen(fptr); |
| 1123 | ptr = fptr + len; |
| 1124 | while ((*ptr != '.') && (ptr != fptr)) { |
| 1125 | extlen++; |
| 1126 | ptr--; |
| 1127 | } |
| 1128 | if(ptr == fptr) extlen = 0; |
| 1129 | |
| 1130 | if (strncasecmp(ROCKBOX_DIR, filename ,strlen(ROCKBOX_DIR)) || |
| 1131 | (len-extlen > maxlen)) |
| 1132 | return; |
| 1133 | |
| 1134 | strncpy(setting, fptr, len-extlen); |
| 1135 | setting[len-extlen]=0; |
| 1136 | |
| 1137 | settings_save(); |
| 1138 | } |
| 1139 | |