Add RANGEFINDER and OPTICALFLOW MT build option (#14042)
[betaflight.git] / src / main / drivers / vtx_table.c
blob5e29e5a548aec7d00a45f85ae32c98b5a036ace2
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 /* Created by jflyper */
23 #include <stdbool.h>
24 #include <stdint.h>
25 #include <ctype.h>
26 #include <string.h>
28 #include "platform.h"
30 #include "drivers/vtx_table.h"
32 #if defined(USE_VTX_TABLE)
33 #include "common/printf.h"
35 #include "pg/vtx_table.h"
36 #include "drivers/vtx_common.h"
37 #endif
39 #if defined(USE_VTX_TABLE)
40 int vtxTableBandCount;
41 int vtxTableChannelCount;
42 uint16_t vtxTableFrequency[VTX_TABLE_MAX_BANDS][VTX_TABLE_MAX_CHANNELS];
43 const char * vtxTableBandNames[VTX_TABLE_MAX_BANDS + 1];
44 char vtxTableBandLetters[VTX_TABLE_MAX_BANDS + 1];
45 const char * vtxTableChannelNames[VTX_TABLE_MAX_CHANNELS + 1];
46 bool vtxTableIsFactoryBand[VTX_TABLE_MAX_BANDS];
48 int vtxTablePowerLevels;
49 uint16_t vtxTablePowerValues[VTX_TABLE_MAX_POWER_LEVELS];
50 const char * vtxTablePowerLabels[VTX_TABLE_MAX_POWER_LEVELS + 1];
52 #else
54 int vtxTableBandCount = VTX_TABLE_MAX_BANDS;
55 int vtxTableChannelCount = VTX_TABLE_MAX_CHANNELS;
56 uint16_t vtxTableFrequency[VTX_TABLE_MAX_BANDS][VTX_TABLE_MAX_CHANNELS] = {
57 { 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725 }, // Boscam A
58 { 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866 }, // Boscam B
59 { 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945 }, // Boscam E
60 { 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880 }, // FatShark
61 { 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917 }, // RaceBand
63 const char * vtxTableBandNames[VTX_TABLE_MAX_BANDS + 1] = {
64 "--------",
65 "BOSCAM A",
66 "BOSCAM B",
67 "BOSCAM E",
68 "FATSHARK",
69 "RACEBAND",
71 char vtxTableBandLetters[VTX_TABLE_MAX_BANDS + 1] = "-ABEFR";
72 const char * vtxTableChannelNames[VTX_TABLE_MAX_CHANNELS + 1] = {
73 "-", "1", "2", "3", "4", "5", "6", "7", "8",
75 bool vtxTableIsFactoryBand[VTX_TABLE_MAX_BANDS];
76 int vtxTablePowerLevels;
77 uint16_t vtxTablePowerValues[VTX_TABLE_MAX_POWER_LEVELS];
78 const char * vtxTablePowerLabels[VTX_TABLE_MAX_POWER_LEVELS + 1];
79 #endif
81 void vtxTableInit(void)
83 #if defined(USE_VTX_TABLE)
84 const vtxTableConfig_t *config = vtxTableConfig();
86 vtxTableBandCount = config->bands;
87 vtxTableChannelCount = config->channels;
89 for (int band = 0; band < VTX_TABLE_MAX_BANDS; band++) {
90 for (int channel = 0; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
91 vtxTableFrequency[band][channel] = config->frequency[band][channel];
93 vtxTableBandNames[band + 1] = config->bandNames[band];
94 vtxTableBandLetters[band + 1] = config->bandLetters[band];
95 vtxTableIsFactoryBand[band] = config->isFactoryBand[band];
98 vtxTableBandNames[0] = "--------";
99 vtxTableBandLetters[0] = '-';
101 for (int channel = 0; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
102 vtxTableChannelNames[channel + 1] = config->channelNames[channel];
104 vtxTableChannelNames[0] = "-";
106 for (int level = 0; level < VTX_TABLE_MAX_POWER_LEVELS; level++) {
107 vtxTablePowerValues[level] = config->powerValues[level];
108 vtxTablePowerLabels[level + 1] = config->powerLabels[level];
110 vtxTablePowerLabels[0] = "---";
112 vtxTablePowerLevels = config->powerLevels;
113 #else
114 for (int band = 0; band < VTX_TABLE_MAX_BANDS; band++) {
115 vtxTableIsFactoryBand[band] = true;
117 for (int powerIndex = 0; powerIndex < VTX_TABLE_MAX_POWER_LEVELS; powerIndex++) {
118 vtxTablePowerValues[powerIndex] = 0;
119 vtxTablePowerLabels[powerIndex] = NULL;
121 vtxTablePowerLevels = VTX_TABLE_MAX_POWER_LEVELS;
122 vtxTableSetFactoryBands(false);
123 #endif
126 #ifndef USE_VTX_TABLE
127 void vtxTableSetFactoryBands(bool isFactory)
129 for(int i = 0;i < VTX_TABLE_MAX_BANDS; i++) {
130 vtxTableIsFactoryBand[i] = isFactory;
133 #endif
135 #if defined(USE_VTX_TABLE)
137 void vtxTableStrncpyWithPad(char *dst, const char *src, int length)
139 char c;
141 while (length && (c = *src++)) {
142 *dst++ = c;
143 length--;
146 while (length--) {
147 *dst++ = ' ';
150 *dst = 0;
153 // Prune a band to "channels"
154 void vtxTableConfigClearChannels(vtxTableConfig_t *config, int band, int channels)
156 for (int channel = channels; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
157 config->frequency[band][channel] = 0;
161 // Clear a channel name for "channel"
162 void vtxTableConfigClearChannelNames(vtxTableConfig_t *config, int channel)
164 tfp_sprintf(config->channelNames[channel], "%d", channel + 1);
167 void vtxTableConfigClearBand(vtxTableConfig_t *config, int band)
169 vtxTableConfigClearChannels(config, band, 0);
170 for (int channel = 0; channel < VTX_TABLE_MAX_CHANNELS; channel++) {
171 vtxTableConfigClearChannelNames(config, channel);
173 char tempbuf[6];
174 tfp_sprintf(tempbuf, "BAND%d", band + 1);
175 vtxTableStrncpyWithPad(config->bandNames[band], tempbuf, VTX_TABLE_BAND_NAME_LENGTH);
176 config->bandLetters[band] = '1' + band;
177 config->isFactoryBand[band] = false;
180 void vtxTableConfigClearPowerValues(vtxTableConfig_t *config, int start)
182 for (int i = start; i < VTX_TABLE_MAX_POWER_LEVELS; i++) {
183 config->powerValues[i] = 0;
187 void vtxTableConfigClearPowerLabels(vtxTableConfig_t *config, int start)
189 for (int i = start; i < VTX_TABLE_MAX_POWER_LEVELS; i++) {
190 char tempbuf[4];
191 tfp_sprintf(tempbuf, "LV%d", i);
192 vtxTableStrncpyWithPad(config->powerLabels[i], tempbuf, VTX_TABLE_POWER_LABEL_LENGTH);
195 #endif