Update CREDITS.txt
[opentx.git] / companion / src / modeledit / templates.cpp
blob00c63d4f0261673330389648fb546b6171538a81
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 "templates.h"
23 #define CHANNEL_ORDER(x) generalSettings.getDefaultStick(x)
24 #define CC(x) (CHANNEL_ORDER(x)) //need to invert this to work with dest
25 // TODO ICC is GeneralSettings::getDefaultChannel(unsigned int stick)
27 void ModelEdit::setCurve(uint8_t c, int8_t ar[])
29 int len=sizeof(ar)/sizeof(int8_t);
31 if (firmware->getCapability(NumCurves)>c) {
32 if (len<9) {
33 model.curves[c].count=5;
34 model.curves[c].custom=false;
35 for (int i=0; i< 5; i++) {
36 model.curves[c].points[i].y=ar[i];
39 else {
40 model.curves[c].count=5;
41 model.curves[c].custom=false;
42 for (int i=0; i< 5; i++) {
43 model.curves[c].points[i].y=ar[i];
49 Templates::Templates(QWidget * parent, ModelData & model):
50 QWidget(parent),
51 model(model)
53 QGridLayout * gridLayout = new QGridLayout(this);
54 QListWidget * templateList = new QListWidget(this);
55 gridLayout->addWidget(templateList, 0, 0, 1, 1);
57 templateList->addItem(tr("Simple 4-CH"));
58 templateList->addItem(tr("T-Cut"));
59 templateList->addItem(tr("Sticky T-Cut"));
60 templateList->addItem(tr("V-Tail"));
61 templateList->addItem(tr("Elevon\\Delta"));
62 templateList->addItem(tr("Heli Setup"));
63 templateList->addItem(tr("Heli Setup with gyro gain control"));
64 templateList->addItem(tr("Gyro gain control"));
65 templateList->addItem(tr("Heli Setup (Futaba's channel assignment style)"));
66 templateList->addItem(tr("Heli Setup with gyro gain control (Futaba's channel assignment style)"));
67 templateList->addItem(tr("Gyro gain control (Futaba's channel assignment style)"));
68 templateList->addItem(tr("Servo Test"));
69 templateList->addItem(tr("MultiCopter"));
70 templateList->addItem(tr("Use Model Config Wizard"));
72 connect(templateList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClicked(QModelIndex)));
75 Templates::~Templates()
79 void Templates::setSwitch(unsigned int idx, unsigned int func, int v1, int v2)
81 g_model.logicalSw[idx-1].func = func;
82 g_model.logicalSw[idx-1].val1 = v1;
83 g_model.logicalSw[idx-1].val2 = v2;
86 void Templates::onDoubleClicked(QModelIndex index)
88 QString text = ui->templateList->item(index.row())->text();
89 if (index.row()==13) {
90 uint64_t result=0xffffffff;
91 modelConfigDialog *mcw = new modelConfigDialog(radioData, &result, this);
92 mcw->exec();
93 if (result!=0xffffffff) {
94 applyNumericTemplate(result);
95 updateSettings();
96 tabMixes();
98 } else {
99 int res = QMessageBox::question(this,tr("Apply Template?"),tr("Apply template \"%1\"?").arg(text),QMessageBox::Yes | QMessageBox::No);
100 if(res!=QMessageBox::Yes) return;
101 applyTemplate(index.row());
102 updateSettings();
103 tabMixes();
107 void Templates::applyNumericTemplate(uint64_t tpl)
109 clearCurves();
110 clearExpos(false);
111 clearMixes(false);
112 int8_t heli_ar1[] = {-100, -20, 30, 70, 90};
113 int8_t heli_ar2[] = {80, 70, 60, 70, 100};
114 int8_t heli_ar3[] = {100, 90, 80, 90, 100};
115 int8_t heli_ar4[] = {-30, -15, 0, 50, 100};
116 int8_t heli_ar5[] = {-100, -50, 0, 50, 100};
117 bool rx[10];
118 for (int i=0; i<10 ; i++) {
119 rx[i]=false;
121 int thrsw=firmware->getCapability(GetThrSwitch);
122 MixData *md = &model.mixData[0];
123 uint8_t spo2ch=(tpl & 0x0F);
124 tpl>>=4;
125 uint8_t spo1ch=(tpl & 0x0F);
126 tpl>>=4;
127 uint8_t fla2ch=(tpl & 0x0F);
128 tpl>>=4;
129 uint8_t fla1ch=(tpl & 0x0F);
130 tpl>>=4;
131 uint8_t rud2ch=(tpl & 0x0F);
132 tpl>>=4;
133 uint8_t ele2ch=(tpl & 0x0F);
134 tpl>>=4;
135 uint8_t ail2ch=(tpl & 0x0F);
136 tpl>>=4;
137 uint8_t chstyle=(tpl & 0x03);
138 tpl>>=2;
139 uint8_t gyro=(tpl & 0x03);
140 tpl>>=2;
141 uint8_t tailtype=(tpl & 0x03);
142 tpl>>=2;
143 uint8_t swashtype=(tpl & 0x07);
144 tpl>>=3;
145 uint8_t ruddertype=(tpl & 0x03);
146 tpl>>=2;
147 uint8_t spoilertype=(tpl & 0x3);
148 tpl>>=2;
149 uint8_t flaptype=(tpl & 0x03);
150 tpl>>=2;
151 uint8_t ailerontype=(tpl & 0x03);
152 tpl>>=2;
153 uint8_t enginetype=(tpl & 0x03);
154 tpl>>=2;
155 uint8_t modeltype=(tpl & 0x03);
157 #define ICC(x) icc[(x)-1]
158 uint8_t icc[4] = {0};
159 for(uint8_t i=1; i<=4; i++) //generate inverse array
160 for(uint8_t j=1; j<=4; j++) if(CC(i)==j) icc[j-1]=i;
162 int ailerons;
163 int flaps;
164 int throttle;
165 int spoilers;
166 int elevators;
167 int rudders;
168 int sign;
169 uint8_t rxch;
170 switch (modeltype) {
171 case 0:
172 ailerons=ailerontype;
173 flaps=flaptype;
174 throttle=1;
175 switch (tailtype) {
176 case 0:
177 case 1:
178 rudders=1;
179 elevators=1;
180 break;
181 case 2:
182 rudders=1;
183 elevators=2;
184 break;
186 rxch=ICC(STK_RUD);
187 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
188 if (tailtype==1) {
189 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
191 rx[rxch-1]=true;
192 rxch=ICC(STK_ELE);
193 if (tailtype==1) {
194 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
196 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
197 rx[rxch-1]=true;
198 rxch=ICC(STK_THR);
199 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("THR").toAscii().data(),6);
200 rx[rxch-1]=true;
201 if (ail2ch > 0) {
202 rx[ail2ch-1]=true;
204 if (ele2ch > 0) {
205 rx[ele2ch-1]=true;
207 if (fla1ch > 0) {
208 rx[fla1ch-1]=true;
210 if (fla2ch > 0) {
211 rx[fla2ch-1]=true;
213 if (ailerons>0) {
214 rxch=ICC(STK_AIL);
215 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
216 rx[rxch-1]=true;
218 if (ailerons>1) {
219 if (ail2ch==0) {
220 for (int j=0; j<10 ; j++) {
221 if (!rx[j]) {
222 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL2").toAscii().data(),6);
223 rx[j]=true;
224 break;
227 } else {
228 md=setDest(ail2ch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL2").toAscii().data(),6);
231 if (elevators>1) {
232 if (ele2ch==0) {
233 for (int j=0; j<10 ; j++) {
234 if (!rx[j]) {
235 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();;strncpy(md->name, tr("ELE2").toAscii().data(),6);
236 rx[j]=true;
237 break;
240 }else{
241 md=setDest(ele2ch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();;strncpy(md->name, tr("ELE2").toAscii().data(),6);
244 if (flaps>0) {
245 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_AIL);strncpy(md->name, tr("FLAPS").toAscii().data(),6); md->speedUp=4; md->speedDown=4;
246 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_AIL);strncpy(md->name, tr("FLAPS").toAscii().data(),6); md->speedUp=4; md->speedDown=4;
248 sign=-1;
249 for (uint8_t i=0; i< flaps; i++) {
250 sign*=-1;
251 int index;
252 if (i==0) {
253 index=fla1ch;
254 } else {
255 index=fla2ch;
257 if (index==0) {
258 for (int j=0; j<10 ; j++) {
259 if (!rx[j]) {
260 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight=100*sign; md->sOffset=0; md->swtch=RawSwitch();strncpy(md->name, tr("FLAP%1").arg(i+1).toAscii().data(),6);
261 rx[j]=true;
262 break;
265 } else {
266 md=setDest(index); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight=100*sign; md->sOffset=0; md->swtch=RawSwitch();strncpy(md->name, tr("FLAP%1").arg(i+1).toAscii().data(),6);
269 break;
270 case 1:
271 setCurve(CURVE5(1),heli_ar1);
272 setCurve(CURVE5(2),heli_ar2);
273 setCurve(CURVE5(3),heli_ar3);
274 setCurve(CURVE5(4),heli_ar4);
275 setCurve(CURVE5(5),heli_ar5);
276 setCurve(CURVE5(6),heli_ar5);
277 switch (swashtype) {
278 case 0:
279 model.swashRingData.type = HELI_SWASH_TYPE_90;
280 break;
281 case 1:
282 model.swashRingData.type = HELI_SWASH_TYPE_120;
283 break;
284 case 2:
285 model.swashRingData.type = HELI_SWASH_TYPE_120X;
286 break;
287 case 3:
288 model.swashRingData.type = HELI_SWASH_TYPE_140;
289 break;
290 case 4:
291 model.swashRingData.type = HELI_SWASH_TYPE_NONE;
292 break;
294 model.swashRingData.collectiveSource = RawSource(SOURCE_TYPE_CH, 10);
296 if (chstyle==0) {
297 if (swashtype!=4) {
298 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 0); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
299 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 1); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
300 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 2); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("PITCH").toAscii().data(),6);
301 } else {
302 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
303 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
304 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("PITCH").toAscii().data(),6);
306 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
307 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(1); md->carryTrim=TRIM_OFF;
308 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(2); md->carryTrim=TRIM_OFF;
309 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(3); md->carryTrim=TRIM_OFF;
310 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
311 switch (gyro) {
312 case 1:
313 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA);strncpy(md->name, tr("GYRO").toAscii().data(),6);
314 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA);strncpy(md->name, tr("GYRO").toAscii().data(),6);
315 break;
316 case 2:
317 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight= 50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA); md->sOffset=100;strncpy(md->name, tr("GYRO").toAscii().data(),6);
318 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=-50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA); md->sOffset=100;strncpy(md->name, tr("GYRO").toAscii().data(),6);
319 break;
321 } else {
322 if (swashtype!=4) {
323 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 1); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
324 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 0); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
325 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 2); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("PITCH").toAscii().data(),6);
326 } else {
327 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
328 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
329 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight= 100; md->swtch=RawSwitch();strncpy(md->name, tr("PITCH").toAscii().data(),6);
331 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
332 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(1); md->carryTrim=TRIM_OFF;
333 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(2); md->carryTrim=TRIM_OFF;
334 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(3); md->carryTrim=TRIM_OFF;
335 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
336 switch (gyro) {
337 case 1:
338 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA);strncpy(md->name, tr("GYRO").toAscii().data(),6);
339 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA);strncpy(md->name, tr("GYRO").toAscii().data(),6);
340 break;
341 case 2:
342 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight= 50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA); md->sOffset=100;strncpy(md->name, tr("GYRO").toAscii().data(),6);
343 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=-50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA); md->sOffset=100;strncpy(md->name, tr("GYRO").toAscii().data(),6);
344 break;
347 // collective
348 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(4); md->carryTrim=TRIM_OFF;
349 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(5); md->carryTrim=TRIM_OFF;
350 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(6); md->carryTrim=TRIM_OFF;
351 break;
352 case 2:
353 ailerons=ailerontype;
354 flaps=flaptype;
355 spoilers=spoilertype;
356 throttle=enginetype;
357 switch (tailtype) {
358 case 0:
359 case 1:
360 rudders=1;
361 elevators=1;
362 break;
363 case 2:
364 rudders=1;
365 elevators=2;
366 break;
368 if (throttle==1) {
369 rxch=ICC(STK_THR);
370 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("THR").toAscii().data(),6);
371 rx[rxch-1]=true;
373 rxch=ICC(STK_RUD);
374 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
375 if (tailtype==1) {
376 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
378 rx[rxch-1]=true;
379 rxch=ICC(STK_ELE);
380 if (tailtype==1) {
381 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
383 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
384 rx[rxch-1]=true;
385 if (ail2ch > 0) {
386 rx[ail2ch-1]=true;
388 if (ele2ch > 0) {
389 rx[ele2ch-1]=true;
391 if (fla1ch > 0) {
392 rx[fla1ch-1]=true;
394 if (fla2ch > 0) {
395 rx[fla2ch-1]=true;
397 if (spo1ch > 0) {
398 rx[spo1ch-1]=true;
400 if (spo2ch > 0) {
401 rx[spo2ch-1]=true;
404 if (ailerons>0) {
405 rxch=ICC(STK_AIL);
406 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
407 rx[rxch-1]=true;
409 if (ailerons>1) {
410 if (ail2ch==0) {
411 for (int j=0; j<10 ; j++) {
412 if (!rx[j]) {
413 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL2").toAscii().data(),6);
414 rx[j]=true;
415 break;
418 } else {
419 md=setDest(ail2ch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL2").toAscii().data(),6);
422 if (elevators>1) {
423 if (ele2ch==0) {
424 for (int j=0; j<10 ; j++) {
425 if (!rx[j]) {
426 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE2").toAscii().data(),6);
427 rx[j]=true;
428 break;
431 } else {
432 md=setDest(ele2ch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE2").toAscii().data(),6);
435 if (flaps>0) {
436 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_AIL);strncpy(md->name, tr("FLAPS").toAscii().data(),6);md->speedUp=4; md->speedDown=4;
437 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_AIL);strncpy(md->name, tr("FLAPS").toAscii().data(),6);md->speedUp=4; md->speedDown=4;
439 sign=-1;
440 for (uint8_t i=0; i< flaps; i++) {
441 sign*=-1;
442 int index;
443 if (i==0) {
444 index=fla1ch;
445 } else {
446 index=fla2ch;
448 if (index==0) {
449 for (int j=0; j<10 ; j++) {
450 if (!rx[j]) {
451 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight=100*sign; md->sOffset=0; md->swtch=RawSwitch();strncpy(md->name, tr("FLAP%1").arg(i+1).toAscii().data(),6);
452 rx[j]=true;
453 break;
456 } else {
457 md=setDest(index); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight=100*sign; md->sOffset=0; md->swtch=RawSwitch();strncpy(md->name, tr("FLAP%1").arg(i+1).toAscii().data(),6);
460 if (spoilers>0) {
461 md=setDest(12); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA);strncpy(md->name, tr("SPOIL").toAscii().data(),6); md->speedUp=4;;md->speedDown=4;
462 md=setDest(12); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA);strncpy(md->name, tr("SPOIL").toAscii().data(),6);md->speedUp=4;md->speedDown=4;
464 sign=-1;
465 for (uint8_t i=0; i< spoilers; i++) {
466 sign*=-1;
467 int index;
468 if (i==0) {
469 index=spo1ch;
470 } else {
471 index=spo2ch;
473 if (index==0) {
474 for (int j=0; j<10 ; j++) {
475 if (!rx[j]) {
476 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_CH, 11); md->weight=100*sign; md->sOffset=0; md->swtch=RawSwitch();strncpy(md->name, tr("SPOIL%1").arg(i+1).toAscii().data(),6);
477 rx[j]=true;
478 break;
481 } else {
482 md=setDest(index); md->srcRaw=RawSource(SOURCE_TYPE_CH, 11); md->weight=100*sign; md->sOffset=0; md->swtch=RawSwitch();strncpy(md->name, tr("SPOIL%1").arg(i+1).toAscii().data(),6);
485 break;
486 case 3:
487 flaps=flaptype;
488 throttle=enginetype;
489 rudders=ruddertype;
490 if (throttle==1) {
491 rxch=ICC(STK_THR);
492 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("THR").toAscii().data(),6);
493 rx[rxch-1]=true;
495 rxch=ICC(STK_ELE);
496 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
497 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("ELE").toAscii().data(),6);
498 rx[rxch-1]=true;
499 rxch=ICC(STK_AIL);
500 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
501 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("AIL").toAscii().data(),6);
502 rx[rxch-1]=true;
503 if (rudders>0) {
504 rxch=ICC(STK_RUD);
505 md=setDest(rxch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD").toAscii().data(),6);
506 rx[rxch-1]=true;
508 if (rud2ch > 0) {
509 rx[rud2ch-1]=true;
511 if (fla1ch > 0) {
512 rx[fla1ch-1]=true;
514 if (fla2ch > 0) {
515 rx[fla2ch-1]=true;
517 if (rudders>1) {
518 if (rud2ch==0) {
519 for (int j=0; j<10 ; j++) {
520 if (!rx[j]) {
521 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD2").toAscii().data(),6);
522 rx[j]=true;
523 break;
526 } else {
527 md=setDest(rud2ch); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=-100; md->swtch=RawSwitch();strncpy(md->name, tr("RUD2").toAscii().data(),6);
530 if (flaps>0) {
531 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_AIL);strncpy(md->name, tr("FLAPS").toAscii().data(),6); md->sOffset=0; md->speedUp=4;
532 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_AIL);strncpy(md->name, tr("FLAPS").toAscii().data(),6); md->sOffset=0; md->speedUp=4;
534 sign=-1;
535 for (uint8_t i=0; i< flaps; i++) {
536 sign*=-1;
537 int index;
538 if (i==0) {
539 index=fla1ch;
540 } else {
541 index=fla2ch;
543 if (index==0) {
544 for (int j=0; j<10 ; j++) {
545 if (!rx[j]) {
546 md=setDest(j+1); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight=100*sign; md->sOffset=0; md->speedUp=4; md->speedDown=4; md->swtch=RawSwitch();strncpy(md->name, tr("FLAP%1").arg(i+1).toAscii().data(),6);
547 rx[j]=true;
548 break;
551 } else {
552 md=setDest(index); md->srcRaw=RawSource(SOURCE_TYPE_CH, 10); md->weight=100*sign; md->sOffset=0; md->speedUp=4; md->speedDown=4; md->swtch=RawSwitch();strncpy(md->name, tr("FLAP%1").arg(i+1).toAscii().data(),6);
555 break;
557 updateHeliTab();
558 updateCurvesTab();
559 if (modeltype==1 && swashtype!=4) {
560 ui->tabWidget->setCurrentIndex(1);
561 } else {
562 ui->tabWidget->setCurrentIndex(4);
564 resizeEvent();
567 void Templates::applyTemplate(uint8_t idx)
569 int8_t heli_ar1[] = {-100, -20, 30, 70, 90};
570 int8_t heli_ar2[] = {80, 70, 60, 70, 100};
571 int8_t heli_ar3[] = {100, 90, 80, 90, 100};
572 int8_t heli_ar4[] = {-30, -15, 0, 50, 100};
573 int8_t heli_ar5[] = {-100, -50, 0, 50, 100};
575 int thrsw=firmware->getCapability(GetThrSwitch);
576 MixData *md = &model.mixData[0];
578 //CC(STK) -> vSTK
579 //ICC(vSTK) -> STK
580 #define ICC(x) icc[(x)-1]
581 uint8_t icc[4] = {0};
582 for(uint8_t i=1; i<=4; i++) //generate inverse array
583 for(uint8_t j=1; j<=4; j++) if(CC(i)==j) icc[j-1]=i;
586 uint8_t j = 0;
588 //Simple 4-Ch
589 if(idx==j++) {
590 if (md->destCh)
591 clearMixes();
592 md=setDest(ICC(STK_RUD)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();
593 md=setDest(ICC(STK_ELE)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=100; md->swtch=RawSwitch();
594 md=setDest(ICC(STK_THR)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch();
595 md=setDest(ICC(STK_AIL)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();
598 //T-Cut
599 if(idx==j++) {
600 md=setDest(ICC(STK_THR)); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
603 //sticky t-cut
604 if(idx==j++) {
605 md=setDest(ICC(STK_THR)); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_VIRTUAL, 12); md->mltpx=MLTPX_REP;
606 md=setDest(14); md->srcRaw=RawSource(SOURCE_TYPE_CH, 13); md->weight= 100; md->swtch=RawSwitch();
607 md=setDest(14); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_VIRTUAL, 11); md->mltpx=MLTPX_REP;
608 md=setDest(14); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
609 setSwitch(0xB, LS_FN_VNEG, RawSource(SOURCE_TYPE_STICK, 2).toValue(), -99);
610 setSwitch(0xC, LS_FN_VPOS, RawSource(SOURCE_TYPE_CH, 13).toValue(), 0);
611 updateSwitchesTab();
614 //V-Tail
615 if(idx==j++) {
616 clearMixes();
617 md=setDest(ICC(STK_THR)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch();
618 md=setDest(ICC(STK_AIL)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();
619 md=setDest(ICC(STK_RUD)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight= 100; md->swtch=RawSwitch();
620 md=setDest(ICC(STK_RUD)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();
621 md=setDest(ICC(STK_ELE)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight= 100; md->swtch=RawSwitch();
622 md=setDest(ICC(STK_ELE)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight= 100; md->swtch=RawSwitch();
625 //Elevon\\Delta
626 if(idx==j++) {
627 clearMixes();
628 md=setDest(ICC(STK_THR)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch();
629 md=setDest(ICC(STK_RUD)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();
630 md=setDest(ICC(STK_ELE)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight= 100; md->swtch=RawSwitch();
631 md=setDest(ICC(STK_ELE)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight= 100; md->swtch=RawSwitch();
632 md=setDest(ICC(STK_AIL)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-100; md->swtch=RawSwitch();
633 md=setDest(ICC(STK_AIL)); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=100; md->swtch=RawSwitch();
636 //Heli Setup
637 if(idx==j++) {
638 clearMixes(); //This time we want a clean slate
639 clearCurves();
641 // Set up Mixes
642 // 3 cyclic channels
643 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 0); md->weight= 100; md->swtch=RawSwitch();
644 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 1); md->weight= 100; md->swtch=RawSwitch();
645 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 2); md->weight= 100; md->swtch=RawSwitch();
647 // rudder
648 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();
650 // throttle
651 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(1); md->carryTrim=TRIM_OFF;
652 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(2); md->carryTrim=TRIM_OFF;
653 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(3); md->carryTrim=TRIM_OFF;
654 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
656 // gyro gain
657 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA);
658 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA);
660 // collective
661 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(4); md->carryTrim=TRIM_OFF;
662 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(5); md->carryTrim=TRIM_OFF;
663 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(6); md->carryTrim=TRIM_OFF;
665 model.swashRingData.type = HELI_SWASH_TYPE_120;
666 model.swashRingData.collectiveSource = RawSource(SOURCE_TYPE_CH, 10);
668 // set up Curves
669 setCurve(CURVE5(1),heli_ar1);
670 setCurve(CURVE5(2),heli_ar2);
671 setCurve(CURVE5(3),heli_ar3);
672 setCurve(CURVE5(4),heli_ar4);
673 setCurve(CURVE5(5),heli_ar5);
674 setCurve(CURVE5(6),heli_ar5);
676 // make sure curves are redrawn
677 updateHeliTab();
678 updateCurvesTab();
679 resizeEvent();
682 //Heli Setup gyro gain control
683 if(idx==j++) {
684 clearMixes(); //This time we want a clean slate
685 clearCurves();
687 // Set up Mixes
688 // 3 cyclic channels
689 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 0); md->weight= 100; md->swtch=RawSwitch();
690 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 1); md->weight= 100; md->swtch=RawSwitch();
691 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 2); md->weight= 100; md->swtch=RawSwitch();
693 // rudder
694 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();
696 // throttle
697 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(1); md->carryTrim=TRIM_OFF;
698 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(2); md->carryTrim=TRIM_OFF;
699 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(3); md->carryTrim=TRIM_OFF;
700 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
702 // gyro gain
703 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight= 50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA); md->sOffset=100;
704 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=-50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA); md->sOffset=100;
706 // collective
707 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(4); md->carryTrim=TRIM_OFF;
708 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(5); md->carryTrim=TRIM_OFF;
709 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(6); md->carryTrim=TRIM_OFF;
711 model.swashRingData.type = HELI_SWASH_TYPE_120;
712 model.swashRingData.collectiveSource = RawSource(SOURCE_TYPE_CH, 10);
714 // set up Curves
715 setCurve(CURVE5(1),heli_ar1);
716 setCurve(CURVE5(2),heli_ar2);
717 setCurve(CURVE5(3),heli_ar3);
718 setCurve(CURVE5(4),heli_ar4);
719 setCurve(CURVE5(5),heli_ar5);
720 setCurve(CURVE5(6),heli_ar5);
722 // make sure curves are redrawn
723 updateHeliTab();
724 updateCurvesTab();
725 resizeEvent();
728 // gyro gain control
729 if(idx==j++) {
730 int res = QMessageBox::question(this,tr("Clear Mixes?"),tr("Really clear existing mixes on CH6?"),QMessageBox::Yes | QMessageBox::No);
731 if(res!=QMessageBox::Yes) return;
732 // first clear mix on ch6
733 bool found=true;
734 while (found) {
735 found=false;
736 for (int i=0; i< firmware->getCapability(Mixes); i++) {
737 if (model.mixData[i].destCh==6) {
738 gm_deleteMix(i);
739 found=true;
740 break;
744 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight= 50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA); md->sOffset=100;
745 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=-50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA); md->sOffset=100;
748 //Heli Setup futaba style
749 if(idx==j++) {
750 clearMixes(); //This time we want a clean slate
751 clearCurves();
753 // Set up Mixes
754 // 3 cyclic channels
755 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 1); md->weight= 100; md->swtch=RawSwitch();
756 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 0); md->weight= 100; md->swtch=RawSwitch();
757 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 2); md->weight= 100; md->swtch=RawSwitch();
759 // rudder
760 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();
762 // throttle
763 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(1); md->carryTrim=TRIM_OFF;
764 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(2); md->carryTrim=TRIM_OFF;
765 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(3); md->carryTrim=TRIM_OFF;
766 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
768 // gyro gain
769 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA);
770 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-30; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA);
772 // collective
773 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(4); md->carryTrim=TRIM_OFF;
774 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(5); md->carryTrim=TRIM_OFF;
775 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(6); md->carryTrim=TRIM_OFF;
777 model.swashRingData.type = HELI_SWASH_TYPE_120;
778 model.swashRingData.collectiveSource = RawSource(SOURCE_TYPE_CH, 10);
780 // set up Curves
781 setCurve(CURVE5(1),heli_ar1);
782 setCurve(CURVE5(2),heli_ar2);
783 setCurve(CURVE5(3),heli_ar3);
784 setCurve(CURVE5(4),heli_ar4);
785 setCurve(CURVE5(5),heli_ar5);
786 setCurve(CURVE5(6),heli_ar5);
788 // make sure curves are redrawn
789 updateHeliTab();
790 updateCurvesTab();
791 resizeEvent();
794 // Heli setup futaba style with gyro gain control
795 if(idx==j++) {
796 clearMixes(); //This time we want a clean slate
797 clearCurves();
799 // Set up Mixes
800 // 3 cyclic channels
801 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 1); md->weight= 100; md->swtch=RawSwitch();
802 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 0); md->weight= 100; md->swtch=RawSwitch();
803 md=setDest(6); md->srcRaw=RawSource(SOURCE_TYPE_CYC, 2); md->weight= 100; md->swtch=RawSwitch();
805 // rudder
806 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch();
808 // throttle
809 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(1); md->carryTrim=TRIM_OFF;
810 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(2); md->carryTrim=TRIM_OFF;
811 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight= 100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(3); md->carryTrim=TRIM_OFF;
812 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,thrsw); md->mltpx=MLTPX_REP;
814 // gyro gain
815 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight= 50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA); md->sOffset=100;
816 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=-50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA); md->sOffset=100;
818 // collective
819 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID0); md->curve=CV(4); md->carryTrim=TRIM_OFF;
820 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID1); md->curve=CV(5); md->carryTrim=TRIM_OFF;
821 md=setDest(11); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_ID2); md->curve=CV(6); md->carryTrim=TRIM_OFF;
823 model.swashRingData.type = HELI_SWASH_TYPE_120;
824 model.swashRingData.collectiveSource = RawSource(SOURCE_TYPE_CH, 10);
826 // set up Curves
827 setCurve(CURVE5(1),heli_ar1);
828 setCurve(CURVE5(2),heli_ar2);
829 setCurve(CURVE5(3),heli_ar3);
830 setCurve(CURVE5(4),heli_ar4);
831 setCurve(CURVE5(5),heli_ar5);
832 setCurve(CURVE5(6),heli_ar5);
834 // make sure curves are redrawn
835 updateHeliTab();
836 updateCurvesTab();
837 resizeEvent();
840 // gyro gain control futaba style
841 if(idx==j++) {
842 int res = QMessageBox::question(this,tr("Clear Mixes?"),tr("Really clear existing mixes on CH5?"),QMessageBox::Yes | QMessageBox::No);
843 if(res!=QMessageBox::Yes) return;
844 // first clear mix on ch6
845 bool found=true;
846 while (found) {
847 found=false;
848 for (int i=0; i< firmware->getCapability(Mixes); i++) {
849 if (model.mixData[i].destCh==5) {
850 gm_deleteMix(i);
851 found=true;
852 break;
856 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight= 50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,-Board::SWITCH_GEA); md->sOffset=100;
857 md=setDest(5); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 5); md->weight=-50; md->swtch=RawSwitch(Board::SWITCH_TYPE_SWITCH,Board::SWITCH_GEA); md->sOffset=100;
860 //Servo Test
861 if(idx==j++) {
862 md=setDest(15); md->srcRaw=RawSource(SOURCE_TYPE_CH, 15); md->weight= 100; md->speedUp = 8; md->speedDown = 8; md->swtch=RawSwitch();
863 md=setDest(16); md->srcRaw=RawSource(SOURCE_TYPE_CUSTOM_SWITCH, 0); md->weight= 110; md->swtch=RawSwitch();
864 md=setDest(16); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight=-110; md->swtch=RawSwitch(Board::SWITCH_TYPE_VIRTUAL, 2); md->mltpx=MLTPX_REP;
865 md=setDest(16); md->srcRaw=RawSource(SOURCE_TYPE_MAX); md->weight= 110; md->swtch=RawSwitch(Board::SWITCH_TYPE_VIRTUAL, 3); md->mltpx=MLTPX_REP;
866 setSwitch(1, LS_FN_LESS, RawSource(SOURCE_TYPE_CH, 14).toValue(), RawSource(SOURCE_TYPE_CH, 15).toValue());
867 setSwitch(2, LS_FN_VPOS, RawSource(SOURCE_TYPE_CH, 14).toValue(), 105);
868 setSwitch(3, LS_FN_VNEG, RawSource(SOURCE_TYPE_CH, 14).toValue(), -105);
870 // redraw switches tab
871 updateSwitchesTab();
874 //MultiCopter
875 if(idx==j++) {
876 if (md->destCh)
877 clearMixes();
878 md=setDest(1); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 3); md->weight=50; md->swtch=RawSwitch(); //CH1 AIL
879 md=setDest(2); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 1); md->weight=-50; md->swtch=RawSwitch(); //CH2 ELE
880 md=setDest(3); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 2); md->weight=100; md->swtch=RawSwitch(); //CH3 THR
881 md=setDest(4); md->srcRaw=RawSource(SOURCE_TYPE_STICK, 0); md->weight=100; md->swtch=RawSwitch(); //CH4 RUD
885 MixData* Templates::setDest(uint8_t dch)
887 uint8_t i = 0;
888 while ((g_model.mixData[i].destCh<=dch) && (g_model.mixData[i].destCh) && (i<firmware->getCapability(Mixes))) i++;
889 if(i==firmware->getCapability(Mixes)) return &g_model.mixData[0];
891 memmove(&g_model.mixData[i+1],&g_model.mixData[i],
892 (firmware->getCapability(Mixes)-(i+1))*sizeof(MixData) );
893 memset(&g_model.mixData[i],0,sizeof(MixData));
894 g_model.mixData[i].destCh = dch;
895 return &g_model.mixData[i];