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