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 "radiodata.h"
22 #include "eeprominterface.h"
24 // TODO here we will move a lot of functions from eeprominterface.cpp when no merge risk
26 RawSource
RawSource::convert(Board::Type before
, Board::Type after
)
28 if (type
== SOURCE_TYPE_STICK
&& index
>= 4 + getBoardCapability(before
, Board::Pots
)) {
29 // 1st slider alignment
30 index
+= getBoardCapability(after
, Board::Pots
) - getBoardCapability(before
, Board::Pots
);
33 if (IS_HORUS(after
)) {
34 if (IS_TARANIS_X9D(before
) || IS_TARANIS_X7(before
)) {
35 if (type
== SOURCE_TYPE_STICK
&& index
>= 7) {
36 // LS and RS on Horus are after sliders L1 and L2
42 // SWI to SWR don't exist on !X9E board
43 if (!IS_TARANIS_X9E(after
) && IS_TARANIS_X9E(before
)) {
44 if (type
== SOURCE_TYPE_SWITCH
&& index
>= 8) {
49 // No SE and SG on X7 board
50 if (IS_TARANIS_X7(after
)) {
51 if (IS_TARANIS_X9(before
) || IS_HORUS(before
)) {
52 if (type
== SOURCE_TYPE_SWITCH
&& index
>= 6) {
55 else if (type
== SOURCE_TYPE_SWITCH
&& index
>= 4) {
64 RawSwitch
RawSwitch::convert(Board::Type before
, Board::Type after
)
66 // SWI to SWR don't exist on !X9E board
67 if (!IS_TARANIS_X9E(after
) && IS_TARANIS_X9E(before
)) {
68 if (type
== SWITCH_TYPE_SWITCH
&& index
>= 24) {
73 // No SE and SG on X7 board
74 if (IS_TARANIS_X7(after
)) {
75 if (IS_TARANIS_X9(before
) || IS_HORUS(before
)) {
76 if (type
== SWITCH_TYPE_SWITCH
&& index
>= 18) {
79 else if (type
== SWITCH_TYPE_SWITCH
&& index
>= 15) {
88 void ExpoData::convert(Board::Type before
, Board::Type after
)
90 swtch
.convert(before
, after
);
93 void MixData::convert(Board::Type before
, Board::Type after
)
95 srcRaw
.convert(before
, after
);
96 swtch
.convert(before
, after
);
99 void LogicalSwitchData::convert(Board::Type before
, Board::Type after
)
101 CSFunctionFamily family
= getFunctionFamily();
104 val1
= RawSource(val1
).convert(before
, after
).toValue();
106 case LS_FAMILY_STICKY
:
107 case LS_FAMILY_VBOOL
:
108 val1
= RawSwitch(val1
).convert(before
, after
).toValue();
109 val2
= RawSwitch(val2
).convert(before
, after
).toValue();
112 val1
= RawSwitch(val1
).convert(before
, after
).toValue();
114 case LS_FAMILY_VCOMP
:
115 val1
= RawSource(val1
).convert(before
, after
).toValue();
116 val2
= RawSource(val2
).convert(before
, after
).toValue();
122 andsw
= RawSwitch(andsw
).convert(before
, after
).toValue();
125 void CustomFunctionData::convert(Board::Type before
, Board::Type after
)
127 swtch
.convert(before
, after
);
130 void FlightModeData::convert(Board::Type before
, Board::Type after
)
132 swtch
.convert(before
, after
);
135 void ModelData::convert(Board::Type before
, Board::Type after
)
137 // Here we can add explicit conversions when moving from one board to another
138 for (int i
=0; i
<CPN_MAX_MIXERS
; i
++) {
139 mixData
[i
].convert(before
, after
);
142 for (int i
=0; i
<CPN_MAX_EXPOS
; i
++) {
143 expoData
[i
].convert(before
, after
);
146 for (int i
=0; i
<CPN_MAX_LOGICAL_SWITCHES
; i
++) {
147 logicalSw
[i
].convert(before
, after
);
150 for (int i
=0; i
<CPN_MAX_SPECIAL_FUNCTIONS
; i
++) {
151 customFn
[i
].convert(before
, after
);
154 for (int i
=0; i
<CPN_MAX_FLIGHT_MODES
; i
++) {
155 flightModeData
[i
].convert(before
, after
);
159 void GeneralSettings::convert(Board::Type before
, Board::Type after
)
161 // Here we can add explicit conversions when moving from one board to another
163 // No SE and SG on X7 board
164 if (IS_TARANIS_X7(after
)) {
165 if (IS_TARANIS_X9(before
) || IS_HORUS(before
)) {
166 switchConfig
[4] = switchConfig
[5];
167 memcpy(switchName
[4], switchName
[5], sizeof(switchName
[4]));
168 switchConfig
[5] = switchConfig
[7];
169 memcpy(switchName
[5], switchName
[7], sizeof(switchName
[5]));
179 RadioData::RadioData()
181 models
.resize(getCurrentFirmware()->getCapability(Models
));
184 void RadioData::setCurrentModel(unsigned int index
)
186 generalSettings
.currModelIndex
= index
;
187 if (index
< models
.size()) {
188 strcpy(generalSettings
.currModelFilename
, models
[index
].filename
);
192 void RadioData::fixModelFilename(unsigned int index
)
194 ModelData
& model
= models
[index
];
195 QString
filename(model
.filename
);
196 bool ok
= filename
.endsWith(".bin");
198 if (filename
.startsWith("model") && filename
.mid(5, filename
.length()-9).toInt() > 0) {
203 for (unsigned i
=0; i
<index
; i
++) {
204 if (strcmp(models
[i
].filename
, model
.filename
) == 0) {
211 sprintf(model
.filename
, "model%d.bin", index
+1);
215 void RadioData::fixModelFilenames()
217 for (unsigned int i
=0; i
<models
.size(); i
++) {
220 setCurrentModel(generalSettings
.currModelIndex
);
223 QString
RadioData::getNextModelFilename()
225 char filename
[sizeof(ModelData::filename
)];
229 sprintf(filename
, "model%d.bin", ++index
);
231 for (unsigned int i
=0; i
<models
.size(); i
++) {
232 if (strcmp(filename
, models
[i
].filename
) == 0) {
241 void RadioData::convert(Board::Type before
, Board::Type after
)
243 generalSettings
.convert(before
, after
);
244 for (unsigned i
=0; i
<models
.size(); i
++) {
245 models
[i
].convert(before
, after
);
247 if (categories
.size() == 0) {
248 categories
.push_back(CategoryData(qPrintable(QObject::tr("Models"))));
249 for (unsigned i
=0; i
<models
.size(); i
++) {
250 models
[i
].category
= 0;
254 if (IS_HORUS(after
)) {