1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 05:45:31 +03:00

Merge pull request #7415 from jflyper/bfdev-change-call-timing-of-vtxInit-after-device-parameter-init

[VTX] Follow-up to #7285 vtx changes
This commit is contained in:
Michael Keller 2019-01-19 14:23:18 +13:00 committed by GitHub
commit 7eedfff428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 19 deletions

View file

@ -128,30 +128,44 @@ bool vtxCommonGetDeviceCapability(const vtxDevice_t *vtxDevice, vtxDeviceCapabil
const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band) const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band)
{ {
return vtxDevice->bandNames[band]; if (vtxDevice) {
return vtxDevice->bandNames[band];
} else {
return "?";
}
} }
char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band) char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band)
{ {
return vtxDevice->bandLetters[band]; if (vtxDevice) {
return vtxDevice->bandLetters[band];
} else {
return '?';
}
} }
const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel) const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel)
{ {
return vtxDevice->channelNames[channel]; if (vtxDevice) {
return vtxDevice->channelNames[channel];
} else {
return "?";
}
} }
//Converts frequency (in MHz) to band and channel values. //Converts frequency (in MHz) to band and channel values.
bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel) bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel)
{ {
// Use reverse lookup order so that 5880Mhz if (vtxDevice) {
// get Raceband 7 instead of Fatshark 8. // Use reverse lookup order so that 5880Mhz
for (int band = vtxDevice->capability.bandCount - 1 ; band >= 0 ; band--) { // get Raceband 7 instead of Fatshark 8.
for (int channel = 0 ; channel < vtxDevice->capability.channelCount ; channel++) { for (int band = vtxDevice->capability.bandCount - 1 ; band >= 0 ; band--) {
if (vtxDevice->frequencyTable[band * vtxDevice->capability.channelCount + channel] == freq) { for (int channel = 0 ; channel < vtxDevice->capability.channelCount ; channel++) {
*pBand = band + 1; if (vtxDevice->frequencyTable[band * vtxDevice->capability.channelCount + channel] == freq) {
*pChannel = channel + 1; *pBand = band + 1;
return true; *pChannel = channel + 1;
return true;
}
} }
} }
} }
@ -168,21 +182,31 @@ bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_
// Returns frequency value (in MHz), or 0 if band/channel out of range. // Returns frequency value (in MHz), or 0 if band/channel out of range.
uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel) uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel)
{ {
if (band > 0 && band <= vtxDevice->capability.bandCount && if (vtxDevice) {
channel > 0 && channel <= vtxDevice->capability.channelCount) { if (band > 0 && band <= vtxDevice->capability.bandCount &&
return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)]; channel > 0 && channel <= vtxDevice->capability.channelCount) {
return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)];
}
} }
return 0; return 0;
} }
const char *vtxCommonLookupPowerName(const vtxDevice_t *vtxDevice, int index) const char *vtxCommonLookupPowerName(const vtxDevice_t *vtxDevice, int index)
{ {
return vtxDevice->powerNames[index]; if (vtxDevice) {
return vtxDevice->powerNames[index];
} else {
return "?";
}
} }
uint16_t vtxCommonLookupPowerValue(const vtxDevice_t *vtxDevice, int index) uint16_t vtxCommonLookupPowerValue(const vtxDevice_t *vtxDevice, int index)
{ {
return vtxDevice->powerValues[index]; if (vtxDevice) {
return vtxDevice->powerValues[index];
} else {
return 0;
}
} }
#endif #endif

View file

@ -709,7 +709,6 @@ void init(void)
#if defined(USE_VTX_COMMON) #if defined(USE_VTX_COMMON)
vtxCommonInit(); vtxCommonInit();
vtxInit();
#endif #endif
#ifdef USE_VTX_SMARTAUDIO #ifdef USE_VTX_SMARTAUDIO

View file

@ -69,8 +69,16 @@ void vtxInit(void)
{ {
bool settingsUpdated = false; bool settingsUpdated = false;
vtxDevice_t *vtxDevice = vtxCommonDevice();
if (!vtxDevice) {
// If a device is not registered, we don't have any table to refer.
// Don't manipulate settings and just return in this case.
return;
}
// sync frequency in parameter group when band/channel are specified // sync frequency in parameter group when band/channel are specified
const uint16_t freq = vtxCommonLookupFrequency(vtxCommonDevice(), vtxSettingsConfig()->band, vtxSettingsConfig()->channel); const uint16_t freq = vtxCommonLookupFrequency(vtxDevice, vtxSettingsConfig()->band, vtxSettingsConfig()->channel);
if (vtxSettingsConfig()->band && freq != vtxSettingsConfig()->freq) { if (vtxSettingsConfig()->band && freq != vtxSettingsConfig()->freq) {
vtxSettingsConfigMutable()->freq = freq; vtxSettingsConfigMutable()->freq = freq;
settingsUpdated = true; settingsUpdated = true;

View file

@ -36,6 +36,7 @@
#include "drivers/time.h" #include "drivers/time.h"
#include "drivers/vtx_rtc6705.h" #include "drivers/vtx_rtc6705.h"
#include "io/vtx.h"
#include "io/vtx_rtc6705.h" #include "io/vtx_rtc6705.h"
#include "io/vtx_string.h" #include "io/vtx_string.h"
@ -69,6 +70,8 @@ bool vtxRTC6705Init(void)
vtxCommonSetDevice(&vtxRTC6705); vtxCommonSetDevice(&vtxRTC6705);
vtxInit();
return true; return true;
} }

View file

@ -706,6 +706,8 @@ bool vtxSmartAudioInit(void)
vtxCommonSetDevice(&vtxSmartAudio); vtxCommonSetDevice(&vtxSmartAudio);
vtxInit();
return true; return true;
} }

View file

@ -614,6 +614,7 @@ bool vtxTrampInit(void)
return false; return false;
} }
// XXX Effect of USE_VTX_COMMON should be reviewed, as following call to vtxInit will do nothing if vtxCommonSetDevice is not called.
#if defined(USE_VTX_COMMON) #if defined(USE_VTX_COMMON)
vtxTramp.capability.bandCount = VTX_TRAMP_BAND_COUNT; vtxTramp.capability.bandCount = VTX_TRAMP_BAND_COUNT;
vtxTramp.capability.channelCount = VTX_TRAMP_CHANNEL_COUNT; vtxTramp.capability.channelCount = VTX_TRAMP_CHANNEL_COUNT;
@ -626,8 +627,11 @@ bool vtxTrampInit(void)
vtxTramp.powerValues = trampPowerTable; vtxTramp.powerValues = trampPowerTable;
vtxCommonSetDevice(&vtxTramp); vtxCommonSetDevice(&vtxTramp);
#endif #endif
vtxInit();
return true; return true;
} }