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 */
26 #include "build/debug.h"
27 #include "common/log.h"
29 #include "vtx_common.h"
31 static vtxDevice_t
*commonVtxDevice
= NULL
;
33 void vtxCommonInit(void)
37 void vtxCommonSetDevice(vtxDevice_t
*vtxDevice
)
39 commonVtxDevice
= vtxDevice
;
42 vtxDevice_t
*vtxCommonDevice(void)
44 return commonVtxDevice
;
47 void vtxCommonProcess(vtxDevice_t
*vtxDevice
, timeUs_t currentTimeUs
)
49 if (vtxDevice
&& vtxDevice
->vTable
->process
) {
50 vtxDevice
->vTable
->process(vtxDevice
, currentTimeUs
);
54 vtxDevType_e
vtxCommonGetDeviceType(vtxDevice_t
*vtxDevice
)
56 if (!vtxDevice
|| !vtxDevice
->vTable
->getDeviceType
) {
57 return VTXDEV_UNKNOWN
;
60 return vtxDevice
->vTable
->getDeviceType(vtxDevice
);
63 bool vtxCommonDeviceIsReady(vtxDevice_t
*vtxDevice
)
65 if (vtxDevice
&& vtxDevice
->vTable
->isReady
) {
66 return vtxDevice
->vTable
->isReady(vtxDevice
);
71 // band and channel are 1 origin
72 void vtxCommonSetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t band
, uint8_t channel
)
77 if ((band
> vtxDevice
->capability
.bandCount
) || (channel
> vtxDevice
->capability
.channelCount
)) {
81 if (vtxDevice
->vTable
->setBandAndChannel
) {
82 vtxDevice
->vTable
->setBandAndChannel(vtxDevice
, band
, channel
);
86 // index is zero origin, zero = power off completely
87 void vtxCommonSetPowerByIndex(vtxDevice_t
*vtxDevice
, uint8_t index
)
92 if (index
> vtxDevice
->capability
.powerCount
)
95 if (vtxDevice
->vTable
->setPowerByIndex
) {
96 vtxDevice
->vTable
->setPowerByIndex(vtxDevice
, index
);
101 void vtxCommonSetPitMode(vtxDevice_t
*vtxDevice
, uint8_t onoff
)
103 if (vtxDevice
&& vtxDevice
->vTable
->setPitMode
) {
104 vtxDevice
->vTable
->setPitMode(vtxDevice
, onoff
);
108 bool vtxCommonGetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t *pBand
, uint8_t *pChannel
)
110 if (vtxDevice
&& vtxDevice
->vTable
->getBandAndChannel
) {
111 return vtxDevice
->vTable
->getBandAndChannel(vtxDevice
, pBand
, pChannel
);
116 bool vtxCommonGetPowerIndex(vtxDevice_t
*vtxDevice
, uint8_t *pIndex
)
118 if (vtxDevice
&& vtxDevice
->vTable
->getPowerIndex
) {
119 return vtxDevice
->vTable
->getPowerIndex(vtxDevice
, pIndex
);
124 bool vtxCommonGetPitMode(vtxDevice_t
*vtxDevice
, uint8_t *pOnOff
)
126 if (vtxDevice
&& vtxDevice
->vTable
->getPitMode
) {
127 return vtxDevice
->vTable
->getPitMode(vtxDevice
, pOnOff
);
132 bool vtxCommonGetFrequency(const vtxDevice_t
*vtxDevice
, uint16_t *pFrequency
)
134 if (vtxDevice
&& vtxDevice
->vTable
->getFrequency
) {
135 return vtxDevice
->vTable
->getFrequency(vtxDevice
, pFrequency
);
140 bool vtxCommonGetDeviceCapability(vtxDevice_t
*vtxDevice
, vtxDeviceCapability_t
*pDeviceCapability
)
143 memcpy(pDeviceCapability
, &vtxDevice
->capability
, sizeof(vtxDeviceCapability_t
));
149 bool vtxCommonGetPower(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
, uint16_t *pPowerMw
)
151 if (vtxDevice
&& vtxDevice
->vTable
->getPower
) {
152 return vtxDevice
->vTable
->getPower(vtxDevice
, pIndex
, pPowerMw
);
157 bool vtxCommonGetOsdInfo(vtxDevice_t
*vtxDevice
, vtxDeviceOsdInfo_t
* pOsdInfo
)
161 if (vtxDevice
&& vtxDevice
->vTable
->getOsdInfo
) {
162 ret
= vtxDevice
->vTable
->getOsdInfo(vtxDevice
, pOsdInfo
);
165 // Make sure we provide sane results even in case API fails
168 pOsdInfo
->channel
= 0;
169 pOsdInfo
->frequency
= 0;
170 pOsdInfo
->powerIndex
= 0;
171 pOsdInfo
->powerMilliwatt
= 0;
172 pOsdInfo
->bandLetter
= '-';
173 pOsdInfo
->bandName
= "-";
174 pOsdInfo
->channelName
= "-";
175 pOsdInfo
->powerIndexLetter
= '0';