Skip to content

Commit

Permalink
Size of frequency table (stride) is now fixed constant
Browse files Browse the repository at this point in the history
  • Loading branch information
ezshinoda committed Feb 6, 2019
1 parent 96fc6dc commit 9b06b57
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/drivers/vtx_common.c
Expand Up @@ -153,6 +153,10 @@ const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel
}
}

// XXX FIXME Size of a band in the frequency table is now fixed at
// VTX_SETTINGS_MAX_CHANNEL (or VTX_TABLE_MAX_CHANNELS).
// Size constant should be consolidated soon or later.

//Converts frequency (in MHz) to band and channel values.
bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel)
{
Expand All @@ -161,7 +165,7 @@ bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_
// 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) {
if (vtxDevice->frequencyTable[band * VTX_SETTINGS_MAX_CHANNEL + channel] == freq) {
*pBand = band + 1;
*pChannel = channel + 1;
return true;
Expand All @@ -185,7 +189,7 @@ uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int ch
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 vtxDevice->frequencyTable[(band - 1) * VTX_SETTINGS_MAX_CHANNEL + (channel - 1)];
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/drivers/vtx_table.c
Expand Up @@ -50,6 +50,9 @@ void vtxTableInit(void)
{
const vtxTableConfig_t *config = vtxTableConfig();

vtxTableBandCount = config->bands;
vtxTableChannelCount = config->channels;

for (int band = 0; band < VTX_TABLE_MAX_BANDS; band++) {
for (int channel = 0; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
vtxTableFrequency[band][channel] = config->frequency[band][channel];
Expand Down
10 changes: 10 additions & 0 deletions src/main/drivers/vtx_table.h
Expand Up @@ -40,3 +40,13 @@ void vtxTableConfigClearBand(struct vtxTableConfig_s *config, int band);
void vtxTableConfigClearPowerValues(struct vtxTableConfig_s *config, int start);
void vtxTableConfigClearPowerLabels(struct vtxTableConfig_s *config, int start);
void vtxTableConfigClearChannels(struct vtxTableConfig_s *config, int band, int channels);

extern int vtxTableBandCount;
extern int vtxTableChannelCount;
extern uint16_t vtxTableFrequency[VTX_TABLE_MAX_BANDS][VTX_TABLE_MAX_CHANNELS];
extern const char * vtxTableBandNames[VTX_TABLE_MAX_BANDS + 1];
extern char vtxTableBandLetters[VTX_TABLE_MAX_BANDS + 1];
extern const char * vtxTableChannelNames[VTX_TABLE_MAX_CHANNELS + 1];
extern int vtxTablePowerLevels;
extern uint16_t vtxTablePowerValues[VTX_TABLE_MAX_POWER_LEVELS];
extern const char * vtxTablePowerLabels[VTX_TABLE_MAX_POWER_LEVELS + 1];
4 changes: 2 additions & 2 deletions src/main/pg/pg_ids.h
Expand Up @@ -140,8 +140,8 @@
#define PG_SERIAL_UART_CONFIG 543
#define PG_RPM_FILTER_CONFIG 544
#define PG_LED_STRIP_STATUS_MODE_CONFIG 545 // Used to hold the configuration for the LED_STRIP status mode (not built on targets with limited flash)
#define PG_VTX_TABLE_CONFIG 545
#define PG_BETAFLIGHT_END 545
#define PG_VTX_TABLE_CONFIG 546
#define PG_BETAFLIGHT_END 546


// OSD configuration (subject to change)
Expand Down

0 comments on commit 9b06b57

Please sign in to comment.