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/>.
19 // Get target build configuration
21 #include "build/debug.h"
23 #include "common/maths.h"
24 #include "common/log.h"
26 #include "config/config_eeprom.h"
27 #include "config/parameter_group.h"
28 #include "config/parameter_group_ids.h"
30 #include "drivers/vtx_common.h"
31 #include "drivers/light_led.h"
32 #include "drivers/system.h"
34 #include "fc/config.h"
35 #include "fc/runtime_config.h"
36 #include "fc/settings.h"
38 #include "io/beeper.h"
40 #include "io/vtx_control.h"
42 #if defined(USE_VTX_CONTROL)
44 PG_REGISTER_WITH_RESET_TEMPLATE(vtxConfig_t
, vtxConfig
, PG_VTX_CONFIG
, 4);
46 PG_RESET_TEMPLATE(vtxConfig_t
, vtxConfig
,
47 .halfDuplex
= SETTING_VTX_HALFDUPLEX_DEFAULT
,
48 .smartAudioEarlyAkkWorkaroundEnable
= SETTING_VTX_SMARTAUDIO_EARLY_AKK_WORKAROUND_DEFAULT
,
49 .smartAudioAltSoftSerialMethod
= SETTING_VTX_SMARTAUDIO_ALTERNATE_SOFTSERIAL_METHOD_DEFAULT
,
50 .softSerialShortStop
= SETTING_VTX_SOFTSERIAL_SHORTSTOP_DEFAULT
,
51 .smartAudioStopBits
= SETTING_VTX_SMARTAUDIO_STOPBITS_DEFAULT
,
54 static uint8_t locked
= 0;
56 void vtxControlInit(void)
61 void vtxControlInputPoll(void)
63 // Check variuos input sources for VTX config updates
65 // XXX: None supported in INAV
68 static void vtxUpdateBandAndChannel(uint8_t bandStep
, uint8_t channelStep
)
70 if (ARMING_FLAG(ARMED
)) {
75 vtxDevice_t
*vtxDevice
= vtxCommonDevice();
77 uint8_t band
= 0, channel
= 0;
78 vtxCommonGetBandAndChannel(vtxDevice
, &band
, &channel
);
79 vtxCommonSetBandAndChannel(vtxDevice
, band
+ bandStep
, channel
+ channelStep
);
84 void vtxIncrementBand(void)
86 vtxUpdateBandAndChannel(+1, 0);
89 void vtxDecrementBand(void)
91 vtxUpdateBandAndChannel(-1, 0);
94 void vtxIncrementChannel(void)
96 vtxUpdateBandAndChannel(0, +1);
99 void vtxDecrementChannel(void)
101 vtxUpdateBandAndChannel(0, -1);
104 void vtxUpdateActivatedChannel(void)
106 if (ARMING_FLAG(ARMED
)) {
111 vtxDevice_t
*vtxDevice
= vtxCommonDevice();
113 static uint8_t lastIndex
= -1;
115 for (uint8_t index
= 0; index
< MAX_CHANNEL_ACTIVATION_CONDITION_COUNT
; index
++) {
116 const vtxChannelActivationCondition_t
*vtxChannelActivationCondition
= &vtxConfig()->vtxChannelActivationConditions
[index
];
118 if (isRangeActive(vtxChannelActivationCondition
->auxChannelIndex
, &vtxChannelActivationCondition
->range
)
119 && index
!= lastIndex
) {
122 vtxCommonSetBandAndChannel(vtxDevice
, vtxChannelActivationCondition
->band
, vtxChannelActivationCondition
->channel
);
130 void vtxCycleBandOrChannel(const uint8_t bandStep
, const uint8_t channelStep
)
132 vtxDevice_t
*vtxDevice
= vtxCommonDevice();
138 uint8_t band
= 0, channel
= 0;
139 vtxDeviceCapability_t capability
;
141 bool haveAllNeededInfo
= vtxCommonGetBandAndChannel(vtxDevice
, &band
, &channel
) && vtxCommonGetDeviceCapability(vtxDevice
, &capability
);
142 if (!haveAllNeededInfo
) {
146 int newChannel
= channel
+ channelStep
;
147 if (newChannel
> capability
.channelCount
) {
149 } else if (newChannel
< 1) {
150 newChannel
= capability
.channelCount
;
153 int newBand
= band
+ bandStep
;
154 if (newBand
> capability
.bandCount
) {
156 } else if (newBand
< 1) {
157 newBand
= capability
.bandCount
;
160 vtxCommonSetBandAndChannel(vtxDevice
, newBand
, newChannel
);
163 void vtxCyclePower(const uint8_t powerStep
)
165 vtxDevice_t
*vtxDevice
= vtxCommonDevice();
172 vtxDeviceCapability_t capability
;
174 bool haveAllNeededInfo
= vtxCommonGetPowerIndex(vtxDevice
, &power
) && vtxCommonGetDeviceCapability(vtxDevice
, &capability
);
175 if (!haveAllNeededInfo
) {
179 int newPower
= power
+ powerStep
;
180 if (newPower
>= capability
.powerCount
) {
182 } else if (newPower
< 0) {
183 newPower
= capability
.powerCount
;
186 vtxCommonSetPowerByIndex(vtxDevice
, newPower
);