1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

[SmartAudio] Added support for custom frequency tables (#8380)

[SmartAudio] Added support for custom frequency tables
This commit is contained in:
Michael Keller 2019-06-25 02:16:14 +12:00 committed by GitHub
commit ed266e7151
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 516 additions and 591 deletions

View file

@ -2452,8 +2452,7 @@ static void cliVtx(char *cmdline)
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
// FIXME Use VTX API to get max
if (val >= 0 && val <= VTX_SETTINGS_MAX_BAND) {
if (val >= 0 && val <= vtxTableBandCount) {
cac->band = val;
validArgumentCount++;
}
@ -2461,8 +2460,7 @@ static void cliVtx(char *cmdline)
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
// FIXME Use VTX API to get max
if (val >= 0 && val <= VTX_SETTINGS_MAX_CHANNEL) {
if (val >= 0 && val <= vtxTableChannelCount) {
cac->channel = val;
validArgumentCount++;
}
@ -2470,8 +2468,7 @@ static void cliVtx(char *cmdline)
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
// FIXME Use VTX API to get max
if (val >= 0 && val < VTX_SETTINGS_POWER_COUNT) {
if (val >= 0 && val < vtxTablePowerLevels) {
cac->power= val;
validArgumentCount++;
}
@ -2502,11 +2499,12 @@ static void cliVtx(char *cmdline)
#ifdef USE_VTX_TABLE
static char *formatVtxTableBandFrequency(const uint16_t *frequency, int channels)
static char *formatVtxTableBandFrequency(const bool isFactory, const uint16_t *frequency, int channels)
{
static char freqbuf[5 * VTX_TABLE_MAX_CHANNELS + 1];
static char freqbuf[5 * VTX_TABLE_MAX_CHANNELS + 8 + 1];
char freqtmp[5 + 1];
freqbuf[0] = 0;
strcat(freqbuf, isFactory ? " FACTORY" : " CUSTOM ");
for (int channel = 0; channel < channels; channel++) {
tfp_sprintf(freqtmp, " %4d", frequency[channel]);
strcat(freqbuf, freqtmp);
@ -2533,11 +2531,11 @@ static const char *printVtxTableBand(dumpFlags_t dumpMask, int band, const vtxTa
}
}
headingStr = cliPrintSectionHeading(dumpMask, !equalsDefault, headingStr);
char *freqbuf = formatVtxTableBandFrequency(defaultConfig->frequency[band], defaultConfig->channels);
char *freqbuf = formatVtxTableBandFrequency(defaultConfig->isFactoryBand[band], defaultConfig->frequency[band], defaultConfig->channels);
cliDefaultPrintLinef(dumpMask, equalsDefault, fmt, band + 1, defaultConfig->bandNames[band], defaultConfig->bandLetters[band], freqbuf);
}
char *freqbuf = formatVtxTableBandFrequency(currentConfig->frequency[band], currentConfig->channels);
char *freqbuf = formatVtxTableBandFrequency(currentConfig->isFactoryBand[band], currentConfig->frequency[band], currentConfig->channels);
cliDumpPrintLinef(dumpMask, equalsDefault, fmt, band + 1, currentConfig->bandNames[band], currentConfig->bandLetters[band], freqbuf);
return headingStr;
}
@ -2822,8 +2820,20 @@ static void cliVtxTable(char *cmdline)
uint16_t bandfreq[VTX_TABLE_MAX_CHANNELS];
int channel = 0;
int channels = vtxTableConfigMutable()->channels;
bool isFactory = false;
for (channel = 0; channel < channels && (tok = strtok_r(NULL, " ", &saveptr)); channel++) {
if (channel == 0 && !isdigit(tok[0])) {
channel -= 1;
if (strcasecmp(tok, "FACTORY") == 0) {
isFactory = true;
} else if (strcasecmp(tok, "CUSTOM") == 0) {
isFactory = false;
} else {
cliPrintErrorLinef("INVALID FACTORY FLAG %s (EXPECTED FACTORY OR CUSTOM)", tok);
return;
}
}
int freq = atoi(tok);
if (freq < 0) {
cliPrintErrorLinef("INVALID FREQUENCY %s", tok);
@ -2846,6 +2856,7 @@ static void cliVtxTable(char *cmdline)
for (int i = 0; i < channel; i++) {
vtxTableConfigMutable()->frequency[band][i] = bandfreq[i];
}
vtxTableConfigMutable()->isFactoryBand[band] = isFactory;
} else {
// Bad subcommand
cliPrintErrorLinef("INVALID SUBCOMMAND %s", tok);
@ -6038,7 +6049,7 @@ const clicmd_t cmdTable[] = {
#endif
#endif
#ifdef USE_VTX_TABLE
CLI_COMMAND_DEF("vtxtable", "vtx frequency able", "<band> <bandname> <bandletter> <freq> ... <freq>\r\n", cliVtxTable),
CLI_COMMAND_DEF("vtxtable", "vtx frequency able", "<band> <bandname> <bandletter> [FACTORY|CUSTOM] <freq> ... <freq>\r\n", cliVtxTable),
#endif
};