From 1b79cbd232c04fbaa3f85e51adb16da7d2a7050d Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Wed, 30 Aug 2023 23:29:46 +0100 Subject: [PATCH] Add define for functions only --- src/main/fc/fc_core.c | 17 ++++++++++------- src/main/fc/fc_msp_box.c | 5 ++++- src/main/fc/multifunction.c | 3 +++ src/main/fc/multifunction.h | 3 +++ src/main/io/osd.c | 4 +++- src/main/navigation/navigation.c | 16 +++++++++++----- src/main/target/common.h | 1 + 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index 8058c418ac..fc9b57dea6 100755 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -177,7 +177,7 @@ int16_t getAxisRcCommand(int16_t rawData, int16_t rate, int16_t deadband) { int16_t stickDeflection = 0; -#if defined(SITL_BUILD) // Workaround due to strange bug in GCC > 10.2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108914 +#if defined(SITL_BUILD) // Workaround due to strange bug in GCC > 10.2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108914 const int16_t value = rawData - PWM_RANGE_MIDDLE; if (value < -500) { stickDeflection = -500; @@ -187,9 +187,9 @@ int16_t getAxisRcCommand(int16_t rawData, int16_t rate, int16_t deadband) stickDeflection = value; } #else - stickDeflection = constrain(rawData - PWM_RANGE_MIDDLE, -500, 500); + stickDeflection = constrain(rawData - PWM_RANGE_MIDDLE, -500, 500); #endif - + stickDeflection = applyDeadbandRescaled(stickDeflection, deadband, -500, 500); return rcLookup(stickDeflection, rate); } @@ -523,9 +523,12 @@ void tryArm(void) } #ifdef USE_DSHOT - if (STATE(MULTIROTOR) && (IS_RC_MODE_ACTIVE(BOXTURTLE) || MULTI_FUNC_FLAG(MF_TURTLE_MODE)) && !FLIGHT_MODE(TURTLE_MODE) && - emergencyArmingCanOverrideArmingDisabled() && isMotorProtocolDshot() - ) { +#ifdef USE_MULTI_FUNCTIONS + const bool turtleIsActive = IS_RC_MODE_ACTIVE(BOXTURTLE) || MULTI_FUNC_FLAG(MF_TURTLE_MODE); +#else + const bool turtleIsActive = IS_RC_MODE_ACTIVE(BOXTURTLE); +#endif + if (STATE(MULTIROTOR) && turtleIsActive && !FLIGHT_MODE(TURTLE_MODE) && emergencyArmingCanOverrideArmingDisabled() && isMotorProtocolDshot()) { sendDShotCommand(DSHOT_CMD_SPIN_DIRECTION_REVERSED); ENABLE_ARMING_FLAG(ARMED); enableFlightMode(TURTLE_MODE); @@ -842,7 +845,7 @@ static float calculateThrottleTiltCompensationFactor(uint8_t throttleTiltCompens void taskMainPidLoop(timeUs_t currentTimeUs) { - + cycleTime = getTaskDeltaTime(TASK_SELF); dT = (float)cycleTime * 0.000001f; diff --git a/src/main/fc/fc_msp_box.c b/src/main/fc/fc_msp_box.c index 7cf603b163..0890b1d605 100644 --- a/src/main/fc/fc_msp_box.c +++ b/src/main/fc/fc_msp_box.c @@ -180,7 +180,9 @@ void initActiveBoxIds(void) RESET_BOX_ID_COUNT; ADD_ACTIVE_BOX(BOXARM); ADD_ACTIVE_BOX(BOXPREARM); +#ifdef USE_MULTI_FUNCTIONS ADD_ACTIVE_BOX(BOXMULTIFUNCTION); +#endif if (sensors(SENSOR_ACC) && STATE(ALTITUDE_CONTROL)) { ADD_ACTIVE_BOX(BOXANGLE); @@ -414,8 +416,9 @@ void packBoxModeFlags(boxBitmask_t * mspBoxModeFlags) #ifdef USE_MULTI_MISSION CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXCHANGEMISSION)), BOXCHANGEMISSION); #endif +#ifdef USE_MULTI_FUNCTIONS CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXMULTIFUNCTION)), BOXMULTIFUNCTION); - +#endif memset(mspBoxModeFlags, 0, sizeof(boxBitmask_t)); for (uint32_t i = 0; i < activeBoxIdCount; i++) { if (activeBoxes[activeBoxIds[i]]) { diff --git a/src/main/fc/multifunction.c b/src/main/fc/multifunction.c index 31b0c66935..c217110842 100644 --- a/src/main/fc/multifunction.c +++ b/src/main/fc/multifunction.c @@ -26,6 +26,8 @@ #include "build/debug.h" #include "drivers/time.h" +#ifdef USE_MULTI_FUNCTIONS + #include "fc/fc_core.h" #include "fc/multifunction.h" #include "fc/rc_modes.h" @@ -127,3 +129,4 @@ multi_function_e multiFunctionSelection(void) return selectedItem; } +#endif diff --git a/src/main/fc/multifunction.h b/src/main/fc/multifunction.h index e868e23522..b5c1e1d9d6 100644 --- a/src/main/fc/multifunction.h +++ b/src/main/fc/multifunction.h @@ -24,6 +24,8 @@ #pragma once +#ifdef USE_MULTI_FUNCTIONS + extern uint8_t multiFunctionFlags; #define MULTI_FUNC_FLAG_DISABLE(mask) (multiFunctionFlags &= ~(mask)) @@ -50,3 +52,4 @@ typedef enum { multi_function_e multiFunctionSelection(void); bool isNextMultifunctionItemAvailable(void); void setMultifunctionSelection(multi_function_e item); +#endif diff --git a/src/main/io/osd.c b/src/main/io/osd.c index ea2885fd4c..8983fc5792 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -5053,6 +5053,7 @@ static textAttributes_t osdGetMultiFunctionMessage(char *buff) static uint8_t warningsCount; const char *message = NULL; +#ifdef USE_MULTI_FUNCTIONS /* --- FUNCTIONS --- */ multi_function_e selectedFunction = multiFunctionSelection(); @@ -5086,7 +5087,7 @@ static textAttributes_t osdGetMultiFunctionMessage(char *buff) case MULTI_FUNC_5: #ifdef USE_DSHOT if (STATE(MULTIROTOR)) { - message = MULTI_FUNC_FLAG(MF_TURTLE_MODE) ? "USE TURTLE" : "END TURTLE"; + message = MULTI_FUNC_FLAG(MF_TURTLE_MODE) ? "END TURTLE" : "USE TURTLE"; break; } #endif @@ -5112,6 +5113,7 @@ static textAttributes_t osdGetMultiFunctionMessage(char *buff) return elemAttr; } +#endif // MULTIFUNCTION - functions only, warnings always defined /* --- WARNINGS --- */ const char *messages[7]; diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index e1e5217e4b..17cfe3a560 100644 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -1305,8 +1305,13 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_TRACKBACK(navigatio if (posControl.flags.estPosStatus >= EST_USABLE) { const int32_t distFromStartTrackback = calculateDistanceToDestination(&posControl.rthTBPointsList[posControl.rthTBLastSavedIndex]) / 100; +#ifdef USE_MULTI_FUNCTIONS + const bool overrideTrackback = rthAltControlStickOverrideCheck(ROLL) || MULTI_FUNC_FLAG(MF_SUSPEND_TRACKBACK); +#else + const bool overrideTrackback = rthAltControlStickOverrideCheck(ROLL); +#endif const bool cancelTrackback = distFromStartTrackback > navConfig()->general.rth_trackback_distance || - ((rthAltControlStickOverrideCheck(ROLL) || MULTI_FUNC_FLAG(MF_SUSPEND_TRACKBACK)) && !posControl.flags.forcedRTHActivated); + (overrideTrackback && !posControl.flags.forcedRTHActivated); if (posControl.activeRthTBPointIndex < 0 || cancelTrackback) { posControl.rthTBWrapAroundCounter = posControl.activeRthTBPointIndex = -1; @@ -2437,10 +2442,11 @@ static navigationHomeFlags_t navigationActualStateHomeValidity(void) #if defined(USE_SAFE_HOME) void checkSafeHomeState(bool shouldBeEnabled) { - const bool safehomeNotApplicable = navConfig()->general.flags.safehome_usage_mode == SAFEHOME_USAGE_OFF || - (MULTI_FUNC_FLAG(MF_SUSPEND_SAFEHOMES) && !posControl.flags.forcedRTHActivated) || - posControl.flags.rthTrackbackActive || - (!posControl.safehomeState.isApplied && posControl.homeDistance < navConfig()->general.min_rth_distance); + bool safehomeNotApplicable = navConfig()->general.flags.safehome_usage_mode == SAFEHOME_USAGE_OFF || posControl.flags.rthTrackbackActive || + (!posControl.safehomeState.isApplied && posControl.homeDistance < navConfig()->general.min_rth_distance); +#ifdef USE_MULTI_FUNCTIONS + safehomeNotApplicable = safehomeNotApplicable || (MULTI_FUNC_FLAG(MF_SUSPEND_SAFEHOMES) && !posControl.flags.forcedRTHActivated); +#endif if (safehomeNotApplicable) { shouldBeEnabled = false; diff --git a/src/main/target/common.h b/src/main/target/common.h index d18bdfb1a2..457e9d4780 100644 --- a/src/main/target/common.h +++ b/src/main/target/common.h @@ -161,6 +161,7 @@ #define NAV_MAX_WAYPOINTS 120 #define USE_RCDEVICE #define USE_MULTI_MISSION +#define USE_MULTI_FUNCTIONS // defines functions only, warnings always defined //Enable VTX control #define USE_VTX_CONTROL