1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 21:05:35 +03:00

Convert direct reference to string and freq table to vtxCommonXXX services

This commit is contained in:
jflyper 2018-12-25 04:38:38 +09:00
parent 69bce7bfff
commit d8f55f35ef
19 changed files with 229 additions and 119 deletions

View file

@ -126,4 +126,63 @@ bool vtxCommonGetDeviceCapability(const vtxDevice_t *vtxDevice, vtxDeviceCapabil
return true;
}
const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band)
{
return vtxDevice->bandNames[band];
}
char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band)
{
return vtxDevice->bandLetters[band];
}
const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel)
{
return vtxDevice->channelNames[channel];
}
//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;
}
}
}
*pBand = 0;
*pChannel = 0;
return false;
}
//Converts band and channel values to a frequency (in MHz) value.
// band: Band value (1 to 5).
// channel: Channel value (1 to 8).
// 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 &&
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];
}
uint16_t vtxCommonLookupPowerValue(const vtxDevice_t *vtxDevice, int index)
{
return vtxDevice->powerValues[index];
}
#endif