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"
40 #if defined(USE_VTX_TABLE)
41 int vtxTableBandCount
;
42 int vtxTableChannelCount
;
43 uint16_t vtxTableFrequency
[VTX_TABLE_MAX_BANDS
][VTX_TABLE_MAX_CHANNELS
];
44 const char * vtxTableBandNames
[VTX_TABLE_MAX_BANDS
+ 1];
45 char vtxTableBandLetters
[VTX_TABLE_MAX_BANDS
+ 1];
46 const char * vtxTableChannelNames
[VTX_TABLE_MAX_CHANNELS
+ 1];
47 bool vtxTableIsFactoryBand
[VTX_TABLE_MAX_BANDS
];
49 int vtxTablePowerLevels
;
50 uint16_t vtxTablePowerValues
[VTX_TABLE_MAX_POWER_LEVELS
];
51 const char * vtxTablePowerLabels
[VTX_TABLE_MAX_POWER_LEVELS
+ 1];
55 int vtxTableBandCount
= VTX_TABLE_MAX_BANDS
;
56 int vtxTableChannelCount
= VTX_TABLE_MAX_CHANNELS
;
57 uint16_t vtxTableFrequency
[VTX_TABLE_MAX_BANDS
][VTX_TABLE_MAX_CHANNELS
] = {
58 { 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725 }, // Boscam A
59 { 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866 }, // Boscam B
60 { 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945 }, // Boscam E
61 { 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880 }, // FatShark
62 { 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917 }, // RaceBand
64 const char * vtxTableBandNames
[VTX_TABLE_MAX_BANDS
+ 1] = {
72 char vtxTableBandLetters
[VTX_TABLE_MAX_BANDS
+ 1] = "-ABEFR";
73 const char * vtxTableChannelNames
[VTX_TABLE_MAX_CHANNELS
+ 1] = {
74 "-", "1", "2", "3", "4", "5", "6", "7", "8",
76 bool vtxTableIsFactoryBand
[VTX_TABLE_MAX_BANDS
];
77 int vtxTablePowerLevels
;
78 uint16_t vtxTablePowerValues
[VTX_TABLE_MAX_POWER_LEVELS
];
79 const char * vtxTablePowerLabels
[VTX_TABLE_MAX_POWER_LEVELS
+ 1];
82 void vtxTableInit(void)
84 #if defined(USE_VTX_TABLE)
85 const vtxTableConfig_t
*config
= vtxTableConfig();
87 vtxTableBandCount
= config
->bands
;
88 vtxTableChannelCount
= config
->channels
;
90 for (int band
= 0; band
< VTX_TABLE_MAX_BANDS
; band
++) {
91 for (int channel
= 0; channel
< VTX_TABLE_MAX_CHANNELS
; channel
++) {
92 vtxTableFrequency
[band
][channel
] = config
->frequency
[band
][channel
];
94 vtxTableBandNames
[band
+ 1] = config
->bandNames
[band
];
95 vtxTableBandLetters
[band
+ 1] = config
->bandLetters
[band
];
96 vtxTableIsFactoryBand
[band
] = config
->isFactoryBand
[band
];
99 vtxTableBandNames
[0] = "--------";
100 vtxTableBandLetters
[0] = '-';
102 for (int channel
= 0; channel
< VTX_TABLE_MAX_CHANNELS
; channel
++) {
103 vtxTableChannelNames
[channel
+ 1] = config
->channelNames
[channel
];
105 vtxTableChannelNames
[0] = "-";
107 for (int level
= 0; level
< VTX_TABLE_MAX_POWER_LEVELS
; level
++) {
108 vtxTablePowerValues
[level
] = config
->powerValues
[level
];
109 vtxTablePowerLabels
[level
+ 1] = config
->powerLabels
[level
];
111 vtxTablePowerLabels
[0] = "---";
113 vtxTablePowerLevels
= config
->powerLevels
;
115 for (int band
= 0; band
< VTX_TABLE_MAX_BANDS
; band
++) {
116 vtxTableIsFactoryBand
[band
] = true;
118 for (int powerIndex
= 0; powerIndex
< VTX_TABLE_MAX_POWER_LEVELS
; powerIndex
++) {
119 vtxTablePowerValues
[powerIndex
] = 0;
120 vtxTablePowerLabels
[powerIndex
] = NULL
;
122 vtxTablePowerLevels
= VTX_TABLE_MAX_POWER_LEVELS
;
123 vtxTableSetFactoryBands(false);
127 #ifndef USE_VTX_TABLE
128 void vtxTableSetFactoryBands(bool isFactory
)
130 for(int i
= 0;i
< VTX_TABLE_MAX_BANDS
; i
++) {
131 vtxTableIsFactoryBand
[i
] = isFactory
;
136 #if defined(USE_VTX_TABLE)
138 void vtxTableStrncpyWithPad(char *dst
, const char *src
, int length
)
142 while (length
&& (c
= *src
++)) {
154 // Prune a band to "channels"
155 void vtxTableConfigClearChannels(vtxTableConfig_t
*config
, int band
, int channels
)
157 for (int channel
= channels
; channel
< VTX_TABLE_MAX_CHANNELS
; channel
++) {
158 config
->frequency
[band
][channel
] = 0;
162 // Clear a channel name for "channel"
163 void vtxTableConfigClearChannelNames(vtxTableConfig_t
*config
, int channel
)
165 tfp_sprintf(config
->channelNames
[channel
], "%d", channel
+ 1);
168 void vtxTableConfigClearBand(vtxTableConfig_t
*config
, int band
)
170 vtxTableConfigClearChannels(config
, band
, 0);
171 for (int channel
= 0; channel
< VTX_TABLE_MAX_CHANNELS
; channel
++) {
172 vtxTableConfigClearChannelNames(config
, channel
);
175 tfp_sprintf(tempbuf
, "BAND%d", band
+ 1);
176 vtxTableStrncpyWithPad(config
->bandNames
[band
], tempbuf
, VTX_TABLE_BAND_NAME_LENGTH
);
177 config
->bandLetters
[band
] = '1' + band
;
178 config
->isFactoryBand
[band
] = false;
181 void vtxTableConfigClearPowerValues(vtxTableConfig_t
*config
, int start
)
183 for (int i
= start
; i
< VTX_TABLE_MAX_POWER_LEVELS
; i
++) {
184 config
->powerValues
[i
] = 0;
188 void vtxTableConfigClearPowerLabels(vtxTableConfig_t
*config
, int start
)
190 for (int i
= start
; i
< VTX_TABLE_MAX_POWER_LEVELS
; i
++) {
192 tfp_sprintf(tempbuf
, "LV%d", i
);
193 vtxTableStrncpyWithPad(config
->powerLabels
[i
], tempbuf
, VTX_TABLE_POWER_LABEL_LENGTH
);