Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Jonathan Gordon | 4e73b53 | 2007-02-13 00:32:17 +0000 | [diff] [blame] | 8 | * $Id$ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 9 | * |
| 10 | * Copyright (C) 2007 Jonathan Gordon |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #ifndef __SETTINGSLIST_H |
| 22 | #define __SETTINGSLIST_H |
| 23 | #include <stdio.h> |
| 24 | #include <stddef.h> |
| 25 | #include <stdbool.h> |
| 26 | #include <limits.h> |
| 27 | #include "inttypes.h" |
| 28 | |
Jonathan Gordon | 0c33756 | 2007-01-24 03:14:07 +0000 | [diff] [blame] | 29 | typedef int (*_isfunc_type)(void); |
| 30 | |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 31 | union storage_type { |
| 32 | int int_; |
| 33 | unsigned int uint_; |
| 34 | bool bool_; |
| 35 | char *charptr; |
| 36 | unsigned char *ucharptr; |
Jonathan Gordon | 0c33756 | 2007-01-24 03:14:07 +0000 | [diff] [blame] | 37 | _isfunc_type func; |
Jonathan Gordon | 5395957 | 2008-11-03 10:43:37 +0000 | [diff] [blame] | 38 | void* custom; |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 39 | }; |
| 40 | /* the variable type for the setting */ |
| 41 | #define F_T_INT 1 |
| 42 | #define F_T_UINT 2 |
| 43 | #define F_T_BOOL 3 |
| 44 | #define F_T_CHARPTR 4 |
| 45 | #define F_T_UCHARPTR 5 |
Jonathan Gordon | 5395957 | 2008-11-03 10:43:37 +0000 | [diff] [blame] | 46 | #define F_T_CUSTOM 6 /* MUST use struct custom_setting below */ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 47 | #define F_T_MASK 0x7 |
| 48 | |
| 49 | struct sound_setting { |
| 50 | int setting; /* from the enum in firmware/sound.h */ |
| 51 | }; |
| 52 | #define F_T_SOUND 0x8 /* this variable uses the set_sound stuff, \ |
| 53 | | with one of the above types (usually F_T_INT) \ |
| 54 | These settings get the default from sound_default(setting); */ |
| 55 | struct bool_setting { |
| 56 | void (*option_callback)(bool); |
| 57 | int lang_yes; |
| 58 | int lang_no; |
| 59 | }; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 60 | #define F_BOOL_SETTING (F_T_BOOL|0x10) |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 61 | #define F_RGB 0x20 |
| 62 | |
Jonathan Gordon | 0c33756 | 2007-01-24 03:14:07 +0000 | [diff] [blame] | 63 | struct filename_setting { |
| 64 | const char* prefix; |
| 65 | const char* suffix; |
| 66 | int max_len; |
| 67 | }; |
| 68 | #define F_FILENAME 0x40 |
| 69 | |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 70 | struct int_setting { |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 71 | void (*option_callback)(int); |
| 72 | int unit; |
| 73 | int min; |
| 74 | int max; |
| 75 | int step; |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 76 | const char* (*formatter)(char*, size_t, int, const char*); |
Jens Arnold | 09a7861 | 2007-11-26 23:10:20 +0000 | [diff] [blame] | 77 | int32_t (*get_talk_id)(int, int); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 78 | }; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 79 | #define F_INT_SETTING 0x80 |
| 80 | |
| 81 | struct choice_setting { |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 82 | void (*option_callback)(int); |
| 83 | int count; |
| 84 | union { |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 85 | const unsigned char **desc; |
| 86 | const int *talks; |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 87 | }; |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 88 | }; |
| 89 | #define F_CHOICE_SETTING 0x100 |
Jonathan Gordon | fe3cfcc | 2007-02-08 10:28:42 +0000 | [diff] [blame] | 90 | #define F_CHOICETALKS 0x200 /* uses .talks in the above struct for the talks */ |
| 91 | /* and cfg_vals for the strings to display */ |
William Wilgus | dc87e9e | 2016-11-22 06:21:31 +0100 | [diff] [blame] | 92 | |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 93 | struct table_setting { |
| 94 | void (*option_callback)(int); |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 95 | const char* (*formatter)(char*, size_t, int, const char*); |
Jens Arnold | 09a7861 | 2007-11-26 23:10:20 +0000 | [diff] [blame] | 96 | int32_t (*get_talk_id)(int, int); |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 97 | int unit; |
| 98 | int count; |
| 99 | const int * values; |
| 100 | }; |
| 101 | #define F_TABLE_SETTING 0x2000 |
| 102 | #define F_ALLOW_ARBITRARY_VALS 0x4000 |
Jonathan Gordon | 0c33756 | 2007-01-24 03:14:07 +0000 | [diff] [blame] | 103 | /* these use the _isfunc_type type for the function */ |
| 104 | /* typedef int (*_isfunc_type)(void); */ |
| 105 | #define F_MIN_ISFUNC 0x100000 /* min(above) is function pointer to above type */ |
| 106 | #define F_MAX_ISFUNC 0x200000 /* max(above) is function pointer to above type */ |
| 107 | #define F_DEF_ISFUNC 0x400000 /* default_val is function pointer to above type */ |
| 108 | |
Jonathan Gordon | 5395957 | 2008-11-03 10:43:37 +0000 | [diff] [blame] | 109 | /* The next stuff is used when none of the other types work. |
| 110 | Should really only be used if the value you want to store in global_settings |
| 111 | is very different to the string you want to use in the config. */ |
| 112 | #define F_CUSTOM_SETTING 0x8000 |
| 113 | struct custom_setting { |
| 114 | /* load the saved value from the .cfg |
| 115 | setting: pointer into global_settings |
William Wilgus | dc87e9e | 2016-11-22 06:21:31 +0100 | [diff] [blame] | 116 | value: the text from the .cfg |
Jonathan Gordon | 5395957 | 2008-11-03 10:43:37 +0000 | [diff] [blame] | 117 | */ |
| 118 | void (*load_from_cfg)(void* setting, char*value); |
| 119 | /* store the value into a .cfg |
| 120 | setting: pointer into global_settings |
| 121 | buf/buf_len: buffer and length to write the string into. |
| 122 | Returns the string. |
| 123 | */ |
| 124 | char* (*write_to_cfg)(void* setting, char*buf, int buf_len); |
| 125 | /* Check if the setting has been changed from the default. |
| 126 | setting: pointer into global_settings |
| 127 | defaultval: the value given in the settings_list.c macro |
| 128 | Return true if the setting was changed |
| 129 | */ |
| 130 | bool (*is_changed)(void* setting, void* defaultval); |
| 131 | /* Set the setting back to its default value. |
| 132 | setting: pointer into global_settings |
| 133 | defaultval: the value given in the settings_list.c macro |
| 134 | */ |
| 135 | void (*set_default)(void* setting, void* defaultval); |
| 136 | }; |
| 137 | |
William Wilgus | a06d9c8 | 2018-12-17 22:27:55 -0600 | [diff] [blame] | 138 | #define F_TIME_SETTING 0x10000 /* int,table format hh:mm:ss.mss auto ranged */ |
Jonathan Gordon | 9adf056 | 2007-05-29 04:39:11 +0000 | [diff] [blame] | 139 | #define F_THEMESETTING 0x0800000 |
| 140 | #define F_RECSETTING 0x1000000 |
Dan Everton | 5886efa | 2007-12-07 10:59:07 +0000 | [diff] [blame] | 141 | #define F_EQSETTING 0x2000000 |
Jonathan Gordon | b8bc45d | 2007-12-24 22:35:31 +0000 | [diff] [blame] | 142 | #define F_SOUNDSETTING 0x4000000 |
Jonathan Gordon | 4718a1e | 2007-02-08 04:33:41 +0000 | [diff] [blame] | 143 | |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 144 | #define F_NVRAM_BYTES_MASK 0xE0000 /*0-4 bytes can be stored */ |
| 145 | #define F_NVRAM_MASK_SHIFT 17 |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 146 | #define NVRAM_CONFIG_VERSION 8 |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 147 | /* Above define should be bumped if |
| 148 | - a new NVRAM setting is added between 2 other NVRAM settings |
| 149 | - number of bytes for a NVRAM setting is changed |
| 150 | - a NVRAM setting is removed |
| 151 | */ |
Nils Wallménius | 12a957b | 2007-09-15 17:29:15 +0000 | [diff] [blame] | 152 | #define F_TEMPVAR 0x0400 /* used if the setting should be set using a temp var */ |
Jonathan Gordon | 91ccc01 | 2007-11-05 13:15:35 +0000 | [diff] [blame] | 153 | #define F_PADTITLE 0x800 /* pad the title with spaces to force it to scroll */ |
Nils Wallménius | 12a957b | 2007-09-15 17:29:15 +0000 | [diff] [blame] | 154 | #define F_NO_WRAP 0x1000 /* used if the list should not wrap */ |
Jonathan Gordon | 0c33756 | 2007-01-24 03:14:07 +0000 | [diff] [blame] | 155 | |
Jonathan Gordon | 1eb17dc | 2013-02-05 23:20:17 +1100 | [diff] [blame] | 156 | #define F_BANFROMQS 0x80000000 /* ban the setting from the quickscreen items */ |
| 157 | #define F_DEPRECATED 0x40000000 /* DEPRECATED setting, don't write to .cfg */ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 158 | struct settings_list { |
Jonathan Gordon | 1eb17dc | 2013-02-05 23:20:17 +1100 | [diff] [blame] | 159 | uint32_t flags; /* BD__ _SER TFFF NNN_ _ATW PTVC IFRB STTT */ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 160 | void *setting; |
Jonathan Gordon | 4ca8a43 | 2007-01-26 05:45:06 +0000 | [diff] [blame] | 161 | int lang_id; /* -1 for none */ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 162 | union storage_type default_val; |
| 163 | const char *cfg_name; /* this settings name in the cfg file */ |
| 164 | const char *cfg_vals; /*comma seperated legal values, or NULL */ |
| 165 | /* used with F_T_UCHARPTR this is the folder prefix */ |
| 166 | union { |
Jens Arnold | d490f44 | 2007-11-25 17:36:21 +0000 | [diff] [blame] | 167 | const void *RESERVED; /* to stop compile errors, will be removed */ |
| 168 | const struct sound_setting *sound_setting; /* use F_T_SOUND for this */ |
| 169 | const struct bool_setting *bool_setting; /* F_BOOL_SETTING */ |
| 170 | const struct filename_setting *filename_setting; /* use F_FILENAME */ |
| 171 | const struct int_setting *int_setting; /* use F_INT_SETTING */ |
| 172 | const struct choice_setting *choice_setting; /* F_CHOICE_SETTING */ |
| 173 | const struct table_setting *table_setting; /* F_TABLE_SETTING */ |
Jonathan Gordon | 5395957 | 2008-11-03 10:43:37 +0000 | [diff] [blame] | 174 | const struct custom_setting *custom_setting; /* F_CUSTOM_SETTING */ |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 175 | }; |
| 176 | }; |
Jonathan Gordon | 9e2807f | 2008-10-26 11:44:21 +0000 | [diff] [blame] | 177 | const struct settings_list* get_settings_list(int*count); |
Jonathan Gordon | b2e5090 | 2007-01-23 13:40:44 +0000 | [diff] [blame] | 178 | #ifndef PLUGIN |
| 179 | /* not needed for plugins and just causes compile error, |
| 180 | possibly fix proberly later */ |
| 181 | extern const struct settings_list settings[]; |
| 182 | extern const int nb_settings; |
| 183 | |
| 184 | #endif |
| 185 | |
| 186 | #endif |