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 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);
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 model
.category
= originalModelData
.category
;
96 model
.moduleData
[0].modelId
= modelId
;
97 model
.setDefaultInputs(settings
);
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
) {
116 if (options
[THROTTLE_CUT_OPTION
]) {
117 // Add the Throttle Cut option
118 MixData
& mix
= model
.mixData
[mixIndex
++];
120 mix
.srcRaw
= SOURCE_TYPE_MAX
;
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
;
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
;