From 03b1f5f54cc35406d4ee9d6460705a9b684cca63 Mon Sep 17 00:00:00 2001 From: Bjoern Schultze Date: Thu, 2 Nov 2017 17:15:52 +0100 Subject: [PATCH] show inflight adjustments in osd --- src/main/fc/rc_adjustments.c | 61 ++++++++++++++++++++++++++++++--- src/main/fc/rc_adjustments.h | 3 +- src/main/io/osd.c | 17 +++++++++ src/main/io/osd.h | 1 + src/main/target/common_fc_pre.h | 3 +- 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index 79b1f63e4c..5add8eb6fa 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -42,6 +42,10 @@ #include "io/beeper.h" #include "io/motors.h" +#if defined(OSD) && defined(USE_OSD_ADJUSTMENTS) +#include "io/osd.h" +#endif + #include "fc/config.h" #include "fc/controlrate_profile.h" #include "fc/rc_adjustments.h" @@ -95,6 +99,11 @@ STATIC_UNIT_TESTED uint8_t adjustmentStateMask = 0; #define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex) (adjustmentStateMask & (1 << adjustmentIndex)) +bool isAnyAdjustmentFunctionBusy() +{ + return adjustmentStateMask != 0; +} + // sync with adjustmentFunction_e static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COUNT - 1] = { { @@ -197,6 +206,35 @@ static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COU } }; +#if defined(OSD) && defined(USE_OSD_ADJUSTMENTS) +static const char * adjustmentLabels[] = { + "RC RATE", + "RC EXPO", + "THROTTLE EXPO", + "ROLL RATE", + "YAW RATE", + "PITCH/ROLL P", + "PITCH/ROLL I", + "PITCH/ROLL D", + "YAW P", + "YAW I", + "YAW D", + "RATE PROFILE", + "PITCH RATE", + "ROLL RATE", + "PITCH P", + "PITCH I", + "PITCH D", + "ROLL P", + "ROLL I", + "ROLL D", + "RC RATE YAW", + "D SETPOINT", + "D SETPOINT TRANSITION", + "HORIZON STRENGTH", +}; +#endif + #define ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET 1 STATIC_UNIT_TESTED adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT]; @@ -216,7 +254,7 @@ STATIC_UNIT_TESTED void configureAdjustment(uint8_t index, uint8_t auxSwitchChan MARK_ADJUSTMENT_FUNCTION_AS_READY(index); } -static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta) +static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta) { beeperConfirmationBeeps(delta > 0 ? 2 : 1); @@ -331,11 +369,14 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT_TRANSITION, newValue); break; default: + newValue = -1; break; }; + + return newValue; } -static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) +static uint8_t applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) { uint8_t beeps = 0; @@ -345,6 +386,7 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) if (getCurrentControlRateProfileIndex() != position) { changeControlRateProfile(position); blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RATE_PROFILE, position); + beeps = position + 1; } break; @@ -365,6 +407,7 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) beeperConfirmationBeeps(beeps); } + return position; } #define RESET_FREQUENCY_2HZ (1000 / 2) @@ -373,6 +416,8 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig) { const uint32_t now = millis(); + int newValue = -1; + const bool canUseRxData = rxIsReceivingSignal(); for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { @@ -413,13 +458,21 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig) continue; } - applyStepAdjustment(controlRateConfig, adjustmentFunction, delta); + newValue = applyStepAdjustment(controlRateConfig, adjustmentFunction, delta); pidInitConfig(pidProfile); } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) { const uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.switchPositions); const uint8_t position = (constrain(rcData[channelIndex], 900, 2100 - 1) - 900) / rangeWidth; - applySelectAdjustment(adjustmentFunction, position); + newValue = applySelectAdjustment(adjustmentFunction, position); } + +#if defined(OSD) && defined(USE_OSD_ADJUSTMENTS) + if (newValue != -1) { + osdShowAdjustment(adjustmentLabels[adjustmentFunction], newValue); + } +#else + UNUSED(newValue); +#endif MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex); } } diff --git a/src/main/fc/rc_adjustments.h b/src/main/fc/rc_adjustments.h index 60900403a6..c0300e9c8a 100644 --- a/src/main/fc/rc_adjustments.h +++ b/src/main/fc/rc_adjustments.h @@ -50,7 +50,6 @@ typedef enum { ADJUSTMENT_FUNCTION_COUNT } adjustmentFunction_e; - typedef enum { ADJUSTMENT_MODE_STEP, ADJUSTMENT_MODE_SELECT @@ -88,7 +87,6 @@ typedef struct adjustmentState_s { uint32_t timeoutAt; } adjustmentState_t; - #ifndef MAX_SIMULTANEOUS_ADJUSTMENT_COUNT #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel #endif @@ -103,3 +101,4 @@ struct controlRateConfig_s; void processRcAdjustments(struct controlRateConfig_s *controlRateConfig); struct pidProfile_s; void useAdjustmentConfig(struct pidProfile_s *pidProfileToUse); +bool isAnyAdjustmentFunctionBusy(); diff --git a/src/main/io/osd.c b/src/main/io/osd.c index ab3233a2f3..61ea8b18a6 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -70,6 +70,7 @@ #include "fc/config.h" #include "fc/rc_controls.h" #include "fc/runtime_config.h" +#include "fc/rc_adjustments.h" #include "flight/altitude.h" #include "flight/navigation.h" @@ -1127,6 +1128,12 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) { static timeUs_t lastTimeUs = 0; +#ifdef USE_OSD_ADJUSTMENTS + if (isAnyAdjustmentFunctionBusy()) { + return; + } +#endif + // detect arm/disarm if (armState != ARMING_FLAG(ARMED)) { if (ARMING_FLAG(ARMED)) { @@ -1239,4 +1246,14 @@ void osdUpdate(timeUs_t currentTimeUs) } #endif } + +#ifdef USE_OSD_ADJUSTMENTS +void osdShowAdjustment(const char * type, int newValue) +{ + char buff[OSD_ELEMENT_BUFFER_LENGTH]; + tfp_sprintf(buff, "%s: %3d", type, newValue); + displayWrite(osdDisplayPort, round(15 - strlen(buff) / 2), 7, buff); +} +#endif + #endif // OSD diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 768bd09019..ebbfca448b 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -162,5 +162,6 @@ void osdInit(struct displayPort_s *osdDisplayPort); void osdResetConfig(osdConfig_t *osdProfile); void osdResetAlarms(void); void osdUpdate(timeUs_t currentTimeUs); +void osdShowAdjustment(const char * type, int newValue); #endif diff --git a/src/main/target/common_fc_pre.h b/src/main/target/common_fc_pre.h index 8a9ff70ed8..4629e94687 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -105,7 +105,7 @@ #define USE_RESOURCE_MGMT #define USE_SERVOS #endif - + #if (FLASH_SIZE > 128) #define USE_CMS #define TELEMETRY_CRSF @@ -144,4 +144,5 @@ #define USE_GPS #define USE_NAV #define USE_UNCOMMON_MIXERS +#define USE_OSD_ADJUSTMENTS #endif