Call vtxInit after device parameters are initialized

This commit is contained in:
jflyper 2019-01-17 02:40:14 +09:00
parent e0fc9300ed
commit 80c1cfa6db
6 changed files with 19 additions and 3 deletions

View File

@ -168,7 +168,7 @@ bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_
// Returns frequency value (in MHz), or 0 if band/channel out of range.
uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel)
{
if (band > 0 && band <= vtxDevice->capability.bandCount &&
if (vtxDevice && band > 0 && band <= vtxDevice->capability.bandCount &&
channel > 0 && channel <= vtxDevice->capability.channelCount) {
return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)];

View File

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

View File

@ -69,8 +69,16 @@ void vtxInit(void)
{
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
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) {
vtxSettingsConfigMutable()->freq = freq;
settingsUpdated = true;

View File

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

View File

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

View File

@ -614,6 +614,7 @@ bool vtxTrampInit(void)
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)
vtxTramp.capability.bandCount = VTX_TRAMP_BAND_COUNT;
vtxTramp.capability.channelCount = VTX_TRAMP_CHANNEL_COUNT;
@ -626,8 +627,11 @@ bool vtxTrampInit(void)
vtxTramp.powerValues = trampPowerTable;
vtxCommonSetDevice(&vtxTramp);
#endif
vtxInit();
return true;
}