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.
23 #if !defined(VIRTUAL_INPUTS)
24 TEST(getSwitch
, undefCSW
)
27 EXPECT_EQ(getSwitch(NUM_PSWITCH
), false);
28 EXPECT_EQ(getSwitch(-NUM_PSWITCH
), true); // no good answer there!
33 TEST(getSwitch
, circularCSW
)
37 g_model
.logicalSw
[0] = { SWSRC_SW1
, SWSRC_SW1
, LS_FUNC_OR
};
38 g_model
.logicalSw
[1] = { SWSRC_SW1
, SWSRC_SW1
, LS_FUNC_AND
};
40 evalLogicalSwitches();
41 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
42 EXPECT_EQ(getSwitch(-SWSRC_SW1
), true);
43 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
44 EXPECT_EQ(getSwitch(-SWSRC_SW2
), true);
48 #if defined(VIRTUAL_INPUTS)
49 void setLogicalSwitch(int index
, uint16_t _func
, int16_t _v1
, int16_t _v2
, int16_t _v3
= 0, uint8_t _delay
= 0, uint8_t _duration
= 0, int8_t _andsw
= 0)
51 g_model
.logicalSw
[index
].func
= _func
;
52 g_model
.logicalSw
[index
].v1
= _v1
;
53 g_model
.logicalSw
[index
].v2
= _v2
;
54 g_model
.logicalSw
[index
].v3
= _v3
;
55 g_model
.logicalSw
[index
].delay
= _delay
;
56 g_model
.logicalSw
[index
].duration
= _duration
;
57 g_model
.logicalSw
[index
].andsw
= _andsw
;
61 #if defined(PCBTARANIS)
62 TEST(getSwitch
, OldTypeStickyCSW
)
68 setLogicalSwitch(0, LS_FUNC_AND
, SWSRC_SA0
, SWSRC_NONE
);
69 setLogicalSwitch(1, LS_FUNC_OR
, SWSRC_SW1
, SWSRC_SW2
);
72 evalLogicalSwitches();
73 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
74 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
76 // now trigger SA0, both switches should become true
78 evalLogicalSwitches();
79 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
80 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
82 // now release SA0 and SW2 should stay true
84 evalLogicalSwitches();
85 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
86 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
88 // now reset logical switches
89 logicalSwitchesReset();
90 evalLogicalSwitches();
91 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
92 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
96 TEST(getSwitch
, nullSW
)
99 EXPECT_EQ(getSwitch(0), true);
103 TEST(getSwitch
, recursiveSW
)
108 g_model
.logicalSw
[0] = { SWSRC_RUD
, -SWSRC_SW2
, LS_FUNC_OR
};
109 g_model
.logicalSw
[1] = { SWSRC_ELE
, -SWSRC_SW1
, LS_FUNC_OR
};
111 simuSetSwitch(2, 0); // RUD 0
112 simuSetSwitch(3, 0); // ELE 0
113 evalLogicalSwitches();
114 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
115 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
117 LS_RECURSIVE_EVALUATION_RESET();
118 evalLogicalSwitches();
119 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
120 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
122 simuSetSwitch(2, 1); // RUD 1
123 LS_RECURSIVE_EVALUATION_RESET();
124 evalLogicalSwitches();
125 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
126 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
128 LS_RECURSIVE_EVALUATION_RESET();
129 evalLogicalSwitches();
130 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
131 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
133 #endif // #if !defined(CPUARM)
135 #if defined(PCBTARANIS)
136 TEST(getSwitch
, inputWithTrim
)
142 // g_model.logicalSw[0] = { LS_FUNC_VPOS, MIXSRC_FIRST_INPUT, 0, 0 };
143 setLogicalSwitch(0, LS_FUNC_VPOS
, MIXSRC_FIRST_INPUT
, 0, 0);
146 evalLogicalSwitches();
147 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
149 setTrimValue(0, 0, 32);
151 evalLogicalSwitches();
152 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
156 #if defined(PCBTARANIS) || defined(PCBHORUS)
157 TEST(evalLogicalSwitches
, playFile
)
164 extern BitField
<(MAX_LOGICAL_SWITCHES
* 2/*on, off*/)> sdAvailableLogicalSwitchAudioFiles
;
165 char filename
[AUDIO_FILENAME_MAXLEN
+1];
168 #define MODELNAME "MODEL01"
170 #define MODELNAME "Model00"
173 sdAvailableLogicalSwitchAudioFiles
.setBit(INDEX_LOGICAL_SWITCH_AUDIO_FILE(0,AUDIO_EVENT_OFF
));
174 sdAvailableLogicalSwitchAudioFiles
.setBit(INDEX_LOGICAL_SWITCH_AUDIO_FILE(0,AUDIO_EVENT_ON
));
175 sdAvailableLogicalSwitchAudioFiles
.setBit(INDEX_LOGICAL_SWITCH_AUDIO_FILE(31,AUDIO_EVENT_OFF
));
176 sdAvailableLogicalSwitchAudioFiles
.setBit(INDEX_LOGICAL_SWITCH_AUDIO_FILE(31,AUDIO_EVENT_ON
));
178 isAudioFileReferenced((LOGICAL_SWITCH_AUDIO_CATEGORY
<< 24) + (0 << 16) + AUDIO_EVENT_OFF
, filename
);
179 EXPECT_EQ(strcmp(filename
, "/SOUNDS/en/" MODELNAME
"/L1-off.wav"), 0);
180 isAudioFileReferenced((LOGICAL_SWITCH_AUDIO_CATEGORY
<< 24) + (0 << 16) + AUDIO_EVENT_ON
, filename
);
181 EXPECT_EQ(strcmp(filename
, "/SOUNDS/en/" MODELNAME
"/L1-on.wav"), 0);
182 isAudioFileReferenced((LOGICAL_SWITCH_AUDIO_CATEGORY
<< 24) + (31 << 16) + AUDIO_EVENT_OFF
, filename
);
183 EXPECT_EQ(strcmp(filename
, "/SOUNDS/en/" MODELNAME
"/L32-off.wav"), 0);
184 isAudioFileReferenced((LOGICAL_SWITCH_AUDIO_CATEGORY
<< 24) + (31 << 16) + AUDIO_EVENT_ON
, filename
);
185 EXPECT_EQ(strcmp(filename
, "/SOUNDS/en/" MODELNAME
"/L32-on.wav"), 0);
187 EXPECT_EQ(isAudioFileReferenced((LOGICAL_SWITCH_AUDIO_CATEGORY
<< 24) + (31 << 16) + AUDIO_EVENT_ON
, filename
), true);
188 EXPECT_EQ(isAudioFileReferenced((LOGICAL_SWITCH_AUDIO_CATEGORY
<< 24) + (32 << 16) + AUDIO_EVENT_ON
, filename
), false);
194 #if defined(PCBTARANIS) && NUM_SWITCHES >= 8
195 TEST(getSwitch
, edgeInstant
)
199 // LS1 setup: EDGE SFup (0:instant)
200 // LS2 setup: (EDGE SFup (0:instant)) AND SAup
201 setLogicalSwitch(0, LS_FUNC_EDGE
, SWSRC_SF2
, -129, -1);
202 setLogicalSwitch(1, LS_FUNC_EDGE
, SWSRC_SF2
, -129, -1, 0, 0, SWSRC_SA2
);
204 simuSetSwitch(0, -1); //SA down
205 simuSetSwitch(5, 0); //SF down
206 // EXPECT_EQ(getSwitch(SWSRC_SF2), false);
207 logicalSwitchesTimerTick();
208 evalLogicalSwitches();
209 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
210 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
212 // now trigger SFup, LS1 should become true
213 simuSetSwitch(5, 1); //SF up
214 // EXPECT_EQ(getSwitch(SWSRC_SF2), true);
215 logicalSwitchesTimerTick();
216 evalLogicalSwitches();
217 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
218 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
220 // now release SA0 and SW2 should stay true
221 simuSetSwitch(5, 0); //SF down
222 logicalSwitchesTimerTick();
223 evalLogicalSwitches();
224 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
225 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
227 // now reset logical switches
228 logicalSwitchesReset();
229 logicalSwitchesTimerTick();
230 evalLogicalSwitches();
231 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
232 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
235 // second part with SAup
237 simuSetSwitch(0, 1); //SA up
238 simuSetSwitch(5, 0); //SF down
239 // EXPECT_EQ(getSwitch(SWSRC_SF2), false);
240 logicalSwitchesTimerTick();
241 evalLogicalSwitches();
242 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
243 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
245 // now trigger SFup, LS1 should become true
246 simuSetSwitch(5, 1); //SF up
247 // EXPECT_EQ(getSwitch(SWSRC_SF2), true);
248 logicalSwitchesTimerTick();
249 evalLogicalSwitches();
250 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
251 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
253 // now release SA0 and SW2 should stay true
254 simuSetSwitch(5, 0); //SF down
255 logicalSwitchesTimerTick();
256 evalLogicalSwitches();
257 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
258 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
260 // now reset logical switches
261 logicalSwitchesReset();
262 logicalSwitchesTimerTick();
263 evalLogicalSwitches();
264 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
265 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
268 // SF is kept up and SA is toggled
269 simuSetSwitch(0, -1); //SA down
270 simuSetSwitch(5, 1); //SF up
271 logicalSwitchesTimerTick();
272 evalLogicalSwitches();
273 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
274 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
276 simuSetSwitch(0, 1); //SA up
277 simuSetSwitch(5, 1); //SF up
278 logicalSwitchesTimerTick();
279 evalLogicalSwitches();
280 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
281 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
283 simuSetSwitch(0, -1); //SA down
284 simuSetSwitch(5, 1); //SF up
285 logicalSwitchesTimerTick();
286 evalLogicalSwitches();
287 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
288 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
290 //test what happens when EDGE condition is true and
291 //logical switches are reset - the switch should fire again
293 simuSetSwitch(0, 1); //SA up
294 simuSetSwitch(5, 1); //SF up
295 logicalSwitchesTimerTick();
296 evalLogicalSwitches();
297 EXPECT_EQ(getSwitch(SWSRC_SW1
), false); //switch will not trigger, because SF was already up
298 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
300 logicalSwitchesReset();
301 logicalSwitchesTimerTick();
302 evalLogicalSwitches();
303 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
304 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
306 logicalSwitchesTimerTick();
307 evalLogicalSwitches();
308 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
309 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
312 TEST(getSwitch
, edgeRelease
)
316 // test for issue #2728
317 // LS1 setup: EDGE SFup (0:release)
318 // LS2 setup: (EDGE SFup (0:release)) AND SAup
319 setLogicalSwitch(0, LS_FUNC_EDGE
, SWSRC_SF2
, -129, 0);
320 setLogicalSwitch(1, LS_FUNC_EDGE
, SWSRC_SF2
, -129, 0, 0, 0, SWSRC_SA2
);
322 simuSetSwitch(0, -1); //SA down
323 simuSetSwitch(5, 0); //SF down
324 logicalSwitchesTimerTick();
325 evalLogicalSwitches();
326 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
327 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
329 simuSetSwitch(5, 1); //SF up
330 logicalSwitchesTimerTick();
331 evalLogicalSwitches();
332 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
333 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
335 simuSetSwitch(5, 0); //SF down
336 logicalSwitchesTimerTick();
337 evalLogicalSwitches();
338 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
339 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
342 // second part with SAup
343 simuSetSwitch(0, 1); //SA up
344 simuSetSwitch(5, 0); //SF down
345 logicalSwitchesTimerTick();
346 evalLogicalSwitches();
347 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
348 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
350 simuSetSwitch(5, 1); //SF up
351 logicalSwitchesTimerTick();
352 evalLogicalSwitches();
353 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
354 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
356 simuSetSwitch(5, 0); //SF down
357 logicalSwitchesTimerTick();
358 evalLogicalSwitches();
359 EXPECT_EQ(getSwitch(SWSRC_SW1
), true);
360 EXPECT_EQ(getSwitch(SWSRC_SW2
), true);
362 // with switches reset both should remain false
363 logicalSwitchesReset();
364 logicalSwitchesTimerTick();
365 evalLogicalSwitches();
366 EXPECT_EQ(getSwitch(SWSRC_SW1
), false);
367 EXPECT_EQ(getSwitch(SWSRC_SW2
), false);
370 #endif // defined(PCBTARANIS)