X10 fixes (#5221)
[opentx.git] / companion / src / boards.cpp
blob2214e4c1dd0de792cba2ce3a2fd6cd7f9c59503d
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_FLAMENCO:
103 return FSIZE_TARANIS;
104 case BOARD_X12S:
105 case BOARD_X10:
106 return FSIZE_HORUS;
107 case BOARD_UNKNOWN:
108 return FSIZE_MAX;
109 default:
110 return 0;
114 const SwitchInfo Boards::getSwitchInfo(Board::Type board, unsigned index)
116 if (IS_TARANIS_X7(board)) {
117 const Board::SwitchInfo switches[] = {
118 {SWITCH_3POS, "SA"},
119 {SWITCH_3POS, "SB"},
120 {SWITCH_3POS, "SC"},
121 {SWITCH_3POS, "SD"},
122 {SWITCH_2POS, "SF"},
123 {SWITCH_TOGGLE, "SH"}
125 if (index < DIM(switches))
126 return switches[index];
128 else if (IS_HORUS_OR_TARANIS(board)) {
129 const Board::SwitchInfo switches[] = {
130 {SWITCH_3POS, "SA"},
131 {SWITCH_3POS, "SB"},
132 {SWITCH_3POS, "SC"},
133 {SWITCH_3POS, "SD"},
134 {SWITCH_3POS, "SE"},
135 {SWITCH_2POS, "SF"},
136 {SWITCH_3POS, "SG"},
137 {SWITCH_TOGGLE, "SH"},
138 {SWITCH_3POS, "SI"},
139 {SWITCH_3POS, "SJ"},
140 {SWITCH_3POS, "SK"},
141 {SWITCH_3POS, "SL"},
142 {SWITCH_3POS, "SM"},
143 {SWITCH_3POS, "SN"},
144 {SWITCH_3POS, "SO"},
145 {SWITCH_3POS, "SP"},
146 {SWITCH_3POS, "SQ"},
147 {SWITCH_3POS, "SR"}
149 if (index < DIM(switches))
150 return switches[index];
152 else {
153 const Board::SwitchInfo switches[] = {
154 {SWITCH_2POS, "THR"},
155 {SWITCH_2POS, "RUD"},
156 {SWITCH_2POS, "ELE"},
157 {SWITCH_3POS, "3POS"},
158 {SWITCH_2POS, "AIL"},
159 {SWITCH_2POS, "GEA"},
160 {SWITCH_TOGGLE, "TRN"}
162 if (index < DIM(switches))
163 return switches[index];
166 return {SWITCH_NOT_AVAILABLE, "???"};
169 const int Boards::getCapability(Board::Type board, Board::Capability capability)
171 switch (capability) {
172 case Sticks:
173 return 4;
174 case Pots:
175 if (IS_HORUS(board))
176 return 3;
177 else if (IS_TARANIS_X7(board))
178 return 2;
179 else if (IS_TARANIS_X9E(board))
180 return 4;
181 else if (IS_TARANIS(board))
182 return 3;
183 else
184 return 3;
185 case Sliders:
186 if (IS_HORUS(board))
187 return 4;
188 else if (IS_TARANIS_X7(board))
189 return 0;
190 else if (IS_TARANIS_X9E(board))
191 return 4;
192 else if (IS_TARANIS(board))
193 return 2;
194 else
195 return 0;
196 case MouseAnalogs:
197 if (IS_HORUS(board))
198 return 2;
199 else
200 return 0;
201 case FactoryInstalledSwitches:
202 if (IS_TARANIS_X9E(board))
203 return 8;
204 // no break
205 case Switches:
206 if (IS_TARANIS_X9E(board))
207 return 18;
208 else if (IS_TARANIS_X7(board))
209 return 6;
210 else if (IS_HORUS_OR_TARANIS(board))
211 return 8;
212 else
213 return 7;
214 case SwitchPositions:
215 if (IS_HORUS_OR_TARANIS(board))
216 return getCapability(board, Switches) * 3;
217 else
218 return 9;
219 case NumTrims:
220 if (IS_HORUS(board))
221 return 6;
222 else
223 return 4;
224 case NumTrimSwitches:
225 return getCapability(board, NumTrims) * 2;
228 return 0;
231 const QString Boards::getAxisName(int index)
233 const QString axes[] = {
234 QObject::tr("Left Horizontal"),
235 QObject::tr("Left Vertical"),
236 QObject::tr("Right Vertical"),
237 QObject::tr("Right Horizontal"),
238 QObject::tr("Aux. 1"),
239 QObject::tr("Aux. 2"),
241 if (index < (int)DIM(axes))
242 return axes[index];
243 else
244 return QObject::tr("Unknown");
247 /* Currently unused
249 const QString Boards::getBoardName(Board::Type board)
251 switch (board) {
252 case BOARD_STOCK:
253 return "9X";
254 case BOARD_M128:
255 return "9X128";
256 case BOARD_GRUVIN9X:
257 return "Gruvin9x";
258 case BOARD_MEGA2560:
259 return "MEGA2560";
260 case BOARD_TARANIS_X7:
261 return "Taranis X7";
262 case BOARD_TARANIS_X9D:
263 return "Taranis X9D";
264 case BOARD_TARANIS_X9DP:
265 return "Taranis X9D+";
266 case BOARD_TARANIS_X9E:
267 return "Taranis X9E";
268 case BOARD_SKY9X:
269 return "Sky9x";
270 case BOARD_9XRPRO:
271 return "9XR-PRO";
272 case BOARD_AR9X:
273 return "AR9X";
274 case BOARD_X12S:
275 return "Horus";
276 case BOARD_X10:
277 return "X10";
278 default:
279 return QObject::tr("Unknown");