Skip to content

Commit

Permalink
fix: Throttle stick not being detected properly (#3733)
Browse files Browse the repository at this point in the history
* Fix thottle timer

* More THR source fixes
  • Loading branch information
3djc committed Jul 3, 2023
1 parent 632eceb commit d60b544
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions radio/src/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,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 != THR_STICK) {
if (g_eeGeneral.stickDeadZone && ch != inputMappingConvertMode(inputMappingGetThrottle())) {
if (v > P_OFFSET) {
// y=ax+b
v = (int)((aParam * (float)v) - bParam);
Expand All @@ -540,7 +540,7 @@ void evalInputs(uint8_t mode)
}
#endif

if (g_model.throttleReversed && ch==THR_STICK) {
if (g_model.throttleReversed && ch==inputMappingConvertMode(inputMappingGetThrottle())) {
v = -v;
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ void doMixerPeriodicUpdates()
val=0; // prevent val be negative, which would corrupt throttle trace and timers; could occur if safetyswitch is smaller than limits
}
else {
val = RESX + calibratedAnalogs[g_model.thrTraceSrc == 0 ? THR_STICK : g_model.thrTraceSrc + MAX_STICKS - 1];
val = RESX + calibratedAnalogs[g_model.thrTraceSrc == 0 ? inputMappingConvertMode(inputMappingGetThrottle()) : g_model.thrTraceSrc + MAX_STICKS - 1];
}

val >>= (RESX_SHIFT-6); // calibrate it (resolution increased by factor 4)
Expand Down
4 changes: 2 additions & 2 deletions radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ void checkTrims()
#else
phase = getTrimFlightMode(mixerCurrentFlightMode, idx);
before = getTrimValue(phase, idx);
thro = (idx==THR_STICK && g_model.thrTrim);
thro = (idx==inputMappingConvertMode(inputMappingGetThrottle()) && g_model.thrTrim);
#endif
int8_t trimInc = g_model.trimInc + 1;
int8_t v = (trimInc==-1) ? min(32, abs(before)/4+1) : (1 << trimInc); // TODO flash saving if (trimInc < 0)
Expand Down Expand Up @@ -1223,7 +1223,7 @@ void instantTrim()

auto controls = adcGetMaxInputs(ADC_INPUT_MAIN);
for (uint8_t stick = 0; stick < controls; stick++) {
if (stick != THR_STICK) { // don't instant trim the throttle stick
if (stick != inputMappingConvertMode(inputMappingGetThrottle())) { // don't instant trim the throttle stick
bool addTrim = false;
int16_t delta = 0;
uint8_t trimFlightMode = getTrimFlightMode(mixerCurrentFlightMode, stick);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ getvalue_t getValueForLogicalSwitch(mixsrc_t i)
int8_t trimIdx = virtualInputsTrims[i-MIXSRC_FIRST_INPUT];
if (trimIdx >= 0) {
int16_t trim = trims[trimIdx];
if (trimIdx == THR_STICK && g_model.throttleReversed)
if (trimIdx == inputMappingConvertMode(inputMappingGetThrottle()) && g_model.throttleReversed)
result -= trim;
else
result += trim;
Expand Down

0 comments on commit d60b544

Please sign in to comment.