-
-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathboardjson.h
More file actions
286 lines (238 loc) · 10.8 KB
/
Copy pathboardjson.h
File metadata and controls
286 lines (238 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "boards.h"
#include <QtCore>
#include <string>
#include <vector>
using namespace Board;
class BoardJson
{
Q_DECLARE_TR_FUNCTIONS(BoardJson)
public:
enum YamlLookupType {
YLT_CONFIG,
YLT_REF
};
struct InputDefn {
Board::AnalogInputType type = AIT_NONE;
std::string tag = "";
std::string name = "";
std::string shortName = "";
Board::FlexType flexType = FLEX_NONE;
bool inverted = false;
Board::LookupValueType cfgYaml = Board::LVT_TAG;
Board::LookupValueType refYaml = Board::LVT_TAG;
InputDefn() = default;
};
typedef std::vector<InputDefn> InputsTable;
struct Display {
unsigned int x = 0;
unsigned int y = 0;
};
struct SwitchDefn {
std::string tag = "";
Board::SwitchType type = Board::SWITCH_NOT_AVAILABLE;
std::string name = "";
int flags = 0;
bool inverted = false;
Board::SwitchType dflt = Board::SWITCH_NOT_AVAILABLE;
Display display;
bool isCustomSwitch = false;
int customSwitchIdx = -1;
Board::LookupValueType cfgYaml = Board::LVT_TAG;
Board::LookupValueType refYaml = Board::LVT_NAME;
SwitchDefn() = default;
};
typedef std::vector<SwitchDefn> SwitchesTable;
struct KeyDefn {
std::string tag = "";
std::string name = "";
std::string key = "";
std::string label = "";
Board::LookupValueType cfgYaml = Board::LVT_TAG;
Board::LookupValueType refYaml = Board::LVT_NAME;
KeyDefn() = default;
};
typedef std::vector<KeyDefn> KeysTable;
struct TrimDefn {
std::string tag = "";
std::string name = "";
Board::LookupValueType cfgYaml = Board::LVT_TAG;
Board::LookupValueType refYaml = Board::LVT_NAME;
TrimDefn() = default;
};
struct DisplayDefn {
int w = 0;
int h = 0;
int phys_w = 0;
int phys_h = 0;
int depth = 0;
int color = 0;
int oled = 0;
int backlight_color = 0;
};
struct CustomSwitchesDefn {
int rgb_led = 0;
int groups = 0;
};
struct HardwareDefn {
int has_audio_mute = 0;
int has_bling_leds = 0;
int has_ext_module_support = 0;
int has_int_module_support = 0;
int sport_max_baudrate = 0;
int surface = 0;
std::string cpu = "";
std::string cpu_type = "";
};
typedef std::vector<TrimDefn> TrimsTable;
explicit BoardJson(Board::Type board, QString hwdefn);
virtual ~BoardJson();
Board::Type board() const { return m_board; }
QString hwdefn() const { return m_hwdefn; }
bool loadDefinition();
const int getCapability(const Board::Capability capability) const;
const QString getCapabilityStr(const Board::Capability capability) const;
const int getInputsCalibrated() const;
const int getInputIndex(const QString val, Board::LookupValueType lvt) const;
const Board::InputInfo getInputInfo(int index) const;
const QString getInputName(int index) const;
const int getInputExtIndex(int index);
const int getInputPotIndex(int index);
const int getInputSliderIndex(int index);
const QString getInputTag(int index) const;
const int getInputTagOffset(QString tag);
const int getInputThrottleIndex();
const int getInputTypeOffset(Board::AnalogInputType type);
const int getInputYamlIndex(const QString val, YamlLookupType ylt) const;
const QString getInputYamlName(int index, YamlLookupType ylt) const;
const bool isInputAvailable(int index) const;
const bool isInputCalibrated(int index) const;
const bool isInputConfigurable(int index) const;
const bool isInputIgnored(int index) const;
const bool isInputFlexGyroAxis(int index) const;
const bool isInputFlexJoystickAxis(int index) const;
const bool isInputFlexPot(int index) const;
const bool isInputFlexSwitch(int index) const;
const bool isInputStick(int index) const;
const bool isInputSwitch(int index) const;
const Board::KeyInfo getKeyInfo(int index) const;
const int getKeyIndex(const QString key) const;
bool hasKeyLockCombo() const { return m_hasKeyLockCombo; }
const int getSwitchIndex(const QString val, Board::LookupValueType lvt) const;
const int getCFSIndexForSwitch(int sw) const;
const int getSwitchIndexForCFS(int customSwitchIdx) const;
const int getSwitchIndexForCFSOffset(int offset) const;
const int getCFSOffsetForCFSIndex(int index) const;
const Board::SwitchInfo getSwitchInfo(int index) const;
const QString getSwitchName(int index) const;
const QString getSwitchTag(int index) const;
const int getSwitchTagNum(int index) const;
const int getSwitchTypeOffset(Board::SwitchType type);
const int getSwitchYamlIndex(const QString val, YamlLookupType ylt) const;
const QString getSwitchYamlName(int index, YamlLookupType ylt) const;
const int getTrimIndex(const QString val, Board::LookupValueType lvt) const;
const QString getTrimName(int index) const;
const QString getTrimTag(int index) const;
const int getTrimYamlIndex(const QString val, YamlLookupType ylt) const;
const QString getTrimYamlName(int index, YamlLookupType ylt) const;
const bool isSwitchConfigurable(int index) const;
const bool isSwitchFlex(int index) const;
const bool isSwitchFunc(int index) const;
private:
Board::Type m_board;
QString m_hwdefn;
InputsTable *m_inputs;
SwitchesTable *m_switches;
TrimsTable *m_trims;
KeysTable *m_keys;
DisplayDefn m_display;
CustomSwitchesDefn m_cfs;
HardwareDefn m_hardware;
bool m_hasKeyLockCombo = false;
struct InputCounts {
unsigned int flexGyroAxes;
unsigned int flexJoystickAxes;
unsigned int flexPots;
unsigned int flexSliders;
unsigned int flexSwitches;
unsigned int rtcbat;
unsigned int sticks;
unsigned int switches;
unsigned int vbat;
};
InputCounts m_inputCnt;
struct SwitchCounts {
unsigned int std;
unsigned int flex;
unsigned int func;
};
SwitchCounts m_switchCnt;
static bool loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims, DisplayDefn & lcd, CustomSwitchesDefn & cfs,
HardwareDefn & hardware, bool & hasKeyLockCombo);
static void afterLoadFixups(Board::Type board, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims);
static int getInputsCalibrated(const InputsTable * inputs);
static int getInputIndex(const InputsTable * inputs, QString val, Board::LookupValueType lvt);
static Board::InputInfo getInputInfo(const InputsTable * inputs, int index);
static QString getInputName(const InputsTable * inputs, int index);
static QString getInputTag(const InputsTable * inputs, int index);
static int getInputTagOffset(const InputsTable * inputs, QString tag);
static int getInputTypeOffset(const InputsTable * inputs, Board::AnalogInputType type);
static int getKeyIndex(const KeysTable * keys, QString key);
static Board::KeyInfo getKeyInfo(const KeysTable * keys, int index);
static int getSwitchIndex(const SwitchesTable * switches, QString val, Board::LookupValueType lvt);
static int getCFSIndexForSwitch(const SwitchesTable * switches, int sw);
static int getSwitchIndexForCFS(const SwitchesTable * switches, int customSwitchIdx);
static int getSwitchIndexForCFSOffset(const SwitchesTable * switches, int offset);
static int getCFSOffsetForCFSIndex(const SwitchesTable * switches, int index);
static Board::SwitchInfo getSwitchInfo(const SwitchesTable * switches, int index);
static QString getSwitchName(const SwitchesTable * switches, int index);
static QString getSwitchTag(const SwitchesTable * switches, int index);
static int getSwitchTagNum(const SwitchesTable * switches, int index);
static int getSwitchTypeOffset(const SwitchesTable * switches, Board::SwitchType type);
static int getTrimIndex(const TrimsTable * trims, QString val, Board::LookupValueType lvt);
static QString getTrimName(const TrimsTable * trims, int index);
static QString getTrimTag(const TrimsTable * trims, int index);
static bool isInputAvailable(const InputDefn & defn);
static bool isInputCalibrated(const InputDefn & defn);
static bool isInputConfigurable(const InputDefn & defn);
static bool isInputFlex(const InputDefn & defn);
static bool isInputFlexGyroAxis(const InputDefn & defn);
static bool isInputFlexJoystickAxis(const InputDefn & defn);
static bool isInputFlexPot(const InputDefn & defn);
static bool isInputFlexPotMultipos(const InputDefn & defn);
static bool isInputFlexSlider(const InputDefn & defn);
static bool isInputFlexSwitch(const InputDefn & defn);
static bool isInputIgnored(const InputDefn & defn);
static bool isInputRTCBat(const InputDefn & defn);
static bool isInputStick(const InputDefn & defn);
static bool isInputSwitch(const InputDefn & defn);
static bool isInputVBat(const InputDefn & defn);
static bool isSwitchStd(const SwitchDefn & defn);
static bool isSwitchFlex(const SwitchDefn & defn);
static bool isSwitchFunc(const SwitchDefn & defn);
static void setInputCounts(const InputsTable * inputs, InputCounts & inputCounts);
static void setSwitchCounts(const SwitchesTable * switches, SwitchCounts & switchCounts);
static int getNumericSuffix(const std::string str);
};