From 19126976165ca052e3d9676385978a55a5fea3c3 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 30 Jul 2023 13:37:21 +0200 Subject: [PATCH] fix: Throttle invert and gimbal dead zone (#3864) --- radio/src/mixer.cpp | 4 ++-- radio/src/tests/mixer.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index ed9977728..8ab3f0737 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -526,7 +526,7 @@ void evalInputs(uint8_t mode) #if defined(STICK_DEAD_ZONE) // dead zone invented by FlySky in my opinion it should goes into ADC // float calculations are not efficient - if (g_eeGeneral.stickDeadZone && ch != inputMappingConvertMode(inputMappingGetThrottle())) { + if (g_eeGeneral.stickDeadZone && ch != inputMappingGetThrottle()) { if (v > P_OFFSET) { // y=ax+b v = (int)((aParam * (float)v) - bParam); @@ -539,7 +539,7 @@ void evalInputs(uint8_t mode) } #endif - if (g_model.throttleReversed && ch==inputMappingConvertMode(inputMappingGetThrottle())) { + if (g_model.throttleReversed && ch == inputMappingGetThrottle()) { v = -v; } diff --git a/radio/src/tests/mixer.cpp b/radio/src/tests/mixer.cpp index 1ab5a874a..a7abe04ac 100644 --- a/radio/src/tests/mixer.cpp +++ b/radio/src/tests/mixer.cpp @@ -75,6 +75,30 @@ class MixerTest : public OpenTxTest {}; #define MIXSRC_CYC2 (MIXSRC_FIRST_HELI + 1) #define MIXSRC_CYC3 (MIXSRC_FIRST_HELI + 2) +TEST_F(MixerTest, throttleInvert) +{ + // Mode 1 / reversed + g_eeGeneral.stickMode = 0; + g_model.throttleReversed = 1; + anaSetFiltered(inputMappingConvertMode(THR_STICK), -1024); + evalMixes(1); + EXPECT_EQ(channelOutputs[2], +1024); + + // Mode 2 / reversed + g_eeGeneral.stickMode = 1; + g_model.throttleReversed = 1; + anaSetFiltered(inputMappingConvertMode(THR_STICK), -1024); + evalMixes(1); + EXPECT_EQ(channelOutputs[2], +1024); + + // Mode 2 / normal + g_eeGeneral.stickMode = 1; + g_model.throttleReversed = 0; + anaSetFiltered(inputMappingConvertMode(THR_STICK), -1024); + evalMixes(1); + EXPECT_EQ(channelOutputs[2], -1024); +} + TEST_F(TrimsTest, throttleTrim) { g_model.thrTrim = 1;