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)
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 */
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"
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];
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] = {
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];
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
;
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);
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
;
135 #if defined(USE_VTX_TABLE)
137 void vtxTableStrncpyWithPad(char *dst
, const char *src
, int length
)
141 while (length
&& (c
= *src
++)) {
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
);
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
++) {
191 tfp_sprintf(tempbuf
, "LV%d", i
);
192 vtxTableStrncpyWithPad(config
->powerLabels
[i
], tempbuf
, VTX_TABLE_POWER_LABEL_LENGTH
);