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"
28 #include "vtx_common.h"
30 static vtxDevice_t
*commonVtxDevice
= NULL
;
32 void vtxCommonInit(void)
36 void vtxCommonSetDevice(vtxDevice_t
*vtxDevice
)
38 commonVtxDevice
= vtxDevice
;
41 vtxDevice_t
*vtxCommonDevice(void)
43 return commonVtxDevice
;
46 void vtxCommonProcess(vtxDevice_t
*vtxDevice
, timeUs_t currentTimeUs
)
48 if (vtxDevice
&& vtxDevice
->vTable
->process
) {
49 vtxDevice
->vTable
->process(vtxDevice
, currentTimeUs
);
53 vtxDevType_e
vtxCommonGetDeviceType(vtxDevice_t
*vtxDevice
)
55 if (!vtxDevice
|| !vtxDevice
->vTable
->getDeviceType
) {
56 return VTXDEV_UNKNOWN
;
59 return vtxDevice
->vTable
->getDeviceType(vtxDevice
);
62 bool vtxCommonDeviceIsReady(vtxDevice_t
*vtxDevice
)
64 if (vtxDevice
&& vtxDevice
->vTable
->isReady
) {
65 return vtxDevice
->vTable
->isReady(vtxDevice
);
70 // band and channel are 1 origin
71 void vtxCommonSetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t band
, uint8_t channel
)
76 if ((band
> vtxDevice
->capability
.bandCount
) || (channel
> vtxDevice
->capability
.channelCount
))
79 if (vtxDevice
->vTable
->setBandAndChannel
) {
80 vtxDevice
->vTable
->setBandAndChannel(vtxDevice
, band
, channel
);
84 // index is zero origin, zero = power off completely
85 void vtxCommonSetPowerByIndex(vtxDevice_t
*vtxDevice
, uint8_t index
)
90 if (index
> vtxDevice
->capability
.powerCount
)
93 if (vtxDevice
->vTable
->setPowerByIndex
) {
94 vtxDevice
->vTable
->setPowerByIndex(vtxDevice
, index
);
99 void vtxCommonSetPitMode(vtxDevice_t
*vtxDevice
, uint8_t onoff
)
101 if (vtxDevice
&& vtxDevice
->vTable
->setPitMode
) {
102 vtxDevice
->vTable
->setPitMode(vtxDevice
, onoff
);
106 bool vtxCommonGetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t *pBand
, uint8_t *pChannel
)
108 if (vtxDevice
&& vtxDevice
->vTable
->getBandAndChannel
) {
109 return vtxDevice
->vTable
->getBandAndChannel(vtxDevice
, pBand
, pChannel
);
114 bool vtxCommonGetPowerIndex(vtxDevice_t
*vtxDevice
, uint8_t *pIndex
)
116 if (vtxDevice
&& vtxDevice
->vTable
->getPowerIndex
) {
117 return vtxDevice
->vTable
->getPowerIndex(vtxDevice
, pIndex
);
122 bool vtxCommonGetPitMode(vtxDevice_t
*vtxDevice
, uint8_t *pOnOff
)
124 if (vtxDevice
&& vtxDevice
->vTable
->getPitMode
) {
125 return vtxDevice
->vTable
->getPitMode(vtxDevice
, pOnOff
);
130 bool vtxCommonGetFrequency(const vtxDevice_t
*vtxDevice
, uint16_t *pFrequency
)
132 if (vtxDevice
&& vtxDevice
->vTable
->getFrequency
) {
133 return vtxDevice
->vTable
->getFrequency(vtxDevice
, pFrequency
);
138 bool vtxCommonGetDeviceCapability(vtxDevice_t
*vtxDevice
, vtxDeviceCapability_t
*pDeviceCapability
)
141 memcpy(pDeviceCapability
, &vtxDevice
->capability
, sizeof(vtxDeviceCapability_t
));
147 bool vtxCommonGetPower(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
, uint16_t *pPowerMw
)
149 if (vtxDevice
&& vtxDevice
->vTable
->getPower
) {
150 return vtxDevice
->vTable
->getPower(vtxDevice
, pIndex
, pPowerMw
);
155 bool vtxCommonGetOsdInfo(vtxDevice_t
*vtxDevice
, vtxDeviceOsdInfo_t
* pOsdInfo
)
159 if (vtxDevice
&& vtxDevice
->vTable
->getOsdInfo
) {
160 ret
= vtxDevice
->vTable
->getOsdInfo(vtxDevice
, pOsdInfo
);
163 // Make sure we provide sane results even in case API fails
166 pOsdInfo
->channel
= 0;
167 pOsdInfo
->frequency
= 0;
168 pOsdInfo
->powerIndex
= 0;
169 pOsdInfo
->powerMilliwatt
= 0;
170 pOsdInfo
->bandLetter
= '-';
171 pOsdInfo
->bandName
= "-";
172 pOsdInfo
->channelName
= "-";
173 pOsdInfo
->powerIndexLetter
= '0';