mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 14:25:20 +03:00
Merge pull request #4478 from bjoern79de/master
show inflight adjustments in osd
This commit is contained in:
commit
6f46ba74bd
5 changed files with 78 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
#define USE_RESOURCE_MGMT
|
||||
#define USE_SERVOS
|
||||
#endif
|
||||
|
||||
|
||||
#if (FLASH_SIZE > 128)
|
||||
#define USE_CMS
|
||||
#define USE_TELEMETRY_CRSF
|
||||
|
@ -146,4 +146,5 @@
|
|||
#define USE_GPS
|
||||
#define USE_NAV
|
||||
#define USE_UNCOMMON_MIXERS
|
||||
#define USE_OSD_ADJUSTMENTS
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue