constrain fastA2I to [0-9] (vice [0-9A])
[inav.git] / src / main / io / vtx_string.c
blobb86a7ba02777471d135928da69c55e072563431d
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 /* Created by jflyper */
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <ctype.h>
23 #include <string.h>
25 #include "platform.h"
26 #include "build/debug.h"
28 #define VTX_STRING_5G8_BAND_COUNT 5
29 #define VTX_STRING_5G8_CHAN_COUNT 8
30 #define VTX_STRING_5G8_POWER_COUNT 5
32 #define VTX_STRING_1G3_BAND_COUNT 2
33 #define VTX_STRING_1G3_CHAN_COUNT 8
34 #define VTX_STRING_1G3_POWER_COUNT 3
36 const uint16_t vtx58frequencyTable[VTX_STRING_5G8_BAND_COUNT][VTX_STRING_5G8_CHAN_COUNT] =
38 { 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725 }, // A
39 { 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866 }, // B
40 { 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945 }, // E
41 { 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880 }, // F
42 { 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917 }, // R
45 const char * const vtx58BandNames[VTX_STRING_5G8_BAND_COUNT + 1] = {
46 "-",
47 "A",
48 "B",
49 "E",
50 "F",
51 "R",
54 const char vtx58BandLetter[VTX_STRING_5G8_BAND_COUNT + 1] = "-ABEFR";
56 const char * const vtx58ChannelNames[VTX_STRING_5G8_CHAN_COUNT + 1] = {
57 "-", "1", "2", "3", "4", "5", "6", "7", "8",
60 const char * const vtx58DefaultPowerNames[VTX_STRING_5G8_POWER_COUNT + 1] = {
61 "---", "PL1", "PL2", "PL3", "PL4", "PL5"
64 const uint16_t vtx1G3frequencyTable[VTX_STRING_1G3_BAND_COUNT][VTX_STRING_1G3_CHAN_COUNT] =
66 { 1080, 1120, 1160, 1200, 1240, 1280, 1320, 1360 }, // A
67 { 1080, 1120, 1160, 1200, 1258, 1280, 1320, 1360 }, // B
70 const char * const vtx1G3BandNames[VTX_STRING_1G3_BAND_COUNT + 1] = {
71 "-",
72 "A",
73 "B",
76 const char vtx1G3BandLetter[VTX_STRING_1G3_BAND_COUNT + 1] = "-AB";
78 const char * const vtx1G3ChannelNames[VTX_STRING_1G3_CHAN_COUNT + 1] = {
79 "-", "1", "2", "3", "4", "5", "6", "7", "8",
82 const char * const vtx1G3DefaultPowerNames[VTX_STRING_1G3_POWER_COUNT + 1] = {
83 "---", "PL1", "PL2", "PL3"
86 bool vtx58_Freq2Bandchan(uint16_t freq, uint8_t *pBand, uint8_t *pChannel)
88 int8_t band;
89 uint8_t channel;
91 // Use reverse lookup order so that 5880Mhz
92 // get Raceband 7 instead of Fatshark 8.
93 for (band = 4 ; band >= 0 ; band--) {
94 for (channel = 0 ; channel < 8 ; channel++) {
95 if (vtx58frequencyTable[band][channel] == freq) {
96 *pBand = band + 1;
97 *pChannel = channel + 1;
98 return true;
103 *pBand = 0;
104 *pChannel = 0;
106 return false;
109 // Converts band and channel values to a frequency (in MHz) value.
110 // band: Band value (1 to 5).
111 // channel: Channel value (1 to 8).
112 // Returns frequency value (in MHz), or 0 if band/channel out of range.
113 uint16_t vtx58_Bandchan2Freq(uint8_t band, uint8_t channel)
115 if (band > 0 && band <= VTX_STRING_5G8_BAND_COUNT &&
116 channel > 0 && channel <= VTX_STRING_5G8_CHAN_COUNT) {
117 return vtx58frequencyTable[band - 1][channel - 1];
119 return 0;
122 // Converts band and channel values to a frequency (in MHz) value.
123 // band: Band value (1 to 2).
124 // channel: Channel value (1 to 8).
125 // Returns frequency value (in MHz), or 0 if band/channel out of range.
126 uint16_t vtx1G3_Bandchan2Freq(uint8_t band, uint8_t channel)
128 if (band > 0 && band <= VTX_STRING_1G3_BAND_COUNT &&
129 channel > 0 && channel <= VTX_STRING_1G3_CHAN_COUNT) {
130 return vtx1G3frequencyTable[band - 1][channel - 1];
132 return 0;