Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / vtx_common.c
blobb175dad868361af32fa381ec2e06accbf1558199
1 /*
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 */
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <ctype.h>
23 #include <string.h>
25 #include "platform.h"
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);
68 return false;
71 // band and channel are 1 origin
72 void vtxCommonSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel)
74 if (!vtxDevice)
75 return;
77 if ((band > vtxDevice->capability.bandCount) || (channel > vtxDevice->capability.channelCount)) {
78 return;
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)
89 if (!vtxDevice)
90 return;
92 if (index > vtxDevice->capability.powerCount)
93 return;
95 if (vtxDevice->vTable->setPowerByIndex) {
96 vtxDevice->vTable->setPowerByIndex(vtxDevice, index);
100 // on = 1, off = 0
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);
113 return false;
116 bool vtxCommonGetPowerIndex(vtxDevice_t *vtxDevice, uint8_t *pIndex)
118 if (vtxDevice && vtxDevice->vTable->getPowerIndex) {
119 return vtxDevice->vTable->getPowerIndex(vtxDevice, pIndex);
121 return false;
124 bool vtxCommonGetPitMode(vtxDevice_t *vtxDevice, uint8_t *pOnOff)
126 if (vtxDevice && vtxDevice->vTable->getPitMode) {
127 return vtxDevice->vTable->getPitMode(vtxDevice, pOnOff);
129 return false;
132 bool vtxCommonGetFrequency(const vtxDevice_t *vtxDevice, uint16_t *pFrequency)
134 if (vtxDevice && vtxDevice->vTable->getFrequency) {
135 return vtxDevice->vTable->getFrequency(vtxDevice, pFrequency);
137 return false;
140 bool vtxCommonGetDeviceCapability(vtxDevice_t *vtxDevice, vtxDeviceCapability_t *pDeviceCapability)
142 if (vtxDevice) {
143 memcpy(pDeviceCapability, &vtxDevice->capability, sizeof(vtxDeviceCapability_t));
144 return true;
146 return false;
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);
154 return false;
157 bool vtxCommonGetOsdInfo(vtxDevice_t *vtxDevice, vtxDeviceOsdInfo_t * pOsdInfo)
159 bool ret = false;
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
166 if (!ret) {
167 pOsdInfo->band = 0;
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';
178 return ret;