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.
22 #include "eeprominterface.h"
23 #include "wizarddata.h"
40 WizMix::WizMix(const GeneralSettings
& settings
, unsigned int modelId
, const ModelData
& modelData
):
44 originalModelData(modelData
),
47 strncpy(name
, originalModelData
.name
, WIZ_MODEL_NAME_LENGTH
);
51 void WizMix::maxMixSwitch(char *name
, MixData
&mix
, int channel
, int sw
, int weight
)
53 strncpy(mix
.name
, name
, MIXDATA_NAME_LEN
);
54 mix
.name
[MIXDATA_NAME_LEN
] = '\0';
56 mix
.srcRaw
= RawSource(SOURCE_TYPE_MAX
);
57 mix
.swtch
= RawSwitch(SWITCH_TYPE_SWITCH
, sw
);
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
);
73 mix
.srcRaw
= RawSource(SOURCE_TYPE_STICK
, input
-1);
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;
94 //ModelData model(originalModelData);
95 model
.category
= originalModelData
.category
;
97 model
.moduleData
[0].modelId
= modelId
;
98 model
.setDefaultInputs(settings
);
103 // Safe copy model name
104 strncpy(model
.name
, name
, WIZ_MODEL_NAME_LENGTH
);
105 model
.name
[WIZ_MODEL_NAME_LENGTH
] = 0;
107 // Add the channel mixes
108 for (int i
=0; i
<WIZ_MAX_CHANNELS
; i
++ )
110 Channel ch
= channel
[i
];
112 addMix(model
, ch
.input1
, ch
.weight1
, i
, mixIndex
);
113 addMix(model
, ch
.input2
, ch
.weight2
, i
, mixIndex
);
115 if ((ch
.input1
== THROTTLE_INPUT
|| ch
.input2
== THROTTLE_INPUT
) && options
[THROTTLE_CUT_OPTION
]) {
116 // Add the Throttle Cut option
117 MixData
& mix
= model
.mixData
[mixIndex
++];
119 mix
.srcRaw
= SOURCE_TYPE_MAX
;
121 mix
.swtch
.type
= SWITCH_TYPE_SWITCH
;
122 mix
.swtch
.index
= IS_ARM(getCurrentBoard()) ? SWITCH_SF0
: SWITCH_THR
;
123 mix
.mltpx
= MLTPX_REP
;
124 strncpy(mix
.name
, "Cut", MIXDATA_NAME_LEN
);
125 mix
.name
[MIXDATA_NAME_LEN
] = '\0';
129 // Add the Flight Timer option
130 if (options
[FLIGHT_TIMER_OPTION
] ){
131 model
.timers
[timerIndex
].mode
.type
= SWITCH_TYPE_TIMER_MODE
;
132 model
.timers
[timerIndex
].mode
.index
= TMRMODE_THR_TRG
;
136 // Add the Throttle Timer option
137 if (options
[THROTTLE_TIMER_OPTION
] && throttleChannel
>=0){
138 model
.timers
[timerIndex
].mode
.type
= SWITCH_TYPE_TIMER_MODE
;
139 model
.timers
[timerIndex
].mode
.index
= TMRMODE_THR
;