Cosmetics
[opentx.git] / companion / src / wizarddata.cpp
blobf544ee4b05dd86331e90c096ac6a78189f575009
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 <string.h>
22 #include "eeprominterface.h"
23 #include "wizarddata.h"
25 Channel::Channel()
27 clear();
30 void Channel::clear()
32 page = Page_None;
33 prebooked = false;
34 input1 = NO_INPUT;
35 input2 = NO_INPUT;
36 weight1 = 0;
37 weight2 = 0;
40 WizMix::WizMix(const GeneralSettings & settings, unsigned int modelId, const ModelData & modelData):
41 complete(false),
42 modelId(modelId),
43 settings(settings),
44 originalModelData(modelData),
45 vehicle(NOVEHICLE)
47 memset(name, 0, sizeof(name));
48 strncpy(name, originalModelData.name, sizeof(name)-1);
51 void WizMix::maxMixSwitch(char *name, MixData &mix, int channel, int sw, int weight)
53 memset(mix.name, 0, sizeof(mix.name));
54 strncpy(mix.name, name, sizeof(mix.name)-1);
55 mix.destCh = channel;
56 mix.srcRaw = RawSource(SOURCE_TYPE_MAX);
57 mix.swtch = RawSwitch(SWITCH_TYPE_SWITCH, sw);
58 mix.weight = weight;
61 void WizMix::addMix(ModelData &model, Input input, int weight, int channel, int & mixIndex)
63 if (input != NO_INPUT) {
64 bool isHorusOrTaranis = IS_ARM(getCurrentBoard());
65 if (input >= RUDDER_INPUT && input <= AILERONS_INPUT) {
66 MixData & mix = model.mixData[mixIndex++];
67 mix.destCh = channel+1;
68 if (isHorusOrTaranis){
69 int channel = settings.getDefaultChannel(input-1);
70 mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, channel);
72 else
73 mix.srcRaw = RawSource(SOURCE_TYPE_STICK, input-1);
74 mix.weight = weight;
76 else if (input==FLAPS_INPUT){
77 // There ought to be some kind of constants for switches somewhere...
78 maxMixSwitch((char *)"Flaps Up", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SA0 :-SWITCH_ELE , weight); //Taranis-Horus SA-UP, 9X ELE-UP
79 maxMixSwitch((char *)"Flaps Dn", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SA2 : SWITCH_ELE , -weight); //Taranis-Horus SA-DOWN, 9X ELE-DOWN
82 else if (input==AIRBRAKES_INPUT){
83 maxMixSwitch((char *)"AirbkOff", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SE0 :-SWITCH_RUD , -weight); //Taranis-Horus SE-UP, 9X RUD-UP
84 maxMixSwitch((char *)"AirbkOn", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SE2 : SWITCH_RUD , weight); //Tatanis-Horus SE-DOWN, 9X RUD-DOWN
89 WizMix::operator ModelData()
91 int throttleChannel = -1;
93 ModelData model;
94 model.category = originalModelData.category;
95 model.used = true;
96 model.moduleData[0].modelId = modelId;
97 model.setDefaultInputs(settings);
99 int mixIndex = 0;
100 int timerIndex = 0;
102 // Safe copy model name
103 memset(model.name, 0, sizeof(model.name));
104 strncpy(model.name, name, sizeof(model.name)-1);
106 // Add the channel mixes
107 for (int i=0; i<WIZ_MAX_CHANNELS; i++ )
109 Channel ch = channel[i];
111 addMix(model, ch.input1, ch.weight1, i, mixIndex);
112 addMix(model, ch.input2, ch.weight2, i, mixIndex);
114 if (ch.input1 == THROTTLE_INPUT || ch.input2 == THROTTLE_INPUT) {
115 throttleChannel++;
116 if (options[THROTTLE_CUT_OPTION]) {
117 // Add the Throttle Cut option
118 MixData & mix = model.mixData[mixIndex++];
119 mix.destCh = i+1;
120 mix.srcRaw = SOURCE_TYPE_MAX;
121 mix.weight = -100;
122 mix.swtch.type = SWITCH_TYPE_SWITCH;
123 mix.swtch.index = IS_ARM(getCurrentBoard()) ? SWITCH_SF0 : SWITCH_THR;
124 mix.mltpx = MLTPX_REP;
125 memset(mix.name, 0, sizeof(mix.name));
126 strncpy(mix.name, "Cut", MIXDATA_NAME_LEN);
131 // Add the Flight Timer option
132 if (options[FLIGHT_TIMER_OPTION] && throttleChannel >= 0){
133 memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
134 strncpy(model.timers[timerIndex].name, "Flt", sizeof(model.timers[timerIndex].name)-1);
135 model.timers[timerIndex].mode.type = SWITCH_TYPE_TIMER_MODE;
136 model.timers[timerIndex].mode.index = TMRMODE_THR_TRG;
137 timerIndex++;
140 // Add the Throttle Timer option
141 if (options[THROTTLE_TIMER_OPTION] && throttleChannel >= 0){
142 memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
143 strncpy(model.timers[timerIndex].name, "Thr", sizeof(model.timers[timerIndex].name)-1);
144 model.timers[timerIndex].mode.type = SWITCH_TYPE_TIMER_MODE;
145 model.timers[timerIndex].mode.index = TMRMODE_THR;
146 timerIndex++;
149 return model;