From 8efdd3bc571fd879ba02326b47c68d3ab8ce5f16 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Mon, 9 Oct 2017 22:13:59 +0100 Subject: [PATCH] Tidy rc_controls.c --- src/main/fc/rc_controls.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/fc/rc_controls.c b/src/main/fc/rc_controls.c index 475de617c..5e39160be 100644 --- a/src/main/fc/rc_controls.c +++ b/src/main/fc/rc_controls.c @@ -135,8 +135,6 @@ void processRcStickPositions(throttleStatus_e throttleStatus) // an extra guard for disarming through switch to prevent that one frame can disarm it static uint8_t rcDisarmTicks; static bool doNotRepeat; - uint8_t stTmp = 0; - int i; #ifdef CMS if (cmsInMenu) { @@ -145,16 +143,20 @@ void processRcStickPositions(throttleStatus_e throttleStatus) #endif // checking sticks positions - for (i = 0; i < 4; i++) { + uint8_t stTmp = 0; + for (int i = 0; i < 4; i++) { stTmp >>= 2; - if (rcData[i] > rxConfig()->mincheck) + if (rcData[i] > rxConfig()->mincheck) { stTmp |= 0x80; // check for MIN - if (rcData[i] < rxConfig()->maxcheck) + } + if (rcData[i] < rxConfig()->maxcheck) { stTmp |= 0x40; // check for MAX + } } if (stTmp == rcSticks) { - if (rcDelayMs <= INT16_MAX - (getTaskDeltaTime(TASK_SELF) / 1000)) + if (rcDelayMs <= INT16_MAX - (getTaskDeltaTime(TASK_SELF) / 1000)) { rcDelayMs += getTaskDeltaTime(TASK_SELF) / 1000; + } } else { rcDelayMs = 0; doNotRepeat = false; @@ -238,15 +240,16 @@ void processRcStickPositions(throttleStatus_e throttleStatus) } // Multiple configuration profiles - i = 0; - if (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_LO) // ROLL left -> Profile 1 - i = 1; - else if (rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_CE) // PITCH up -> Profile 2 - i = 2; - else if (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_HI) // ROLL right -> Profile 3 - i = 3; - if (i) { - changePidProfile(i - 1); + int newPidProfile = 0; + if (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_LO) { // ROLL left -> Profile 1 + newPidProfile = 1; + } else if (rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_CE) { // PITCH up -> Profile 2 + newPidProfile = 2; + } else if (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_HI) { // ROLL right -> Profile 3 + newPidProfile = 3; + } + if (newPidProfile) { + changePidProfile(newPidProfile - 1); return; } @@ -269,7 +272,6 @@ void processRcStickPositions(throttleStatus_e throttleStatus) // Accelerometer Trim - rollAndPitchTrims_t accelerometerTrimsDelta; memset(&accelerometerTrimsDelta, 0, sizeof(accelerometerTrimsDelta));