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 "customfunctiondata.h"
23 #include "eeprominterface.h"
24 #include "radiodata.h"
25 #include "radiodataconversionstate.h"
27 void CustomFunctionData::clear()
29 memset(this, 0, sizeof(CustomFunctionData
));
30 if (!getCurrentFirmware()->getCapability(SafetyChannelCustomFunction
)) {
35 bool CustomFunctionData::isEmpty() const
37 return (swtch
.type
== SWITCH_TYPE_NONE
);
40 QString
CustomFunctionData::nameToString(int index
, bool globalContext
) const
42 return RadioData::getElementName((globalContext
? tr("GF") : tr("SF")), index
+1, 0, true);
45 QString
CustomFunctionData::funcToString(const ModelData
* model
) const
47 if (func
>= FuncOverrideCH1
&& func
<= FuncOverrideCH32
)
48 return tr("Override %1").arg(RawSource(SOURCE_TYPE_CH
, func
).toString(model
));
49 else if (func
== FuncTrainer
)
51 else if (func
== FuncTrainerRUD
)
52 return tr("Trainer RUD");
53 else if (func
== FuncTrainerELE
)
54 return tr("Trainer ELE");
55 else if (func
== FuncTrainerTHR
)
56 return tr("Trainer THR");
57 else if (func
== FuncTrainerAIL
)
58 return tr("Trainer AIL");
59 else if (func
== FuncInstantTrim
)
60 return tr("Instant Trim");
61 else if (func
== FuncPlaySound
)
62 return tr("Play Sound");
63 else if (func
== FuncPlayHaptic
)
65 else if (func
== FuncReset
)
67 else if (func
>= FuncSetTimer1
&& func
<= FuncSetTimer3
)
68 return tr("Set Timer %1").arg(func
-FuncSetTimer1
+1);
69 else if (func
== FuncVario
)
71 else if (func
== FuncPlayPrompt
)
72 return tr("Play Track");
73 else if (func
== FuncPlayBoth
)
74 return tr("Play Both");
75 else if (func
== FuncPlayValue
)
76 return tr("Play Value");
77 else if (func
== FuncPlayScript
)
78 return tr("Play Script");
79 else if (func
== FuncLogs
)
81 else if (func
== FuncVolume
)
83 else if (func
== FuncBacklight
)
84 return tr("Backlight");
85 else if (func
== FuncScreenshot
)
86 return tr("Screenshot");
87 else if (func
== FuncBackgroundMusic
)
88 return tr("Background Music");
89 else if (func
== FuncBackgroundMusicPause
)
90 return tr("Background Music Pause");
91 else if (func
>= FuncAdjustGV1
&& func
<= FuncAdjustGVLast
)
92 return tr("Adjust %1").arg(RawSource(SOURCE_TYPE_GVAR
, func
-FuncAdjustGV1
).toString(model
));
93 else if (func
== FuncSetFailsafeInternalModule
)
94 return tr("SetFailsafe Int. Module");
95 else if (func
== FuncSetFailsafeExternalModule
)
96 return tr("SetFailsafe Ext. Module");
97 else if (func
== FuncRangeCheckInternalModule
)
98 return tr("RangeCheck Int. Module");
99 else if (func
== FuncRangeCheckExternalModule
)
100 return tr("RangeCheck Ext. Module");
101 else if (func
== FuncBindInternalModule
)
102 return tr("Bind Int. Module");
103 else if (func
== FuncBindExternalModule
)
104 return tr("Bind Ext. Module");
106 return QString("???"); // Highlight unknown functions with output of question marks.(BTW should not happen that we do not know what a function is)
110 void CustomFunctionData::populateResetParams(const ModelData
* model
, QComboBox
* b
, unsigned int value
= 0)
113 Firmware
* firmware
= Firmware::getCurrentVariant();
114 Board::Type board
= firmware
->getBoard();
116 b
->addItem(tr("Timer1"), val
++);
117 b
->addItem(tr("Timer2"), val
++);
119 b
->addItem( tr("Timer3"), val
++);
121 b
->addItem(tr("Flight"), val
++);
122 b
->addItem(tr("Telemetry"), val
++);
123 int reCount
= firmware
->getCapability(RotaryEncoders
);
125 b
->addItem(tr("Rotary Encoder"), val
++);
127 else if (reCount
== 2) {
128 b
->addItem(tr("REa"), val
++);
129 b
->addItem(tr("REb"), val
++);
131 if ((int)value
< b
->count()) {
132 b
->setCurrentIndex(value
);
134 if (model
&& IS_ARM(board
)) {
135 for (int i
=0; i
<CPN_MAX_SENSORS
; ++i
) {
136 if (model
->sensorData
[i
].isAvailable()) {
137 RawSource item
= RawSource(SOURCE_TYPE_TELEMETRY
, 3*i
);
138 b
->addItem(item
.toString(model
), val
+i
);
139 if ((int)value
== val
+i
) {
140 b
->setCurrentIndex(b
->count()-1);
147 void CustomFunctionData::populatePlaySoundParams(QStringList
& qs
)
149 qs
<<"Beep 1" << "Beep 2" << "Beep 3" << "Warn1" << "Warn2" << "Cheep" << "Ratata" << "Tick" << "Siren" << "Ring" ;
150 qs
<< "SciFi" << "Robot" << "Chirp" << "Tada" << "Crickt" << "AlmClk" ;
153 void CustomFunctionData::populateHapticParams(QStringList
& qs
)
155 qs
<< "0" << "1" << "2" << "3";
158 QString
CustomFunctionData::paramToString(const ModelData
* model
) const
161 if (func
<= FuncInstantTrim
) {
162 return QString("%1").arg(param
);
164 else if (func
==FuncLogs
) {
165 return QString("%1").arg(param
/10.0) + tr("s");
167 else if (func
==FuncPlaySound
) {
168 CustomFunctionData::populatePlaySoundParams(qs
);
169 if (param
>=0 && param
<(int)qs
.count())
172 return tr("<font color=red><b>Inconsistent parameter</b></font>");
174 else if (func
==FuncPlayHaptic
) {
175 CustomFunctionData::populateHapticParams(qs
);
176 if (param
>=0 && param
<(int)qs
.count())
179 return tr("<font color=red><b>Inconsistent parameter</b></font>");
181 else if (func
==FuncReset
) {
183 CustomFunctionData::populateResetParams(model
, &cb
);
184 int pos
= cb
.findData(param
);
186 return cb
.itemText(pos
);
188 return tr("<font color=red><b>Inconsistent parameter</b></font>");
190 else if ((func
==FuncVolume
)|| (func
==FuncPlayValue
)) {
191 RawSource
item(param
);
192 return item
.toString(model
);
194 else if ((func
==FuncPlayPrompt
) || (func
==FuncPlayBoth
)) {
195 if ( getCurrentFirmware()->getCapability(VoicesAsNumbers
)) {
196 return QString("%1").arg(param
);
202 else if ((func
>=FuncAdjustGV1
) && (func
<FuncCount
)) {
203 switch (adjustMode
) {
204 case FUNC_ADJUST_GVAR_CONSTANT
:
205 return tr("Value ")+QString("%1").arg(param
);
206 case FUNC_ADJUST_GVAR_SOURCE
:
207 case FUNC_ADJUST_GVAR_GVAR
:
208 return RawSource(param
).toString();
209 case FUNC_ADJUST_GVAR_INCDEC
:
210 if (param
==0) return tr("Decr:") + " -1";
211 else return tr("Incr:") + " +1";
217 QString
CustomFunctionData::repeatToString() const
219 if (repeatParam
== -1) {
220 return tr("played once, not during startup");
222 else if (repeatParam
== 0) {
226 unsigned int step
= IS_ARM(getCurrentBoard()) ? 1 : 10;
227 return tr("repeat(%1s)").arg(step
*repeatParam
);
231 QString
CustomFunctionData::enabledToString() const
233 if ((func
>=FuncOverrideCH1
&& func
<=FuncOverrideCH32
) ||
234 (func
>=FuncAdjustGV1
&& func
<=FuncAdjustGVLast
) ||
236 (func
>=FuncSetTimer1
&& func
<=FuncSetTimer2
) ||
237 (func
==FuncVolume
) ||
238 (func
<= FuncInstantTrim
)) {
240 return tr("DISABLED");
246 void CustomFunctionData::convert(RadioDataConversionState
& cstate
)
248 cstate
.setComponent(tr("CFN"), 8);
249 cstate
.setSubComp(nameToString(cstate
.subCompIdx
, (cstate
.toModel() ? false : true)));
250 swtch
.convert(cstate
);
251 if (func
== FuncVolume
|| func
== FuncPlayValue
|| (func
>= FuncAdjustGV1
&& func
<= FuncAdjustGVLast
&& adjustMode
== 1)) {
252 param
= RawSource(param
).convert(cstate
.withComponentField("PARAM")).toValue();