1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

Corrected VTX vtables to not use static device handle

This commit is contained in:
Martin Budden 2018-02-01 09:24:57 +00:00
parent f000d7bf10
commit e2683cd2dc
14 changed files with 259 additions and 281 deletions

View file

@ -30,114 +30,86 @@
#include "drivers/vtx_common.h"
vtxDevice_t *vtxDevice = NULL;
static vtxDevice_t *vtxDevice = NULL;
void vtxCommonInit(void)
{
}
void vtxCommonRegisterDevice(vtxDevice_t *pDevice)
void vtxCommonSetDevice(vtxDevice_t *pDevice)
{
vtxDevice = pDevice;
}
bool vtxCommonDeviceRegistered(void)
vtxDevice_t *vtxCommonDevice(void)
{
return vtxDevice;
}
vtxDevType_e vtxCommonGetDeviceType(void)
vtxDevType_e vtxCommonGetDeviceType(const vtxDevice_t *vtxDevice)
{
if (!vtxDevice || !vtxDevice->vTable->getDeviceType) {
if (!vtxDevice) {
return VTXDEV_UNKNOWN;
}
return vtxDevice->vTable->getDeviceType();
return vtxDevice->vTable->getDeviceType(vtxDevice);
}
void vtxCommonProcess(timeUs_t currentTimeUs) {
if (vtxDevice && vtxDevice->vTable->process) {
vtxDevice->vTable->process(currentTimeUs);
void vtxCommonProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
{
if (vtxDevice) {
vtxDevice->vTable->process(vtxDevice, currentTimeUs);
}
}
// band and channel are 1 origin
void vtxCommonSetBandAndChannel(uint8_t band, uint8_t channel)
void vtxCommonSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel)
{
if (vtxDevice && (band <= vtxDevice->capability.bandCount) && (channel <= vtxDevice->capability.channelCount)) {
if (vtxDevice->vTable->setBandAndChannel) {
vtxDevice->vTable->setBandAndChannel(band, channel);
}
if (band <= vtxDevice->capability.bandCount && channel <= vtxDevice->capability.channelCount) {
vtxDevice->vTable->setBandAndChannel(vtxDevice, band, channel);
}
}
// index is zero origin, zero = power off completely
void vtxCommonSetPowerByIndex(uint8_t index)
void vtxCommonSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t index)
{
if (vtxDevice && (index < vtxDevice->capability.powerCount)) {
if (vtxDevice->vTable->setPowerByIndex) {
vtxDevice->vTable->setPowerByIndex(index);
}
if (index < vtxDevice->capability.powerCount) {
vtxDevice->vTable->setPowerByIndex(vtxDevice, index);
}
}
// on = 1, off = 0
void vtxCommonSetPitMode(uint8_t onoff)
void vtxCommonSetPitMode(vtxDevice_t *vtxDevice, uint8_t onOff)
{
if (vtxDevice && vtxDevice->vTable->setPitMode) {
vtxDevice->vTable->setPitMode(onoff);
}
vtxDevice->vTable->setPitMode(vtxDevice, onOff);
}
void vtxCommonSetFrequency(uint16_t freq)
void vtxCommonSetFrequency(vtxDevice_t *vtxDevice, uint16_t frequency)
{
if (vtxDevice && vtxDevice->vTable->setFrequency) {
vtxDevice->vTable->setFrequency(freq);
}
vtxDevice->vTable->setFrequency(vtxDevice, frequency);
}
bool vtxCommonGetBandAndChannel(uint8_t *pBand, uint8_t *pChannel)
bool vtxCommonGetBandAndChannel(const vtxDevice_t *vtxDevice, uint8_t *pBand, uint8_t *pChannel)
{
if (vtxDevice && vtxDevice->vTable->getBandAndChannel) {
return vtxDevice->vTable->getBandAndChannel(pBand, pChannel);
} else {
return false;
}
return vtxDevice->vTable->getBandAndChannel(vtxDevice, pBand, pChannel);
}
bool vtxCommonGetPowerIndex(uint8_t *pIndex)
bool vtxCommonGetPowerIndex(const vtxDevice_t *vtxDevice, uint8_t *pIndex)
{
if (vtxDevice && vtxDevice->vTable->getPowerIndex) {
return vtxDevice->vTable->getPowerIndex(pIndex);
} else {
return false;
}
return vtxDevice->vTable->getPowerIndex(vtxDevice, pIndex);
}
bool vtxCommonGetPitMode(uint8_t *pOnOff)
bool vtxCommonGetPitMode(const vtxDevice_t *vtxDevice, uint8_t *pOnOff)
{
if (vtxDevice && vtxDevice->vTable->getPitMode) {
return vtxDevice->vTable->getPitMode(pOnOff);
} else {
return false;
}
return vtxDevice->vTable->getPitMode(vtxDevice, pOnOff);
}
bool vtxCommonGetFrequency(uint16_t *pFreq)
bool vtxCommonGetFrequency(const vtxDevice_t *vtxDevice, uint16_t *pFrequency)
{
if (vtxDevice && vtxDevice->vTable->getFrequency) {
return vtxDevice->vTable->getFrequency(pFreq);
} else {
return false;
}
return vtxDevice->vTable->getFrequency(vtxDevice, pFrequency);
}
bool vtxCommonGetDeviceCapability(vtxDeviceCapability_t *pDeviceCapability)
bool vtxCommonGetDeviceCapability(const vtxDevice_t *vtxDevice, vtxDeviceCapability_t *pDeviceCapability)
{
if (!vtxDevice) {
return false;
}
memcpy(pDeviceCapability, &vtxDevice->capability, sizeof(vtxDeviceCapability_t));
return true;
}