mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Merge pull request #10348 from pgreenland/vtx_irc_tramp_logic_pitmode_cli
Fix VTX tramp protocol for all
This commit is contained in:
commit
7154abc48e
3 changed files with 35 additions and 28 deletions
|
@ -185,11 +185,16 @@ static bool vtxProcessPower(vtxDevice_t *vtxDevice)
|
||||||
|
|
||||||
static bool vtxProcessPitMode(vtxDevice_t *vtxDevice)
|
static bool vtxProcessPitMode(vtxDevice_t *vtxDevice)
|
||||||
{
|
{
|
||||||
|
static bool prevPmSwitchState = false;
|
||||||
|
|
||||||
unsigned vtxStatus;
|
unsigned vtxStatus;
|
||||||
if (vtxCommonGetStatus(vtxDevice, &vtxStatus)) {
|
if (!ARMING_FLAG(ARMED) && vtxCommonGetStatus(vtxDevice, &vtxStatus)) {
|
||||||
bool currPmSwitchState = IS_RC_MODE_ACTIVE(BOXVTXPITMODE);
|
bool currPmSwitchState = IS_RC_MODE_ACTIVE(BOXVTXPITMODE);
|
||||||
|
|
||||||
|
if (currPmSwitchState != prevPmSwitchState) {
|
||||||
|
prevPmSwitchState = currPmSwitchState;
|
||||||
|
|
||||||
if (currPmSwitchState) {
|
if (currPmSwitchState) {
|
||||||
if (!ARMING_FLAG(ARMED)) {
|
|
||||||
#if defined(VTX_SETTINGS_FREQCMD)
|
#if defined(VTX_SETTINGS_FREQCMD)
|
||||||
if (vtxSettingsConfig()->pitModeFreq) {
|
if (vtxSettingsConfig()->pitModeFreq) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -200,7 +205,6 @@ static bool vtxProcessPitMode(vtxDevice_t *vtxDevice)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (vtxStatus & VTX_STATUS_PIT_MODE) {
|
if (vtxStatus & VTX_STATUS_PIT_MODE) {
|
||||||
vtxCommonSetPitMode(vtxDevice, false);
|
vtxCommonSetPitMode(vtxDevice, false);
|
||||||
|
@ -209,6 +213,7 @@ static bool vtxProcessPitMode(vtxDevice_t *vtxDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -918,8 +918,6 @@ static void vtxSASetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t index)
|
||||||
|
|
||||||
static void vtxSASetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff)
|
static void vtxSASetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff)
|
||||||
{
|
{
|
||||||
static bool lastOnOff = false;
|
|
||||||
|
|
||||||
if (!vtxSAIsReady(vtxDevice) || saDevice.version < 2) {
|
if (!vtxSAIsReady(vtxDevice) || saDevice.version < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -929,12 +927,6 @@ static void vtxSASetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only issue pit mode commands on status change
|
|
||||||
if (lastOnOff == onoff) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastOnOff = onoff;
|
|
||||||
|
|
||||||
if (saDevice.version >= 3 && !saDevice.willBootIntoPitMode) {
|
if (saDevice.version >= 3 && !saDevice.willBootIntoPitMode) {
|
||||||
if (onoff) {
|
if (onoff) {
|
||||||
// enable pitmode using SET_POWER command with 0 dbm.
|
// enable pitmode using SET_POWER command with 0 dbm.
|
||||||
|
|
|
@ -94,6 +94,7 @@ typedef enum {
|
||||||
TRAMP_STATUS_ONLINE_CONFIG
|
TRAMP_STATUS_ONLINE_CONFIG
|
||||||
} trampStatus_e;
|
} trampStatus_e;
|
||||||
|
|
||||||
|
// Module state
|
||||||
static trampStatus_e trampStatus = TRAMP_STATUS_OFFLINE;
|
static trampStatus_e trampStatus = TRAMP_STATUS_OFFLINE;
|
||||||
|
|
||||||
// Device limits, read from device during init
|
// Device limits, read from device during init
|
||||||
|
@ -105,20 +106,20 @@ static uint32_t trampRFPowerMax;
|
||||||
static uint32_t trampCurFreq = 0;
|
static uint32_t trampCurFreq = 0;
|
||||||
static uint16_t trampCurConfPower = 0; // Configured power
|
static uint16_t trampCurConfPower = 0; // Configured power
|
||||||
static uint16_t trampCurActPower = 0; // Actual power
|
static uint16_t trampCurActPower = 0; // Actual power
|
||||||
static uint8_t trampCurPitMode = 0;
|
static uint8_t trampCurPitMode = 0; // Expect to startup out of pitmode
|
||||||
static int16_t trampCurTemp = 0;
|
static int16_t trampCurTemp = 0;
|
||||||
static uint8_t trampCurControlMode = 0;
|
static uint8_t trampCurControlMode = 0;
|
||||||
|
|
||||||
// Device configuration, desired state of device
|
// Device configuration, desired state of device
|
||||||
static uint32_t trampConfFreq = 0;
|
static uint32_t trampConfFreq = 0;
|
||||||
static uint16_t trampConfPower = 0;
|
static uint16_t trampConfPower = 0;
|
||||||
static uint8_t trampConfPitMode = 0;
|
static uint8_t trampConfPitMode = 0; // Initially configured out of pitmode
|
||||||
|
|
||||||
// Last device configuration, last desired state of device - used to reset
|
// Last device configuration, last desired state of device - used to reset
|
||||||
// retry count
|
// retry count
|
||||||
static uint32_t trampLastConfFreq = 0;
|
static uint32_t trampLastConfFreq = 0;
|
||||||
static uint16_t trampLastConfPower = 0;
|
static uint16_t trampLastConfPower = 0;
|
||||||
static uint8_t trampLastConfPitMode = 0;
|
static uint8_t trampLastConfPitMode = 0; // Mirror trampConfPitMode
|
||||||
|
|
||||||
// Retry count
|
// Retry count
|
||||||
static uint8_t trampRetryCount = TRAMP_MAX_RETRIES;
|
static uint8_t trampRetryCount = TRAMP_MAX_RETRIES;
|
||||||
|
@ -325,7 +326,7 @@ static void trampQuery(uint8_t cmd)
|
||||||
static void vtxTrampProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
|
static void vtxTrampProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
UNUSED(vtxDevice);
|
UNUSED(vtxDevice);
|
||||||
uint8_t configUpdateRequired = 0;
|
bool configUpdateRequired = false;
|
||||||
|
|
||||||
// Read response from device
|
// Read response from device
|
||||||
const char replyCode = trampReceive();
|
const char replyCode = trampReceive();
|
||||||
|
@ -374,19 +375,19 @@ static void vtxTrampProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
|
||||||
trampSendCommand('F', trampConfFreq);
|
trampSendCommand('F', trampConfFreq);
|
||||||
|
|
||||||
// Set flag
|
// Set flag
|
||||||
configUpdateRequired = 1;
|
configUpdateRequired = true;
|
||||||
} else if (!trampVtxRaceLockEnabled() && (trampConfPower != trampCurConfPower)) {
|
} else if (!trampVtxRaceLockEnabled() && (trampConfPower != trampCurConfPower)) {
|
||||||
// Power can be and needs to be updated, issue request
|
// Power can be and needs to be updated, issue request
|
||||||
trampSendCommand('P', trampConfPower);
|
trampSendCommand('P', trampConfPower);
|
||||||
|
|
||||||
// Set flag
|
// Set flag
|
||||||
configUpdateRequired = 1;
|
configUpdateRequired = true;
|
||||||
} else if (trampConfPitMode != trampCurPitMode) {
|
} else if (trampConfPitMode != trampCurPitMode) {
|
||||||
// Pit mode needs to be updated, issue request
|
// Pit mode needs to be updated, issue request
|
||||||
trampSendCommand('I', trampConfPitMode);
|
trampSendCommand('I', trampConfPitMode ? 0 : 1);
|
||||||
|
|
||||||
// Set flag
|
// Set flag
|
||||||
configUpdateRequired = 1;
|
configUpdateRequired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configUpdateRequired) {
|
if (configUpdateRequired) {
|
||||||
|
@ -464,7 +465,14 @@ static void vtxTrampProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
|
||||||
|
|
||||||
DEBUG_SET(DEBUG_VTX_TRAMP, 0, trampStatus);
|
DEBUG_SET(DEBUG_VTX_TRAMP, 0, trampStatus);
|
||||||
DEBUG_SET(DEBUG_VTX_TRAMP, 1, replyCode);
|
DEBUG_SET(DEBUG_VTX_TRAMP, 1, replyCode);
|
||||||
DEBUG_SET(DEBUG_VTX_TRAMP, 2, configUpdateRequired);
|
DEBUG_SET(DEBUG_VTX_TRAMP, 2, ((trampConfPitMode << 14) & 0xC000) |
|
||||||
|
((trampCurPitMode << 12) & 0x3000) |
|
||||||
|
((trampConfPower << 8) & 0x0F00) |
|
||||||
|
((trampCurConfPower << 4) & 0x00F0) |
|
||||||
|
((trampConfFreq != trampCurFreq) ? 0x0008 : 0x0000) |
|
||||||
|
((trampConfPower != trampCurConfPower) ? 0x0004 : 0x0000) |
|
||||||
|
((trampConfPitMode != trampCurPitMode) ? 0x0002 : 0x0000) |
|
||||||
|
(configUpdateRequired ? 0x0001 : 0x0000));
|
||||||
DEBUG_SET(DEBUG_VTX_TRAMP, 3, trampRetryCount);
|
DEBUG_SET(DEBUG_VTX_TRAMP, 3, trampRetryCount);
|
||||||
|
|
||||||
#ifdef USE_CMS
|
#ifdef USE_CMS
|
||||||
|
@ -515,7 +523,7 @@ static void vtxTrampSetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff)
|
||||||
{
|
{
|
||||||
UNUSED(vtxDevice);
|
UNUSED(vtxDevice);
|
||||||
|
|
||||||
trampConfPitMode = onoff ? 0 : 1; // note inverted values
|
trampConfPitMode = onoff;
|
||||||
if (trampConfPitMode != trampLastConfPitMode) {
|
if (trampConfPitMode != trampLastConfPitMode) {
|
||||||
// Requested pitmode changed, reset retry count
|
// Requested pitmode changed, reset retry count
|
||||||
trampRetryCount = TRAMP_MAX_RETRIES;
|
trampRetryCount = TRAMP_MAX_RETRIES;
|
||||||
|
@ -602,8 +610,10 @@ static bool vtxTrampGetStatus(const vtxDevice_t *vtxDevice, unsigned *status)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return pitmode from latest query response
|
// Mirror configued pit mode state rather than use current pitmode as we
|
||||||
*status = (trampCurPitMode ? 0 : VTX_STATUS_PIT_MODE);
|
// should, otherwise the logic in vtxProcessPitMode may not get us to the
|
||||||
|
// correct state if pitmode is toggled quickly
|
||||||
|
*status = (trampConfPitMode ? VTX_STATUS_PIT_MODE : 0);
|
||||||
|
|
||||||
// Check VTX is not locked
|
// Check VTX is not locked
|
||||||
*status |= ((trampCurControlMode & TRAMP_CONTROL_RACE_LOCK) ? VTX_STATUS_LOCKED : 0);
|
*status |= ((trampCurControlMode & TRAMP_CONTROL_RACE_LOCK) ? VTX_STATUS_LOCKED : 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue