diff --git a/src/main/drivers/vtx_common.c b/src/main/drivers/vtx_common.c index 55381e8459..422e090a90 100644 --- a/src/main/drivers/vtx_common.c +++ b/src/main/drivers/vtx_common.c @@ -128,30 +128,44 @@ bool vtxCommonGetDeviceCapability(const vtxDevice_t *vtxDevice, vtxDeviceCapabil 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) { - return vtxDevice->bandLetters[band]; + if (vtxDevice) { + return vtxDevice->bandLetters[band]; + } else { + return '?'; + } } 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. bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel) { - // Use reverse lookup order so that 5880Mhz - // get Raceband 7 instead of Fatshark 8. - for (int band = vtxDevice->capability.bandCount - 1 ; band >= 0 ; band--) { - for (int channel = 0 ; channel < vtxDevice->capability.channelCount ; channel++) { - if (vtxDevice->frequencyTable[band * vtxDevice->capability.channelCount + channel] == freq) { - *pBand = band + 1; - *pChannel = channel + 1; - return true; + if (vtxDevice) { + // Use reverse lookup order so that 5880Mhz + // get Raceband 7 instead of Fatshark 8. + for (int band = vtxDevice->capability.bandCount - 1 ; band >= 0 ; band--) { + for (int channel = 0 ; channel < vtxDevice->capability.channelCount ; channel++) { + if (vtxDevice->frequencyTable[band * vtxDevice->capability.channelCount + channel] == freq) { + *pBand = band + 1; + *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. uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel) { - if (vtxDevice && band > 0 && band <= vtxDevice->capability.bandCount && - channel > 0 && channel <= vtxDevice->capability.channelCount) { - return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)]; - + if (vtxDevice) { + if (band > 0 && band <= vtxDevice->capability.bandCount && + channel > 0 && channel <= vtxDevice->capability.channelCount) { + return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)]; + } } + return 0; } 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) { - return vtxDevice->powerValues[index]; + if (vtxDevice) { + return vtxDevice->powerValues[index]; + } else { + return 0; + } } #endif