From 17a28650701c3188d50b4bb066d0bf5164797557 Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 2 Jul 2014 21:50:25 +0200 Subject: [PATCH] Fixes #1424 --- radio/src/opentx.cpp | 33 +++++++++++++++++++++++---------- radio/src/opentx.h | 5 +++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index e79f27cb7..6735cd0c0 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -551,17 +551,17 @@ int getTrimValue(uint8_t phase, uint8_t idx) #endif } -void setTrimValue(uint8_t phase, uint8_t idx, int trim) -{ #if defined(PCBTARANIS) +bool setTrimValue(uint8_t phase, uint8_t idx, int trim) +{ for (uint8_t i=0; itrim[idx]; if (v.mode == TRIM_MODE_NONE) - return; + return false; unsigned int p = v.mode >> 1; if (p == phase || phase == 0) { v.value = trim; - break;; + break; } else if (v.mode % 2 == 0) { phase = p; @@ -571,7 +571,13 @@ void setTrimValue(uint8_t phase, uint8_t idx, int trim) break; } } -#elif defined(PCBSTD) + eeDirty(EE_MODEL); + return true; +} +#else +void setTrimValue(uint8_t phase, uint8_t idx, int trim) +{ +#if defined(PCBSTD) FlightModeData *p = flightModeAddress(phase); p->trim[idx] = (int8_t)(trim >> 2); idx <<= 1; @@ -582,6 +588,7 @@ void setTrimValue(uint8_t phase, uint8_t idx, int trim) #endif eeDirty(EE_MODEL); } +#endif #if !defined(PCBTARANIS) uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx) @@ -1320,12 +1327,18 @@ uint8_t checkTrim(uint8_t event) if (TRIM_REUSED(idx)) { SET_GVAR_VALUE(trimGvar[idx], phase, after); } - else { - setTrimValue(phase, idx, after); - } -#else - setTrimValue(phase, idx, after); + else #endif + { +#if defined(PCBTARANIS) + if (!setTrimValue(phase, idx, after)) { + // we don't play a beep, so we exit now the function + return; + } +#else + setTrimValue(phase, idx, after); +#endif + } #if defined(AUDIO) // toneFreq higher/lower according to trim position diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 8b754e355..0a576ff26 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -753,7 +753,12 @@ int8_t getMovedSwitch(); trim_t getRawTrimValue(uint8_t phase, uint8_t idx); int getTrimValue(uint8_t phase, uint8_t idx); + +#if defined(PCBTARANIS) +bool setTrimValue(uint8_t phase, uint8_t idx, int trim); +#else void setTrimValue(uint8_t phase, uint8_t idx, int trim); +#endif #if defined(ROTARY_ENCODERS) int16_t getRotaryEncoder(uint8_t idx);