[companion] Adjust GVAR not possible in global functions (fix #5425)
[opentx.git] / companion / src / boards.cpp
blobee539b099c9768dfd72b09ba503db12f1b46b501
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "boards.h"
22 #include "macros.h"
24 // TODO remove all those constants
25 // Update: These are now all only used within this class.
26 // External access is only via getEEpromSize() and getFlashSize()
28 #define EESIZE_STOCK 2048
29 #define EESIZE_M128 4096
30 #define EESIZE_GRUVIN9X 4096
31 #define EESIZE_TARANIS (32*1024)
32 #define EESIZE_SKY9X (128*4096)
33 #define EESIZE_9XRPRO (128*4096)
34 #define EESIZE_MAX EESIZE_9XRPRO
36 // getFlashSize() (and these macros) is only used by radiointerface::getDfuArgs (perhaps can find a better way?)
37 #define FSIZE_STOCK (64*1024)
38 #define FSIZE_M128 (128*1024)
39 #define FSIZE_GRUVIN9X (256*1024)
40 #define FSIZE_TARANIS (512*1024)
41 #define FSIZE_SKY9X (256*1024)
42 #define FSIZE_9XRPRO (512*1024)
43 #define FSIZE_HORUS (2048*1024)
44 #define FSIZE_MAX FSIZE_HORUS
46 using namespace Board;
48 void Boards::setBoardType(const Type & board)
50 if (board >= BOARD_UNKNOWN && board < BOARD_ENUM_COUNT)
51 m_boardType = board;
52 else
53 m_boardType = BOARD_UNKNOWN;
56 const int Boards::getEEpromSize(Board::Type board)
58 switch (board) {
59 case BOARD_STOCK:
60 return EESIZE_STOCK;
61 case BOARD_M128:
62 return EESIZE_M128;
63 case BOARD_MEGA2560:
64 case BOARD_GRUVIN9X:
65 return EESIZE_GRUVIN9X;
66 case BOARD_SKY9X:
67 return EESIZE_SKY9X;
68 case BOARD_9XRPRO:
69 case BOARD_AR9X:
70 return EESIZE_9XRPRO;
71 case BOARD_TARANIS_X7:
72 case BOARD_TARANIS_X9D:
73 case BOARD_TARANIS_X9DP:
74 case BOARD_TARANIS_X9E:
75 case BOARD_FLAMENCO:
76 return EESIZE_TARANIS;
77 case BOARD_UNKNOWN:
78 return EESIZE_MAX;
79 default:
80 return 0; // unlimited
84 const int Boards::getFlashSize(Type board)
86 switch (board) {
87 case BOARD_STOCK:
88 return FSIZE_STOCK;
89 case BOARD_M128:
90 return FSIZE_M128;
91 case BOARD_MEGA2560:
92 case BOARD_GRUVIN9X:
93 return FSIZE_GRUVIN9X;
94 case BOARD_SKY9X:
95 return FSIZE_SKY9X;
96 case BOARD_9XRPRO:
97 case BOARD_AR9X:
98 return FSIZE_9XRPRO;
99 case BOARD_TARANIS_X9D:
100 case BOARD_TARANIS_X9DP:
101 case BOARD_TARANIS_X9E:
102 case BOARD_TARANIS_X7:
103 case BOARD_FLAMENCO:
104 return FSIZE_TARANIS;
105 case BOARD_X12S:
106 case BOARD_X10:
107 return FSIZE_HORUS;
108 case BOARD_UNKNOWN:
109 return FSIZE_MAX;
110 default:
111 return 0;
115 const SwitchInfo Boards::getSwitchInfo(Board::Type board, unsigned index)
117 if (IS_TARANIS_X7(board)) {
118 const Board::SwitchInfo switches[] = {
119 {SWITCH_3POS, "SA"},
120 {SWITCH_3POS, "SB"},
121 {SWITCH_3POS, "SC"},
122 {SWITCH_3POS, "SD"},
123 {SWITCH_2POS, "SF"},
124 {SWITCH_TOGGLE, "SH"}
126 if (index < DIM(switches))
127 return switches[index];
129 else if (IS_HORUS_OR_TARANIS(board)) {
130 const Board::SwitchInfo switches[] = {
131 {SWITCH_3POS, "SA"},
132 {SWITCH_3POS, "SB"},
133 {SWITCH_3POS, "SC"},
134 {SWITCH_3POS, "SD"},
135 {SWITCH_3POS, "SE"},
136 {SWITCH_2POS, "SF"},
137 {SWITCH_3POS, "SG"},
138 {SWITCH_TOGGLE, "SH"},
139 {SWITCH_3POS, "SI"},
140 {SWITCH_3POS, "SJ"},
141 {SWITCH_3POS, "SK"},
142 {SWITCH_3POS, "SL"},
143 {SWITCH_3POS, "SM"},
144 {SWITCH_3POS, "SN"},
145 {SWITCH_3POS, "SO"},
146 {SWITCH_3POS, "SP"},
147 {SWITCH_3POS, "SQ"},
148 {SWITCH_3POS, "SR"}
150 if (index < DIM(switches))
151 return switches[index];
153 else {
154 const Board::SwitchInfo switches[] = {
155 {SWITCH_3POS, "3POS"},
156 {SWITCH_2POS, "THR"},
157 {SWITCH_2POS, "RUD"},
158 {SWITCH_2POS, "ELE"},
159 {SWITCH_2POS, "AIL"},
160 {SWITCH_2POS, "GEA"},
161 {SWITCH_TOGGLE, "TRN"}
163 if (index < DIM(switches))
164 return switches[index];
167 return {SWITCH_NOT_AVAILABLE, "???"};
170 const int Boards::getCapability(Board::Type board, Board::Capability capability)
172 switch (capability) {
173 case Sticks:
174 return 4;
175 case Pots:
176 if (IS_HORUS(board))
177 return 3;
178 else if (IS_TARANIS_X7(board))
179 return 2;
180 else if (IS_TARANIS_X9E(board))
181 return 4;
182 else if (IS_TARANIS(board))
183 return 3;
184 else
185 return 3;
186 case Sliders:
187 if (IS_HORUS(board))
188 return 4;
189 else if (IS_TARANIS_X7(board))
190 return 0;
191 else if (IS_TARANIS_X9E(board))
192 return 4;
193 else if (IS_TARANIS(board))
194 return 2;
195 else
196 return 0;
197 case MouseAnalogs:
198 if (IS_HORUS(board))
199 return 2;
200 else
201 return 0;
202 case FactoryInstalledSwitches:
203 if (IS_TARANIS_X9E(board))
204 return 8;
205 // no break
206 case Switches:
207 if (IS_TARANIS_X9E(board))
208 return 18;
209 else if (IS_TARANIS_X7(board))
210 return 6;
211 else if (IS_HORUS_OR_TARANIS(board))
212 return 8;
213 else
214 return 7;
215 case SwitchPositions:
216 if (IS_HORUS_OR_TARANIS(board))
217 return getCapability(board, Switches) * 3;
218 else
219 return 9;
220 case NumTrims:
221 if (IS_HORUS(board))
222 return 6;
223 else
224 return 4;
225 case NumTrimSwitches:
226 return getCapability(board, NumTrims) * 2;
229 return 0;
232 const QString Boards::getAxisName(int index)
234 const QString axes[] = {
235 QObject::tr("Left Horizontal"),
236 QObject::tr("Left Vertical"),
237 QObject::tr("Right Vertical"),
238 QObject::tr("Right Horizontal"),
239 QObject::tr("Aux. 1"),
240 QObject::tr("Aux. 2"),
242 if (index < (int)DIM(axes))
243 return axes[index];
244 else
245 return QObject::tr("Unknown");
248 /* Currently unused
250 const QString Boards::getBoardName(Board::Type board)
252 switch (board) {
253 case BOARD_STOCK:
254 return "9X";
255 case BOARD_M128:
256 return "9X128";
257 case BOARD_GRUVIN9X:
258 return "Gruvin9x";
259 case BOARD_MEGA2560:
260 return "MEGA2560";
261 case BOARD_TARANIS_X7:
262 return "Taranis X7";
263 case BOARD_TARANIS_X9D:
264 return "Taranis X9D";
265 case BOARD_TARANIS_X9DP:
266 return "Taranis X9D+";
267 case BOARD_TARANIS_X9E:
268 return "Taranis X9E";
269 case BOARD_SKY9X:
270 return "Sky9x";
271 case BOARD_9XRPRO:
272 return "9XR-PRO";
273 case BOARD_AR9X:
274 return "AR9X";
275 case BOARD_X12S:
276 return "Horus";
277 case BOARD_X10:
278 return "X10";
279 default:
280 return QObject::tr("Unknown");