7 #include "config/parameter_group.h"
9 #include "settings_generated.h"
11 typedef struct lookupTableEntry_s
{
12 const char * const *values
;
13 const uint8_t valueCount
;
16 #define SETTING_TYPE_OFFSET 0
17 #define SETTING_SECTION_OFFSET 3
18 #define SETTING_MODE_OFFSET 6
21 // value type, bits 0-2
22 VAR_UINT8
= (0 << SETTING_TYPE_OFFSET
),
23 VAR_INT8
= (1 << SETTING_TYPE_OFFSET
),
24 VAR_UINT16
= (2 << SETTING_TYPE_OFFSET
),
25 VAR_INT16
= (3 << SETTING_TYPE_OFFSET
),
26 VAR_UINT32
= (4 << SETTING_TYPE_OFFSET
),
27 VAR_FLOAT
= (5 << SETTING_TYPE_OFFSET
), // 0x05
28 VAR_STRING
= (6 << SETTING_TYPE_OFFSET
) // 0x06
32 // value section, bits 3-5
33 MASTER_VALUE
= (0 << SETTING_SECTION_OFFSET
),
34 PROFILE_VALUE
= (1 << SETTING_SECTION_OFFSET
),
35 CONTROL_RATE_VALUE
= (2 << SETTING_SECTION_OFFSET
),
36 BATTERY_CONFIG_VALUE
= (3 << SETTING_SECTION_OFFSET
),
37 MIXER_CONFIG_VALUE
= (4 << SETTING_SECTION_OFFSET
),
38 EZ_TUNE_VALUE
= (5 << SETTING_SECTION_OFFSET
)
42 // value mode, bits 6-7
43 MODE_DIRECT
= (0 << SETTING_MODE_OFFSET
),
44 MODE_LOOKUP
= (1 << SETTING_MODE_OFFSET
), // 0x40
48 #define SETTING_TYPE_MASK (0x07)
49 #define SETTING_SECTION_MASK (0x38)
50 #define SETTING_MODE_MASK (0xC0)
52 typedef struct settingMinMaxConfig_s
{
53 const uint8_t indexes
[SETTING_MIN_MAX_INDEX_BYTES
];
54 } settingMinMaxConfig_t
;
56 typedef struct settingLookupTableConfig_s
{
57 const uint8_t tableIndex
;
58 } settingLookupTableConfig_t
;
61 settingLookupTableConfig_t lookup
;
62 settingMinMaxConfig_t minmax
;
66 const uint8_t encoded_name
[SETTING_ENCODED_NAME_MAX_BYTES
];
67 const uint8_t type
; // see settingFlag_e
68 const settingConfig_t config
;
69 const setting_offset_t offset
;
71 } __attribute__((packed
)) setting_t
;
73 static inline setting_type_e
SETTING_TYPE(const setting_t
*s
) { return (setting_type_e
)(s
->type
& SETTING_TYPE_MASK
); }
74 static inline setting_section_e
SETTING_SECTION(const setting_t
*s
) { return (setting_section_e
)(s
->type
& SETTING_SECTION_MASK
); }
75 static inline setting_mode_e
SETTING_MODE(const setting_t
*s
) { return (setting_mode_e
)(s
->type
& SETTING_MODE_MASK
); }
77 void settingGetName(const setting_t
*val
, char *buf
);
78 bool settingNameContains(const setting_t
*val
, char *buf
, const char *cmdline
);
79 bool settingNameIsExactMatch(const setting_t
*val
, char *buf
, const char *cmdline
, uint8_t var_name_length
);
80 // Returns a setting_t with the exact name (case sensitive), or
81 // NULL if no setting with that name exists.
82 const setting_t
*settingFind(const char *name
);
83 // Returns the setting at the given index, or NULL if
84 // the index is greater than the total count.
85 const setting_t
*settingGet(unsigned index
);
86 // Returns the setting index for the given setting.
87 unsigned settingGetIndex(const setting_t
*val
);
88 // Checks if all settings have values in their valid ranges.
89 // If they don't, invalidIndex is filled with the first invalid
90 // settings index and false is returned.
91 bool settingsValidate(unsigned *invalidIndex
);
92 // Returns the size in bytes of the setting value.
93 size_t settingGetValueSize(const setting_t
*val
);
94 pgn_t
settingGetPgn(const setting_t
*val
);
95 // Returns a pointer to the actual value stored by
96 // the setting_t. The returned value might be modified.
97 void * settingGetValuePointer(const setting_t
*val
);
98 // Returns a pointer to the backed up copy of the value. Note that
99 // this will contain random garbage unless a copy of the parameter
100 // group for the value has been manually performed. Currently, this
101 // is only used by cli.c during config dumps.
102 const void * settingGetCopyValuePointer(const setting_t
*val
);
103 // Returns the minimum valid value for the given setting_t. setting_min_t
104 // depends on the target and build options, but will always be a signed
105 // integer (e.g. intxx_t,)
106 setting_min_t
settingGetMin(const setting_t
*val
);
107 // Returns the maximum valid value for the given setting_t. setting_max_t
108 // depends on the target and build options, but will always be an unsigned
109 // integer (e.g. uintxx_t,)
110 setting_max_t
settingGetMax(const setting_t
*val
);
111 // Returns the lookup table for the given setting. If the setting mode
112 // is not MODE_LOOKUP, it returns NULL;
113 const lookupTableEntry_t
* settingLookupTable(const setting_t
*val
);
114 // Returns the string in the table which corresponds to the value v
115 // for the given setting. If the setting mode is not MODE_LOOKUP or
116 // if the value is out of range, it returns NULL.
117 const char * settingLookupValueName(const setting_t
*val
, unsigned v
);
118 // Returns the length of the longest value name for the given setting,
119 // or 0 if the setting does not use value names.
120 size_t settingGetValueNameMaxSize(const setting_t
*val
);
121 // Returns the setting value as a const char * iff the setting is of type
122 // VAR_STRING. Otherwise it returns NULL.
123 const char * settingGetString(const setting_t
*val
);
124 // Sets the value for the given string setting. Size indicates the number of
125 // bytes in the string without the '\0' terminator (i.e. its strlen()).
126 // If the setting is not of type VAR_STRING, this function does nothing.
127 void settingSetString(const setting_t
*val
, const char *s
, size_t size
);
128 // Returns the max string length (without counting the '\0' terminator)
129 // for setting of type VAR_STRING. Otherwise it returns 0.
130 setting_max_t
settingGetStringMaxLength(const setting_t
*val
);
132 // Retrieve the setting indexes for the given PG. If the PG is not
133 // found, these function returns false.
134 bool settingsGetParameterGroupIndexes(pgn_t pg
, uint16_t *start
, uint16_t *end
);