mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
138 lines
4.2 KiB
C
138 lines
4.2 KiB
C
/*
|
|
* This file is part of Cleanflight and Betaflight.
|
|
*
|
|
* Cleanflight and Betaflight are free software. You can redistribute
|
|
* this software and/or modify this software under the terms of the
|
|
* GNU General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* Cleanflight and Betaflight are distributed in the hope that they
|
|
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software.
|
|
*
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/* Created by jflyper */
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
|
|
#include "platform.h"
|
|
|
|
#if defined(USE_VTX_TABLE)
|
|
|
|
#include "common/printf.h"
|
|
|
|
#include "pg/vtx_table.h"
|
|
#include "drivers/vtx_common.h"
|
|
#include "drivers/vtx_table.h"
|
|
|
|
int vtxTableBandCount;
|
|
int vtxTableChannelCount;
|
|
uint16_t vtxTableFrequency[VTX_TABLE_MAX_BANDS][VTX_TABLE_MAX_CHANNELS];
|
|
const char * vtxTableBandNames[VTX_TABLE_MAX_BANDS + 1];
|
|
char vtxTableBandLetters[VTX_TABLE_MAX_BANDS + 1];
|
|
const char * vtxTableChannelNames[VTX_TABLE_MAX_CHANNELS + 1];
|
|
|
|
int vtxTablePowerLevels;
|
|
uint16_t vtxTablePowerValues[VTX_TABLE_MAX_POWER_LEVELS];
|
|
const char * vtxTablePowerLabels[VTX_TABLE_MAX_POWER_LEVELS + 1];
|
|
|
|
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];
|
|
}
|
|
vtxTableBandNames[band + 1] = config->bandNames[band];
|
|
vtxTableBandLetters[band + 1] = config->bandLetters[band];
|
|
}
|
|
|
|
vtxTableBandNames[0] = "--------";
|
|
vtxTableBandLetters[0] = '-';
|
|
|
|
for (int channel = 0; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
|
|
vtxTableChannelNames[channel + 1] = config->channelNames[channel];
|
|
}
|
|
vtxTableChannelNames[0] = "-";
|
|
|
|
for (int level = 0; level < config->powerLevels; level++) {
|
|
vtxTablePowerValues[level] = config->powerValues[level];
|
|
vtxTablePowerLabels[level + 1] = config->powerLabels[level];
|
|
}
|
|
vtxTablePowerLabels[0] = "---";
|
|
|
|
vtxTablePowerLevels = config->powerLevels;
|
|
}
|
|
|
|
void vtxTableStrncpyWithPad(char *dst, const char *src, int length)
|
|
{
|
|
char c;
|
|
|
|
while (length && (c = *src++)) {
|
|
*dst++ = c;
|
|
length--;
|
|
}
|
|
|
|
while (length--) {
|
|
*dst++ = ' ';
|
|
}
|
|
|
|
*dst = 0;
|
|
}
|
|
|
|
// Prune a band to "channels"
|
|
void vtxTableConfigClearChannels(vtxTableConfig_t *config, int band, int channels)
|
|
{
|
|
for (int channel = channels; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
|
|
config->frequency[band][channel] = 0;
|
|
}
|
|
}
|
|
|
|
// Clear a channel name for "channel"
|
|
void vtxTableConfigClearChannelNames(vtxTableConfig_t *config, int channel)
|
|
{
|
|
tfp_sprintf(config->channelNames[channel], "%d", channel + 1);
|
|
}
|
|
|
|
void vtxTableConfigClearBand(vtxTableConfig_t *config, int band)
|
|
{
|
|
vtxTableConfigClearChannels(config, band, 0);
|
|
for (int channel = 0; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
|
|
vtxTableConfigClearChannelNames(config, channel);
|
|
}
|
|
char tempbuf[6];
|
|
tfp_sprintf(tempbuf, "BAND%d", band + 1);
|
|
vtxTableStrncpyWithPad(config->bandNames[band], tempbuf, VTX_TABLE_BAND_NAME_LENGTH);
|
|
config->bandLetters[band] = '1' + band;
|
|
}
|
|
|
|
void vtxTableConfigClearPowerValues(vtxTableConfig_t *config, int start)
|
|
{
|
|
for (int i = start; i < VTX_TABLE_MAX_POWER_LEVELS; i++) {
|
|
config->powerValues[i] = 0;
|
|
}
|
|
}
|
|
|
|
void vtxTableConfigClearPowerLabels(vtxTableConfig_t *config, int start)
|
|
{
|
|
for (int i = start; i < VTX_TABLE_MAX_POWER_LEVELS; i++) {
|
|
char tempbuf[4];
|
|
tfp_sprintf(tempbuf, "LV%d", i);
|
|
vtxTableStrncpyWithPad(config->powerLabels[i], tempbuf, VTX_TABLE_POWER_LABEL_LENGTH);
|
|
}
|
|
}
|
|
#endif
|