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_HORUS_OR_TARANIS(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
);
104 // Safe copy model name
105 strncpy(model
.name
, name
, WIZ_MODEL_NAME_LENGTH
);
106 model
.name
[WIZ_MODEL_NAME_LENGTH
] = 0;
108 // Add the channel mixes
109 for (int i
=0; i
<WIZ_MAX_CHANNELS
; i
++ )
111 Channel ch
= channel
[i
];
112 if (ch
.input1
== THROTTLE_INPUT
|| ch
.input2
== THROTTLE_INPUT
)
115 addMix(model
, ch
.input1
, ch
.weight1
, i
, mixIndex
);
116 addMix(model
, ch
.input2
, ch
.weight2
, i
, mixIndex
);
119 // Add the Throttle Cut option
120 if( options
[THROTTLE_CUT_OPTION
] && throttleChannel
>=0 ){
121 model
.customFn
[switchIndex
].swtch
.type
= SWITCH_TYPE_SWITCH
;
122 model
.customFn
[switchIndex
].swtch
.index
= IS_HORUS_OR_TARANIS(getCurrentBoard()) ? SWITCH_SF0
: SWITCH_THR
;
123 model
.customFn
[switchIndex
].enabled
= 1;
124 model
.customFn
[switchIndex
].func
= (AssignFunc
)throttleChannel
;
125 model
.customFn
[switchIndex
].param
= -100;
128 // Add the Flight Timer option
129 if (options
[FLIGHT_TIMER_OPTION
] ){
130 model
.timers
[timerIndex
].mode
.type
= SWITCH_TYPE_TIMER_MODE
;
131 model
.timers
[timerIndex
].mode
.index
= TMRMODE_THR_TRG
;
135 // Add the Throttle Timer option
136 if (options
[THROTTLE_TIMER_OPTION
] && throttleChannel
>=0){
137 model
.timers
[timerIndex
].mode
.type
= SWITCH_TYPE_TIMER_MODE
;
138 model
.timers
[timerIndex
].mode
.index
= TMRMODE_THR
;