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
+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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user