Skip to content

Commit

Permalink
Merge pull request #10355 from geoffsim/MSP-VTX
Browse files Browse the repository at this point in the history
MSP VTX Code Updates
  • Loading branch information
mmosca authored Nov 4, 2024
2 parents 625a3a0 + be0e8a1 commit 78e1392
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 618 deletions.
4 changes: 2 additions & 2 deletions src/main/drivers/vtx_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

#define VTX_SETTINGS_POWER_COUNT 8
#define VTX_SETTINGS_DEFAULT_POWER 1
#define VTX_SETTINGS_MIN_POWER 1
#define VTX_SETTINGS_MIN_POWER 0
#define VTX_SETTINGS_MIN_USER_FREQ 5000
#define VTX_SETTINGS_MAX_USER_FREQ 5999
#define VTX_SETTINGS_FREQCMD
#define VTX_SETTINGS_MAX_POWER (VTX_SETTINGS_POWER_COUNT - VTX_SETTINGS_MIN_POWER + 1)
#define VTX_SETTINGS_MAX_POWER (VTX_SETTINGS_POWER_COUNT - VTX_SETTINGS_MIN_POWER)

#else

Expand Down
49 changes: 26 additions & 23 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2692,21 +2692,15 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
if (newFrequency <= VTXCOMMON_MSP_BANDCHAN_CHKVAL) { //value is band and channel
const uint8_t newBand = (newFrequency / 8) + 1;
const uint8_t newChannel = (newFrequency % 8) + 1;

if(vtxSettingsConfig()->band != newBand || vtxSettingsConfig()->channel != newChannel) {
vtxCommonSetBandAndChannel(vtxDevice, newBand, newChannel);
if (vtxSettingsConfig()->band != newBand || vtxSettingsConfig()->channel != newChannel) {
vtxSettingsConfigMutable()->band = newBand;
vtxSettingsConfigMutable()->channel = newChannel;
}

vtxSettingsConfigMutable()->band = newBand;
vtxSettingsConfigMutable()->channel = newChannel;
}

if (sbufBytesRemaining(src) > 1) {
uint8_t newPower = sbufReadU8(src);
uint8_t currentPower = 0;
vtxCommonGetPowerIndex(vtxDevice, &currentPower);
if (newPower != currentPower) {
vtxCommonSetPowerByIndex(vtxDevice, newPower);
if (vtxSettingsConfig()->power != newPower) {
vtxSettingsConfigMutable()->power = newPower;
}

Expand All @@ -2722,28 +2716,37 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
vtxSettingsConfigMutable()->lowPowerDisarm = sbufReadU8(src);
}

// //////////////////////////////////////////////////////////
// this code is taken from BF, it's hack for HDZERO VTX MSP frame
// API version 1.42 - this parameter kept separate since clients may already be supplying
// API version 1.42 - extension for pitmode frequency
if (sbufBytesRemaining(src) >= 2) {
sbufReadU16(src); //skip pitModeFreq
}

// API version 1.42 - extensions for non-encoded versions of the band, channel or frequency
if (sbufBytesRemaining(src) >= 4) {
uint8_t newBand = sbufReadU8(src);
if (vtxSettingsConfig()->band != newBand) {
vtxSettingsConfigMutable()->band = newBand;
}

const uint8_t newChannel = sbufReadU8(src);
vtxSettingsConfigMutable()->band = newBand;
vtxSettingsConfigMutable()->channel = newChannel;
if (vtxSettingsConfig()->channel != newChannel) {
vtxSettingsConfigMutable()->channel = newChannel;
}
}

/* if (sbufBytesRemaining(src) >= 4) {
sbufRead8(src); // freq_l
sbufRead8(src); // freq_h
sbufRead8(src); // band count
sbufRead8(src); // channel count
}*/
// //////////////////////////////////////////////////////////
if (sbufBytesRemaining(src) >= 2) {
sbufReadU16(src); // freq
}

if (sbufBytesRemaining(src) >= 3) {
sbufReadU8(src); // band count
sbufReadU8(src); // channel count

uint8_t newPowerCount = sbufReadU8(src);
if (newPowerCount > 0 && newPowerCount < (vtxDevice->capability.powerCount)) {
vtxDevice->capability.powerCount = newPowerCount;
}
}
}
}
}
Expand Down Expand Up @@ -3700,7 +3703,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
while (bytesCount < 80) //whole response should be less 155 bytes at worst.
{
bool blink1;
uint16_t lastChar;
uint16_t lastChar = 0;

count = 0;
while ( true )
Expand Down
5 changes: 1 addition & 4 deletions src/main/fc/fc_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ void taskHandleSerial(timeUs_t currentTimeUs)
#ifdef USE_MSP_OSD
// Capture MSP Displayport messages to determine if VTX is connected
mspOsdSerialProcess(mspFcProcessCommand);
#ifdef USE_VTX_MSP
mspVtxSerialProcess(mspFcProcessCommand);
#endif
#endif

}
Expand Down Expand Up @@ -409,7 +406,7 @@ void fcTasksInit(void)
setTaskEnabled(TASK_OPFLOW, sensors(SENSOR_OPFLOW));
#endif
#ifdef USE_VTX_CONTROL
#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP)
#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP)
setTaskEnabled(TASK_VTXCTRL, true);
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/rc_adjustments.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t
case ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE:
applyAdjustmentU16(ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE, &navConfigMutable()->fw.minThrottleDownPitchAngle, delta, SETTING_FW_MIN_THROTTLE_DOWN_PITCH_MIN, SETTING_FW_MIN_THROTTLE_DOWN_PITCH_MAX);
break;
#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP)
#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP)
case ADJUSTMENT_VTX_POWER_LEVEL:
{
vtxDeviceCapability_t vtxDeviceCapability;
Expand Down
Loading

0 comments on commit 78e1392

Please sign in to comment.