feat(radio): refactor of switch handling to better support customisable switches (#6095)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
3djc
elecpower
parent
28833f42e6
commit
0c8c39b134
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "gtests.h"
|
||||
|
||||
class SpecialFunctionsTest : public OpenTxTest {};
|
||||
class SpecialFunctionsTest : public EdgeTxTest {};
|
||||
|
||||
TEST_F(SpecialFunctionsTest, SwitchFiledSize)
|
||||
{
|
||||
@@ -38,22 +38,27 @@ TEST_F(SpecialFunctionsTest, SwitchFiledSize)
|
||||
|
||||
TEST_F(SpecialFunctionsTest, FlightReset)
|
||||
{
|
||||
g_model.customFn[0].swtch = SWSRC_FIRST_SWITCH;
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
int swPos = (sw * 3) + SWSRC_FIRST_SWITCH;
|
||||
|
||||
g_model.customFn[0].swtch = swPos;
|
||||
g_model.customFn[0].func = FUNC_RESET;
|
||||
g_model.customFn[0].all.val = FUNC_RESET_FLIGHT;
|
||||
g_model.customFn[0].active = true;
|
||||
|
||||
|
||||
mainRequestFlags = 0;
|
||||
simuSetSwitch(0, 0);
|
||||
EXPECT_EQ(false, getSwitch(SWSRC_FIRST_SWITCH));
|
||||
simuSetSwitch(sw, 0);
|
||||
EXPECT_EQ(false, getSwitch(swPos));
|
||||
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), false);
|
||||
|
||||
// now trigger SA0
|
||||
simuSetSwitch(0, -1);
|
||||
EXPECT_EQ(true, getSwitch(SWSRC_FIRST_SWITCH));
|
||||
simuSetSwitch(sw, -1);
|
||||
EXPECT_EQ(true, getSwitch(swPos));
|
||||
|
||||
// flightReset() should be called
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
@@ -68,9 +73,15 @@ TEST_F(SpecialFunctionsTest, FlightReset)
|
||||
#if defined(GVARS)
|
||||
TEST_F(SpecialFunctionsTest, GvarsInc)
|
||||
{
|
||||
simuSetSwitch(0, 0); // SA-
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
int swPos = (sw * 3) + SWSRC_FIRST_SWITCH;
|
||||
|
||||
g_model.customFn[0].swtch = SWSRC_FIRST_SWITCH;
|
||||
simuSetSwitch(sw, 0); // SA-
|
||||
|
||||
g_model.customFn[0].swtch = swPos;
|
||||
g_model.customFn[0].func = FUNC_ADJUST_GVAR;
|
||||
g_model.customFn[0].all.mode = FUNC_ADJUST_GVAR_INCDEC;
|
||||
g_model.customFn[0].all.param = 0; // GV1
|
||||
@@ -82,39 +93,39 @@ TEST_F(SpecialFunctionsTest, GvarsInc)
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 10);
|
||||
|
||||
// now trigger SA0
|
||||
simuSetSwitch(0, -1); // SAdown
|
||||
simuSetSwitch(sw, -1); // SAdown
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 9);
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 9);
|
||||
|
||||
simuSetSwitch(0, 0); // SA-
|
||||
simuSetSwitch(sw, 0); // SA-
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 9);
|
||||
|
||||
simuSetSwitch(0, -1); // SAdown
|
||||
simuSetSwitch(sw, -1); // SAdown
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 8);
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 8);
|
||||
|
||||
simuSetSwitch(0, 0); // SA-
|
||||
simuSetSwitch(sw, 0); // SA-
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 8);
|
||||
|
||||
g_model.customFn[0].all.val = 10; // inc/dec value
|
||||
|
||||
simuSetSwitch(0, -1); // SAdown
|
||||
simuSetSwitch(sw, -1); // SAdown
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 18);
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 18);
|
||||
|
||||
simuSetSwitch(0, 0); // SA-
|
||||
simuSetSwitch(sw, 0); // SA-
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 18);
|
||||
|
||||
simuSetSwitch(0, -1); // SAdown
|
||||
simuSetSwitch(sw, -1); // SAdown
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
EXPECT_EQ(g_model.flightModeData[0].gvars[0], 28);
|
||||
evalFunctions(g_model.customFn, modelFunctionsContext);
|
||||
|
||||
@@ -129,6 +129,14 @@ uint16_t simu_get_analog(uint8_t idx)
|
||||
|
||||
void simuQueueAudio(const uint8_t*, uint32_t) {}
|
||||
|
||||
void fsLedOn(uint8_t idx)
|
||||
{
|
||||
}
|
||||
|
||||
void fsLedOff(uint8_t idx)
|
||||
{
|
||||
}
|
||||
|
||||
static char _stringResult[200];
|
||||
|
||||
const char * nchar2string(const char * string, int size)
|
||||
|
||||
@@ -44,8 +44,27 @@ extern const char * nchar2string(const char * string, int size);
|
||||
#define EXPECT_ZSTREQ(c_string, z_string) EXPECT_STREQ(c_string, zchar2string(z_string, sizeof(z_string)))
|
||||
#define EXPECT_STRNEQ(c_string, n_string) EXPECT_STREQ(c_string, nchar2string(n_string, sizeof(n_string)))
|
||||
|
||||
#if defined(RADIO_GX12)
|
||||
#define RADIO_RESET() \
|
||||
g_eeGeneral.switchConfig = 0x00007bff
|
||||
g_eeGeneral.switchSetType(0, SWITCH_2POS); \
|
||||
g_eeGeneral.switchSetType(1, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(2, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(3, SWITCH_2POS); \
|
||||
g_eeGeneral.switchSetType(4, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(5, SWITCH_2POS); \
|
||||
g_eeGeneral.switchSetType(6, SWITCH_TOGGLE); \
|
||||
g_eeGeneral.switchSetType(7, SWITCH_TOGGLE)
|
||||
#else
|
||||
#define RADIO_RESET() \
|
||||
g_eeGeneral.switchSetType(0, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(1, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(2, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(3, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(4, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(5, SWITCH_2POS); \
|
||||
g_eeGeneral.switchSetType(6, SWITCH_3POS); \
|
||||
g_eeGeneral.switchSetType(7, SWITCH_TOGGLE)
|
||||
#endif
|
||||
|
||||
inline void SYSTEM_RESET()
|
||||
{
|
||||
@@ -54,7 +73,7 @@ inline void SYSTEM_RESET()
|
||||
#endif
|
||||
generalDefault();
|
||||
g_eeGeneral.templateSetup = 0;
|
||||
for (int i=0; i<switchGetMaxSwitches(); i++) {
|
||||
for (int i=0; i<switchGetMaxAllSwitches(); i++) {
|
||||
simuSetSwitch(i, -1);
|
||||
}
|
||||
}
|
||||
@@ -91,7 +110,7 @@ inline void TELEMETRY_RESET()
|
||||
memclear(g_model.telemetrySensors, sizeof(g_model.telemetrySensors));
|
||||
}
|
||||
|
||||
class OpenTxTest : public testing::Test
|
||||
class EdgeTxTest : public testing::Test
|
||||
{
|
||||
protected: // You should make the members protected s.t. they can be
|
||||
// accessed from sub-classes.
|
||||
|
||||
+54
-34
@@ -22,8 +22,8 @@
|
||||
#include "gtests.h"
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
class TrimsTest : public OpenTxTest {};
|
||||
class MixerTest : public OpenTxTest {};
|
||||
class TrimsTest : public EdgeTxTest {};
|
||||
class MixerTest : public EdgeTxTest {};
|
||||
|
||||
#define CHECK_NO_MOVEMENT(channel, value, duration) \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
@@ -660,7 +660,7 @@ TEST_F(MixerTest, RecursiveAddChannel)
|
||||
|
||||
TEST_F(MixerTest, RecursiveAddChannelAfterInactivePhase)
|
||||
{
|
||||
if (switchGetMaxSwitches() < 4) return;
|
||||
if (switchGetMaxAllSwitches() < 4) return;
|
||||
|
||||
g_model.flightModeData[1].swtch = SWSRC_FIRST_SWITCH + 1;
|
||||
g_model.mixData[0].destCh = 0;
|
||||
@@ -711,22 +711,26 @@ TEST_F(MixerTest, SlowOnPhase)
|
||||
|
||||
TEST_F(MixerTest, SlowOnSwitchSource)
|
||||
{
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
if (sw >= switchGetMaxAllSwitches()) return;
|
||||
|
||||
g_model.mixData[0].destCh = 0;
|
||||
g_model.mixData[0].mltpx = MLTPX_ADD;
|
||||
g_eeGeneral.switchConfig = 0x03;
|
||||
g_model.mixData[0].srcRaw = MIXSRC_FIRST_SWITCH;
|
||||
int switchIndex = 0;
|
||||
g_model.mixData[0].srcRaw = sw + MIXSRC_FIRST_SWITCH;
|
||||
g_model.mixData[0].weight = makeSourceNumVal(100);
|
||||
g_model.mixData[0].speedUp = 50;
|
||||
g_model.mixData[0].speedDown = 50;
|
||||
|
||||
s_mixer_first_run_done = true;
|
||||
|
||||
simuSetSwitch(switchIndex, -1);
|
||||
simuSetSwitch(sw, -1);
|
||||
CHECK_SLOW_MOVEMENT(0, -1, 250, 500);
|
||||
EXPECT_EQ(chans[0], -CHANNEL_MAX);
|
||||
|
||||
simuSetSwitch(switchIndex, 1);
|
||||
simuSetSwitch(sw, 1);
|
||||
CHECK_SLOW_MOVEMENT(0, +1, 500, 500);
|
||||
}
|
||||
|
||||
@@ -755,11 +759,15 @@ TEST_F(MixerTest, SlowOnPhasePrec10ms)
|
||||
|
||||
TEST_F(MixerTest, SlowOnSwitchSourcePrec10ms)
|
||||
{
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
if (sw >= switchGetMaxAllSwitches()) return;
|
||||
|
||||
g_model.mixData[0].destCh = 0;
|
||||
g_model.mixData[0].mltpx = MLTPX_ADD;
|
||||
g_eeGeneral.switchConfig = 0x03;
|
||||
g_model.mixData[0].srcRaw = MIXSRC_FIRST_SWITCH;
|
||||
int switchIndex = 0;
|
||||
g_model.mixData[0].srcRaw = sw + MIXSRC_FIRST_SWITCH;
|
||||
g_model.mixData[0].weight = makeSourceNumVal(100);
|
||||
g_model.mixData[0].speedUp = 50;
|
||||
g_model.mixData[0].speedDown = 50;
|
||||
@@ -767,11 +775,11 @@ TEST_F(MixerTest, SlowOnSwitchSourcePrec10ms)
|
||||
|
||||
s_mixer_first_run_done = true;
|
||||
|
||||
simuSetSwitch(switchIndex, -1);
|
||||
simuSetSwitch(sw, -1);
|
||||
CHECK_SLOW_MOVEMENT(0, -1, 25, 50);
|
||||
EXPECT_EQ(chans[0], -CHANNEL_MAX);
|
||||
|
||||
simuSetSwitch(switchIndex, 1);
|
||||
simuSetSwitch(sw, 1);
|
||||
CHECK_SLOW_MOVEMENT(0, +1, 50, 50);
|
||||
}
|
||||
|
||||
@@ -790,61 +798,66 @@ TEST_F(MixerTest, SlowDisabledOnStartup)
|
||||
|
||||
TEST_F(MixerTest, DelayOnSwitch)
|
||||
{
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
if (sw >= switchGetMaxAllSwitches()) return;
|
||||
int swPos = (sw * 3) + SWSRC_FIRST_SWITCH + 2;
|
||||
|
||||
g_model.mixData[0].destCh = 0;
|
||||
g_model.mixData[0].mltpx = MLTPX_ADD;
|
||||
g_model.mixData[0].srcRaw = MIXSRC_MAX;
|
||||
g_model.mixData[0].weight = makeSourceNumVal(100);
|
||||
g_model.mixData[0].swtch = SWSRC_FIRST_SWITCH + 2;
|
||||
g_model.mixData[0].swtch = swPos;
|
||||
g_model.mixData[0].delayUp = 50;
|
||||
g_model.mixData[0].delayDown = 50;
|
||||
|
||||
int switch_index = 0;
|
||||
simuSetSwitch(switch_index, -1);
|
||||
simuSetSwitch(sw, -1);
|
||||
|
||||
evalFlightModeMixes(e_perout_mode_normal, 0);
|
||||
EXPECT_EQ(chans[0], 0);
|
||||
|
||||
simuSetSwitch(switch_index, 1);
|
||||
simuSetSwitch(sw, 1);
|
||||
CHECK_DELAY(0, 500);
|
||||
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1);
|
||||
EXPECT_EQ(chans[0], CHANNEL_MAX);
|
||||
|
||||
auto sw_cfg = (SwitchConfig)SWITCH_CONFIG(switch_index);
|
||||
if (sw_cfg == SWITCH_3POS) {
|
||||
simuSetSwitch(switch_index, 0);
|
||||
CHECK_DELAY(0, 500);
|
||||
simuSetSwitch(sw, 0);
|
||||
CHECK_DELAY(0, 500);
|
||||
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1);
|
||||
EXPECT_EQ(chans[0], 0);
|
||||
}
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1);
|
||||
EXPECT_EQ(chans[0], 0);
|
||||
}
|
||||
|
||||
TEST_F(MixerTest, DelayOnSwitch2)
|
||||
{
|
||||
g_eeGeneral.switchConfig = SWITCH_3POS;
|
||||
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
if (sw >= switchGetMaxAllSwitches()) return;
|
||||
|
||||
g_model.mixData[0].destCh = 0;
|
||||
g_model.mixData[0].mltpx = MLTPX_ADD;
|
||||
g_model.mixData[0].srcRaw = MIXSRC_FIRST_SWITCH;
|
||||
g_model.mixData[0].srcRaw = sw + MIXSRC_FIRST_SWITCH;
|
||||
g_model.mixData[0].weight = makeSourceNumVal(100);
|
||||
// g_model.mixData[0].swtch = SWSRC_ON;
|
||||
g_model.mixData[0].delayUp = 50;
|
||||
g_model.mixData[0].delayDown = 50;
|
||||
|
||||
int switch_index = 0;
|
||||
simuSetSwitch(switch_index, -1);
|
||||
simuSetSwitch(sw, -1);
|
||||
|
||||
evalFlightModeMixes(e_perout_mode_normal, 0);
|
||||
EXPECT_EQ(chans[0], 0);
|
||||
|
||||
simuSetSwitch(switch_index, 1);
|
||||
simuSetSwitch(sw, 1);
|
||||
CHECK_DELAY(0, 500);
|
||||
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1);
|
||||
EXPECT_EQ(chans[0], CHANNEL_MAX);
|
||||
|
||||
simuSetSwitch(switch_index, 0);
|
||||
simuSetSwitch(sw, 0);
|
||||
CHECK_DELAY(0, 500);
|
||||
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1);
|
||||
@@ -1018,11 +1031,18 @@ TEST(Trainer, UnpluggedTest)
|
||||
|
||||
TEST_F(MixerTest, flightModeTransition)
|
||||
{
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
if (sw >= switchGetMaxAllSwitches()) return;
|
||||
int swPos = (sw * 3) + SWSRC_FIRST_SWITCH + 2;
|
||||
|
||||
SYSTEM_RESET();
|
||||
MODEL_RESET();
|
||||
MIXER_RESET();
|
||||
setModelDefaults();
|
||||
g_model.flightModeData[1].swtch = SWSRC_FIRST_SWITCH + 2;
|
||||
g_model.flightModeData[1].swtch = swPos;
|
||||
g_model.flightModeData[0].fadeIn = 100;
|
||||
g_model.flightModeData[0].fadeOut = 100;
|
||||
g_model.flightModeData[1].fadeIn = 100;
|
||||
@@ -1038,7 +1058,7 @@ TEST_F(MixerTest, flightModeTransition)
|
||||
g_model.mixData[1].flightModes = 0b11101;
|
||||
g_model.mixData[1].weight = makeSourceNumVal(-10);
|
||||
evalMixes(1);
|
||||
simuSetSwitch(0, 1);
|
||||
simuSetSwitch(sw, 1);
|
||||
CHECK_FLIGHT_MODE_TRANSITION(0, 1000, 1024, -102);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,22 +47,28 @@ TEST(getSwitch, OldTypeStickyCSW)
|
||||
MODEL_RESET();
|
||||
MIXER_RESET();
|
||||
|
||||
setLogicalSwitch(0, LS_FUNC_AND, SWSRC_FIRST_SWITCH, SWSRC_NONE);
|
||||
int sw;
|
||||
for (sw = 0; sw < switchGetMaxAllSwitches(); sw += 1)
|
||||
if (g_model.getSwitchType(sw) == SWITCH_3POS)
|
||||
break;
|
||||
int swPos = (sw * 3) + SWSRC_FIRST_SWITCH;
|
||||
|
||||
setLogicalSwitch(0, LS_FUNC_AND, swPos, SWSRC_NONE);
|
||||
setLogicalSwitch(1, LS_FUNC_OR, SWSRC_SW1, SWSRC_SW2);
|
||||
|
||||
simuSetSwitch(0, 0);
|
||||
simuSetSwitch(sw, 0);
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
// now trigger SA0, both switches should become true
|
||||
simuSetSwitch(0, -1);
|
||||
simuSetSwitch(sw, -1);
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), true);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), true);
|
||||
|
||||
// now release SA0 and SW2 should stay true
|
||||
simuSetSwitch(0, 0);
|
||||
simuSetSwitch(sw, 0);
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), true);
|
||||
@@ -135,38 +141,41 @@ TEST(evalLogicalSwitches, playFile)
|
||||
#undef MODELNAME
|
||||
}
|
||||
|
||||
#define SWSRC_SA2 (SWSRC_FIRST_SWITCH + 2)
|
||||
#define SWSRC_SD2 (SWSRC_FIRST_SWITCH + 3 * 3 + 2)
|
||||
|
||||
TEST(getSwitch, edgeInstant)
|
||||
{
|
||||
if (switchGetMaxSwitches() < 6) return;
|
||||
int sw1, sw2;
|
||||
for (sw1 = 0; sw1 < switchGetMaxAllSwitches(); sw1 += 1)
|
||||
if (g_model.getSwitchType(sw1) == SWITCH_3POS)
|
||||
break;
|
||||
for (sw2 = sw1 + 1; sw2 < switchGetMaxAllSwitches(); sw2 += 1)
|
||||
if (g_model.getSwitchType(sw2) == SWITCH_3POS)
|
||||
break;
|
||||
int sw1Pos = (sw1 * 3) + SWSRC_FIRST_SWITCH;
|
||||
int sw2Pos = (sw2 * 3) + SWSRC_FIRST_SWITCH;
|
||||
|
||||
MODEL_RESET();
|
||||
MIXER_RESET();
|
||||
// LS1 setup: EDGE SDup (0:instant)
|
||||
// LS2 setup: (EDGE SDup (0:instant)) AND SAup
|
||||
setLogicalSwitch(0, LS_FUNC_EDGE, SWSRC_SD2, -129, -1);
|
||||
setLogicalSwitch(1, LS_FUNC_EDGE, SWSRC_SD2, -129, -1, 0, 0, SWSRC_SA2);
|
||||
// LS1 setup: EDGE SD down (0:instant)
|
||||
// LS2 setup: (EDGE SD down (0:instant)) AND SA down
|
||||
setLogicalSwitch(0, LS_FUNC_EDGE, sw2Pos + 2, -129, -1);
|
||||
setLogicalSwitch(1, LS_FUNC_EDGE, sw2Pos + 2, -129, -1, 0, 0, sw1Pos + 2);
|
||||
|
||||
simuSetSwitch(0, -1); //SA down
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
// EXPECT_EQ(getSwitch(SWSRC_SD2), false);
|
||||
simuSetSwitch(sw1, -1); //SA up
|
||||
simuSetSwitch(sw2, 0); //SD mid
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
// now trigger SFup, LS1 should become true
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
// EXPECT_EQ(getSwitch(SWSRC_SD2), true);
|
||||
// now trigger SD donw, LS1 should become true
|
||||
simuSetSwitch(sw2, 1); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), true);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
// now release SA0 and SW2 should stay true
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
// now release SD and LS1 should become false
|
||||
simuSetSwitch(sw2, 0); //SD mid
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
@@ -179,27 +188,24 @@ TEST(getSwitch, edgeInstant)
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
// second part with SA down
|
||||
|
||||
// second part with SAup
|
||||
|
||||
simuSetSwitch(0, 1); //SA up
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
// EXPECT_EQ(getSwitch(SWSRC_SD2), false);
|
||||
simuSetSwitch(sw1, 1); //SA down
|
||||
simuSetSwitch(sw2, 0); //SD mid
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
// now trigger SFup, LS1 should become true
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
// EXPECT_EQ(getSwitch(SWSRC_SD2), true);
|
||||
// now trigger SD down, LS1 & LS2 should become true
|
||||
simuSetSwitch(sw2, 1); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), true);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), true);
|
||||
|
||||
// now release SA0 and SW2 should stay true
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
// now release SA and LS1 & LS2 should stay false
|
||||
simuSetSwitch(sw2, 0); //SD mid
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
@@ -213,23 +219,23 @@ TEST(getSwitch, edgeInstant)
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
// now bug #2939
|
||||
// SD is kept up and SA is toggled
|
||||
simuSetSwitch(0, -1); //SA down
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
// SD is kept down and SA is toggled
|
||||
simuSetSwitch(sw1, -1); //SA up
|
||||
simuSetSwitch(sw2, 1); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), true);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
simuSetSwitch(0, 1); //SA up
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
simuSetSwitch(sw1, 1); //SA down
|
||||
simuSetSwitch(sw2, 1); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
simuSetSwitch(0, -1); //SA down
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
simuSetSwitch(sw1, -1); //SA up
|
||||
simuSetSwitch(sw2, 1); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
@@ -238,8 +244,8 @@ TEST(getSwitch, edgeInstant)
|
||||
//test what happens when EDGE condition is true and
|
||||
//logical switches are reset - the switch should fire again
|
||||
|
||||
simuSetSwitch(0, 1); //SA up
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
simuSetSwitch(sw1, 1); //SA down
|
||||
simuSetSwitch(sw2, 1); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false); //switch will not trigger, because SF was already up
|
||||
@@ -259,30 +265,38 @@ TEST(getSwitch, edgeInstant)
|
||||
|
||||
TEST(getSwitch, edgeRelease)
|
||||
{
|
||||
if (switchGetMaxSwitches() < 6) return;
|
||||
|
||||
int sw1, sw2;
|
||||
for (sw1 = 0; sw1 < switchGetMaxAllSwitches(); sw1 += 1)
|
||||
if (g_model.getSwitchType(sw1) == SWITCH_3POS)
|
||||
break;
|
||||
for (sw2 = sw1 + 1; sw2 < switchGetMaxAllSwitches(); sw2 += 1)
|
||||
if (g_model.getSwitchType(sw2) == SWITCH_3POS)
|
||||
break;
|
||||
int sw1Pos = (sw1 * 3) + SWSRC_FIRST_SWITCH;
|
||||
int sw2Pos = (sw2 * 3) + SWSRC_FIRST_SWITCH;
|
||||
|
||||
MODEL_RESET();
|
||||
MIXER_RESET();
|
||||
// test for issue #2728
|
||||
// LS1 setup: EDGE SDup (0:release)
|
||||
// LS2 setup: (EDGE SDup (0:release)) AND SAup
|
||||
setLogicalSwitch(0, LS_FUNC_EDGE, SWSRC_SD2, -129, 0);
|
||||
setLogicalSwitch(1, LS_FUNC_EDGE, SWSRC_SD2, -129, 0, 0, 0, SWSRC_SA2 );
|
||||
setLogicalSwitch(0, LS_FUNC_EDGE, sw2Pos + 2, -129, 0);
|
||||
setLogicalSwitch(1, LS_FUNC_EDGE, sw2Pos + 2, -129, 0, 0, 0, sw1Pos + 2 );
|
||||
|
||||
simuSetSwitch(0, -1); //SA down
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
simuSetSwitch(sw1, -1); //SA down
|
||||
simuSetSwitch(sw2, 0); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
simuSetSwitch(sw2, 1); //SD up
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
simuSetSwitch(sw2, 0); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), true);
|
||||
@@ -290,20 +304,20 @@ TEST(getSwitch, edgeRelease)
|
||||
|
||||
|
||||
// second part with SAup
|
||||
simuSetSwitch(0, 1); //SA up
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
simuSetSwitch(sw1, 1); //SA up
|
||||
simuSetSwitch(sw2, 0); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
simuSetSwitch(3, 1); //SD up
|
||||
simuSetSwitch(sw2, 1); //SD up
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), false);
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW2), false);
|
||||
|
||||
simuSetSwitch(3, 0); //SD down
|
||||
simuSetSwitch(sw2, 0); //SD down
|
||||
logicalSwitchesTimerTick();
|
||||
evalLogicalSwitches();
|
||||
EXPECT_EQ(getSwitch(SWSRC_SW1), true);
|
||||
@@ -327,7 +341,7 @@ TEST(FlexSwitches, switchGetPosition)
|
||||
switchInit();
|
||||
|
||||
auto sw_idx = boardGetMaxSwitches();
|
||||
auto sw_name = switchGetName(sw_idx);
|
||||
auto sw_name = switchGetDefaultName(sw_idx);
|
||||
EXPECT_STREQ("FL1", sw_name);
|
||||
EXPECT_FALSE(switchIsFlexValid(sw_idx));
|
||||
|
||||
@@ -358,8 +372,8 @@ TEST(FlexSwitches, getValue)
|
||||
auto sw_idx = boardGetMaxSwitches();
|
||||
switchConfigFlex(sw_idx, 0);
|
||||
|
||||
g_eeGeneral.switchConfig = (swconfig_t)SWITCH_3POS << (sw_idx * SW_CFG_BITS);
|
||||
EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(sw_idx));
|
||||
g_eeGeneral.switchSetType(sw_idx, SWITCH_3POS);
|
||||
EXPECT_EQ(SWITCH_3POS, g_model.getSwitchType(sw_idx));
|
||||
|
||||
auto offset = adcGetInputOffset(ADC_INPUT_FLEX);
|
||||
anaSetFiltered(offset, -1024);
|
||||
@@ -371,8 +385,8 @@ TEST(FlexSwitches, getValue)
|
||||
anaSetFiltered(offset, +1024);
|
||||
EXPECT_EQ(+1024, getValue(MIXSRC_FIRST_SWITCH + sw_idx));
|
||||
|
||||
g_eeGeneral.switchConfig = (swconfig_t)SWITCH_2POS << (sw_idx * SW_CFG_BITS);
|
||||
EXPECT_EQ(SWITCH_2POS, SWITCH_CONFIG(sw_idx));
|
||||
g_eeGeneral.switchSetType(sw_idx, SWITCH_2POS);
|
||||
EXPECT_EQ(SWITCH_2POS, g_model.getSwitchType(sw_idx));
|
||||
|
||||
anaSetFiltered(offset, -1024);
|
||||
EXPECT_EQ(-1024, getValue(MIXSRC_FIRST_SWITCH + sw_idx));
|
||||
@@ -395,8 +409,8 @@ TEST(FlexSwitches, getSwitch)
|
||||
auto sw_idx = boardGetMaxSwitches();
|
||||
switchConfigFlex(sw_idx, 0);
|
||||
|
||||
g_eeGeneral.switchConfig = (swconfig_t)SWITCH_3POS << (sw_idx * SW_CFG_BITS);
|
||||
EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(sw_idx));
|
||||
g_eeGeneral.switchSetType(sw_idx, SWITCH_3POS);
|
||||
EXPECT_EQ(SWITCH_3POS, g_model.getSwitchType(sw_idx));
|
||||
|
||||
auto offset = adcGetInputOffset(ADC_INPUT_FLEX);
|
||||
anaSetFiltered(offset, -1024);
|
||||
|
||||
Reference in New Issue
Block a user