Merge pull request #4455 from codecae/vtx_settings_pg_rework

Move vtxSettingsConfig to vtx_common.  Rework MSP_SET_VTX_CONFIG and CMS.
This commit is contained in:
Michael Keller 2017-11-10 08:14:36 +13:00 committed by GitHub
commit 39727ce384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 418 additions and 547 deletions

View File

@ -171,7 +171,7 @@ FC_SRC = \
telemetry/ibus_shared.c \
sensors/esc_sensor.c \
io/vtx_string.c \
io/vtx_settings_config.c \
io/vtx.c \
io/vtx_rtc6705.c \
io/vtx_smartaudio.c \
io/vtx_tramp.c \
@ -275,7 +275,7 @@ SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \
cms/cms_menu_vtx_smartaudio.c \
cms/cms_menu_vtx_tramp.c \
io/vtx_string.c \
io/vtx_settings_config.c \
io/vtx.c \
io/vtx_rtc6705.c \
io/vtx_smartaudio.c \
io/vtx_tramp.c \

View File

@ -29,11 +29,13 @@
#include "cms/cms.h"
#include "cms/cms_types.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
#include "io/vtx_string.h"
#include "io/vtx_rtc6705.h"
#include "io/vtx_settings_config.h"
#if defined(VTX_SETTINGS_CONFIG)
#include "io/vtx.h"
static uint8_t cmsx_vtxBand;
static uint8_t cmsx_vtxChannel;
@ -60,7 +62,13 @@ static void cmsx_Vtx_ConfigRead(void)
static void cmsx_Vtx_ConfigWriteback(void)
{
vtxSettingsSaveBandChanAndPower(cmsx_vtxBand + 1, cmsx_vtxChannel, cmsx_vtxPower + VTX_RTC6705_MIN_POWER);
// update vtx_ settings
vtxSettingsConfigMutable()->band = cmsx_vtxBand + 1;
vtxSettingsConfigMutable()->channel = cmsx_vtxChannel;
vtxSettingsConfigMutable()->power = cmsx_vtxPower + VTX_RTC6705_MIN_POWER;
vtxSettingsConfigMutable()->freq = vtx58_Bandchan2Freq(cmsx_vtxBand + 1, cmsx_vtxChannel);
saveConfigAndNotify();
}
static long cmsx_Vtx_onEnter(void)
@ -99,6 +107,4 @@ CMS_Menu cmsx_menuVtxRTC6705 = {
.entries = cmsx_menuVtxEntries
};
#endif // VTX_SETTINGS_CONFIG
#endif // CMS

View File

@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include "platform.h"
@ -30,9 +31,13 @@
#include "cms/cms_types.h"
#include "cms/cms_menu_vtx_smartaudio.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
#include "io/vtx_string.h"
#include "io/vtx_smartaudio.h"
#include "io/vtx_settings_config.h"
#include "io/vtx.h"
// Interface to CMS
@ -76,18 +81,16 @@ uint16_t saCmsUserFreqNew; // User defined frequency
void saCmsUpdate(void)
{
// XXX Take care of pit mode update somewhere???
if (saCmsOpmodel == SACMS_OPMODEL_UNDEF) {
// This is a first valid response to GET_SETTINGS.
saCmsOpmodel = (saDevice.mode & SA_MODE_GET_PITMODE) ? SACMS_OPMODEL_RACE : SACMS_OPMODEL_FREE;
saCmsFselMode = (saDevice.mode & SA_MODE_GET_FREQ_BY_FREQ) ? 1 : 0;
saCmsBand = (saDevice.channel / 8) + 1;
saCmsChan = (saDevice.channel % 8) + 1;
saCmsFreqRef = vtx58frequencyTable[saDevice.channel / 8][saDevice.channel % 8];
saCmsDeviceFreq = vtx58frequencyTable[saDevice.channel / 8][saDevice.channel % 8];
saCmsBand = vtxSettingsConfig()->band;
saCmsChan = vtxSettingsConfig()->channel;
saCmsFreqRef = vtxSettingsConfig()->freq;
saCmsDeviceFreq = saCmsFreqRef;
if ((saDevice.mode & SA_MODE_GET_PITMODE) == 0) {
saCmsRFState = SACMS_TXMODE_ACTIVE;
@ -97,15 +100,11 @@ void saCmsUpdate(void)
saCmsRFState = SACMS_TXMODE_PIT_OUTRANGE;
}
if (saDevice.version == 2) {
saCmsPower = saDevice.power + 1; // XXX Take care V1
} else {
saCmsPower = saDacToPowerIndex(saDevice.power) + 1;
}
saCmsPower = vtxSettingsConfig()->power;
// if user-freq mode then track possible change
if (saCmsFselMode != 0 && saDevice.freq != 0) {
saCmsUserFreq = saDevice.freq;
if (saCmsFselMode && vtxSettingsConfig()->freq) {
saCmsUserFreq = vtxSettingsConfig()->freq;
}
saCmsFselModeNew = saCmsFselMode; //init mode for menu
@ -252,8 +251,9 @@ static long saCmsConfigPowerByGvar(displayPort_t *pDisp, const void *self)
return 0;
}
if (saCmsOpmodel == SACMS_OPMODEL_FREE)
saSetPowerByIndex(saCmsPower - 1);
if (saCmsOpmodel == SACMS_OPMODEL_FREE && !saDeferred) {
vtxSettingsConfigMutable()->power = saCmsPower;
}
return 0;
}
@ -417,12 +417,21 @@ static long saCmsCommence(displayPort_t *pDisp, const void *self)
UNUSED(pDisp);
UNUSED(self);
const vtxSettingsConfig_t prevSettings = {
.band = vtxSettingsConfig()->band,
.channel = vtxSettingsConfig()->channel,
.freq = vtxSettingsConfig()->freq,
.power = vtxSettingsConfig()->power,
};
vtxSettingsConfig_t newSettings = prevSettings;
if (saCmsOpmodel == SACMS_OPMODEL_RACE) {
// Race model
// Setup band, freq and power.
saSetBandAndChannel(saCmsBand - 1, saCmsChan - 1);
newSettings.band = saCmsBand;
newSettings.channel = saCmsChan;
newSettings.freq = vtx58_Bandchan2Freq(saCmsBand, saCmsChan);
// If in pit mode, cancel it.
if (saCmsPitFMode == 0)
@ -433,14 +442,25 @@ static long saCmsCommence(displayPort_t *pDisp, const void *self)
// Freestyle model
// Setup band and freq / user freq
if (saCmsFselModeNew == 0) {
saSetBandAndChannel(saCmsBand - 1, saCmsChan - 1);
newSettings.band = saCmsBand;
newSettings.channel = saCmsChan;
newSettings.freq = vtx58_Bandchan2Freq(saCmsBand, saCmsChan);
} else {
saSetMode(0); //make sure FREE mode is setup
saSetFreq(saCmsUserFreq);
newSettings.band = 0;
newSettings.freq = saCmsUserFreq;
}
}
saSetPowerByIndex(saCmsPower - 1);
newSettings.power = saCmsPower;
if (memcmp(&prevSettings, &newSettings, sizeof(vtxSettingsConfig_t))) {
vtxSettingsConfigMutable()->band = newSettings.band;
vtxSettingsConfigMutable()->channel = newSettings.channel;
vtxSettingsConfigMutable()->power = newSettings.power;
vtxSettingsConfigMutable()->freq = newSettings.freq;
saveConfigAndNotify();
}
return MENU_CHAIN_BACK;
}
@ -496,7 +516,6 @@ static long saCmsConfigUserFreq(displayPort_t *pDisp, const void *self)
UNUSED(self);
saCmsUserFreq = saCmsUserFreqNew;
//saSetFreq(saCmsUserFreq);
return MENU_CHAIN_BACK;
}
@ -504,8 +523,8 @@ static long saCmsConfigUserFreq(displayPort_t *pDisp, const void *self)
static OSD_Entry saCmsMenuPORFreqEntries[] = {
{ "- POR FREQ -", OME_Label, NULL, NULL, 0 },
{ "CUR FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsORFreq, 5000, 5900, 0 }, DYNAMIC },
{ "NEW FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsORFreqNew, 5000, 5900, 1 }, 0 },
{ "CUR FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsORFreq, 5000, 5999, 0 }, DYNAMIC },
{ "NEW FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsORFreqNew, 5000, 5999, 1 }, 0 },
{ "SET", OME_Funcall, saCmsSetPORFreq, NULL, 0 },
{ "BACK", OME_Back, NULL, NULL, 0 },
@ -525,8 +544,8 @@ static CMS_Menu saCmsMenuPORFreq =
static OSD_Entry saCmsMenuUserFreqEntries[] = {
{ "- USER FREQ -", OME_Label, NULL, NULL, 0 },
{ "CUR FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsUserFreq, 5000, 5900, 0 }, DYNAMIC },
{ "NEW FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsUserFreqNew, 5000, 5900, 1 }, 0 },
{ "CUR FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsUserFreq, 5000, 5999, 0 }, DYNAMIC },
{ "NEW FREQ", OME_UINT16, NULL, &(OSD_UINT16_t){ &saCmsUserFreqNew, 5000, 5999, 1 }, 0 },
{ "SET", OME_Funcall, saCmsConfigUserFreq, NULL, 0 },
{ "BACK", OME_Back, NULL, NULL, 0 },

View File

@ -29,10 +29,13 @@
#include "cms/cms.h"
#include "cms/cms_types.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
#include "io/vtx_string.h"
#include "io/vtx_tramp.h"
#include "io/vtx_settings_config.h"
#include "io/vtx.h"
char trampCmsStatusString[31] = "- -- ---- ----";
// m bc ffff tppp
@ -154,7 +157,12 @@ static long trampCmsCommence(displayPort_t *pDisp, const void *self)
trampCommitChanges();
// update'vtx_' settings
vtxSettingsSaveBandChanAndPower(trampCmsBand, trampCmsChan, trampCmsPower);
vtxSettingsConfigMutable()->band = trampCmsBand;
vtxSettingsConfigMutable()->channel = trampCmsChan;
vtxSettingsConfigMutable()->power = trampCmsPower;
vtxSettingsConfigMutable()->freq = vtx58_Bandchan2Freq(trampCmsBand, trampCmsChan);
saveConfigAndNotify();
return MENU_CHAIN_BACK;
}

View File

@ -24,19 +24,18 @@
#include "platform.h"
#include "build/debug.h"
#include "common/time.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
#if defined(VTX_COMMON)
#include "vtx_common.h"
vtxDevice_t *vtxDevice = NULL;
void vtxCommonInit(void)
{
}
// Whatever registered last will win
void vtxCommonRegisterDevice(vtxDevice_t *pDevice)
{
vtxDevice = pDevice;
@ -47,15 +46,6 @@ bool vtxCommonDeviceRegistered(void)
return vtxDevice;
}
void vtxCommonProcess(uint32_t currentTimeUs)
{
if (!vtxDevice)
return;
if (vtxDevice->vTable->process)
vtxDevice->vTable->process(currentTimeUs);
}
vtxDevType_e vtxCommonGetDeviceType(void)
{
if (!vtxDevice || !vtxDevice->vTable->getDeviceType)
@ -64,47 +54,41 @@ vtxDevType_e vtxCommonGetDeviceType(void)
return vtxDevice->vTable->getDeviceType();
}
void vtxCommonProcess(timeUs_t currentTimeUs) {
if (vtxDevice->vTable->process) {
vtxDevice->vTable->process(currentTimeUs);
}
}
// band and channel are 1 origin
void vtxCommonSetBandAndChannel(uint8_t band, uint8_t channel)
{
if (!vtxDevice)
return;
if ((band > vtxDevice->capability.bandCount) || (channel > vtxDevice->capability.channelCount))
return;
if (vtxDevice->vTable->setBandAndChannel)
vtxDevice->vTable->setBandAndChannel(band, channel);
if ((band <= vtxDevice->capability.bandCount) && (channel <= vtxDevice->capability.channelCount)) {
if (vtxDevice->vTable->setBandAndChannel) {
vtxDevice->vTable->setBandAndChannel(band, channel);
}
}
}
// index is zero origin, zero = power off completely
void vtxCommonSetPowerByIndex(uint8_t index)
{
if (!vtxDevice)
return;
if (index > vtxDevice->capability.powerCount)
return;
if (vtxDevice->vTable->setPowerByIndex)
vtxDevice->vTable->setPowerByIndex(index);
if (index <= vtxDevice->capability.powerCount) {
if (vtxDevice->vTable->setPowerByIndex) {
vtxDevice->vTable->setPowerByIndex(index);
}
}
}
// on = 1, off = 0
void vtxCommonSetPitMode(uint8_t onoff)
{
if (!vtxDevice)
return;
if (vtxDevice->vTable->setPitMode)
vtxDevice->vTable->setPitMode(onoff);
}
void vtxCommonSetFrequency(uint16_t freq)
{
if (!vtxDevice) {
return;
}
if (vtxDevice->vTable->setFrequency) {
vtxDevice->vTable->setFrequency(freq);
}
@ -112,9 +96,6 @@ void vtxCommonSetFrequency(uint16_t freq)
bool vtxCommonGetBandAndChannel(uint8_t *pBand, uint8_t *pChannel)
{
if (!vtxDevice)
return false;
if (vtxDevice->vTable->getBandAndChannel)
return vtxDevice->vTable->getBandAndChannel(pBand, pChannel);
else
@ -163,4 +144,5 @@ bool vtxCommonGetDeviceCapability(vtxDeviceCapability_t *pDeviceCapability)
memcpy(pDeviceCapability, &vtxDevice->capability, sizeof(vtxDeviceCapability_t));
return true;
}
#endif

View File

@ -19,22 +19,54 @@
#pragma once
#include "common/time.h"
#include "io/vtx.h"
#define VTX_SETTINGS_MIN_BAND 1
#define VTX_SETTINGS_MAX_BAND 5
#define VTX_SETTINGS_MIN_CHANNEL 1
#define VTX_SETTINGS_MAX_CHANNEL 8
#define VTX_SETTINGS_BAND_COUNT (VTX_SETTINGS_MAX_BAND - VTX_SETTINGS_MIN_BAND + 1)
#define VTX_SETTINGS_CHANNEL_COUNT (VTX_SETTINGS_MAX_CHANNEL - VTX_SETTINGS_MIN_CHANNEL + 1)
#define VTX_SETTINGS_DEFAULT_BAND 4
#define VTX_SETTINGS_DEFAULT_CHANNEL 1
#define VTX_SETTINGS_DEFAULT_FREQ 5740
#define VTX_SETTINGS_MAX_FREQUENCY_MHZ 5999 //max freq (in MHz) for 'vtx_freq' setting
#if defined(VTX_SMARTAUDIO) || defined(VTX_TRAMP)
#define VTX_SETTINGS_POWER_COUNT 5
#define VTX_SETTINGS_DEFAULT_POWER 1
#define VTX_SETTINGS_MIN_POWER 0
#define VTX_SETTINGS_FREQCMD
#elif defined(VTX_RTC6705)
#include "io/vtx_rtc6705.h"
#define VTX_SETTINGS_POWER_COUNT VTX_RTC6705_POWER_COUNT
#define VTX_SETTINGS_DEFAULT_POWER VTX_RTC6705_DEFAULT_POWER
#define VTX_SETTINGS_MIN_POWER VTX_RTC6705_MIN_POWER
#endif
// check value for MSP_SET_VTX_CONFIG to determine if value is encoded
// band/channel or frequency in MHz (3 bits for band and 3 bits for channel)
#define VTXCOMMON_MSP_BANDCHAN_CHKVAL ((uint16_t)((7 << 3) + 7))
typedef enum {
VTXDEV_UNSUPPORTED = 0, // reserved for MSP
VTXDEV_RTC6705 = 1,
VTXDEV_RTC6705 = 1,
// 2 reserved
VTXDEV_SMARTAUDIO = 3,
VTXDEV_TRAMP = 4,
VTXDEV_UNKNOWN = 0xFF,
VTXDEV_SMARTAUDIO = 3,
VTXDEV_TRAMP = 4,
VTXDEV_UNKNOWN = 0xFF,
} vtxDevType_e;
// VTX magic numbers
#define VTX_COMMON_BAND_USER 0
#define VTX_COMMON_BAND_A 1
#define VTX_COMMON_BAND_B 2
@ -47,14 +79,14 @@ typedef enum {
#define VTX_6705_POWER_25 1
#define VTX_6705_POWER_200 2
// SmartAudio "---", 25, 200, 500. 800 mW
// SmartAudio "---", 25, 200, 500, 800 mW
#define VTX_SA_POWER_OFF 0
#define VTX_SA_POWER_25 1
#define VTX_SA_POWER_200 2
#define VTX_SA_POWER_500 3
#define VTX_SA_POWER_800 4
// Tramp "---", 25, 200, 400. 600 mW
// Tramp "---", 25, 100, 200, 400, 600 mW
#define VTX_TRAMP_POWER_OFF 0
#define VTX_TRAMP_POWER_25 1
#define VTX_TRAMP_POWER_100 2
@ -117,7 +149,7 @@ void vtxCommonRegisterDevice(vtxDevice_t *pDevice);
bool vtxCommonDeviceRegistered(void);
// VTable functions
void vtxCommonProcess(uint32_t currentTimeUs);
void vtxCommonProcess(timeUs_t currentTimeUs);
uint8_t vtxCommonGetDeviceType(void);
void vtxCommonSetBandAndChannel(uint8_t band, uint8_t channel);
void vtxCommonSetPowerByIndex(uint8_t level);

View File

@ -81,6 +81,7 @@ extern uint8_t __config_end;
#include "drivers/vcd.h"
#include "drivers/light_led.h"
#include "drivers/camera_control.h"
#include "drivers/vtx_common.h"
#include "fc/settings.h"
#include "fc/cli.h"
@ -113,7 +114,7 @@ extern uint8_t __config_end;
#include "io/serial.h"
#include "io/transponder_ir.h"
#include "io/vtx_control.h"
#include "io/vtx_settings_config.h"
#include "io/vtx.h"
#include "msp/msp_protocol.h"

View File

@ -100,6 +100,7 @@
#include "io/osd.h"
#include "io/osd_slave.h"
#include "io/displayport_msp.h"
#include "io/vtx.h"
#include "io/vtx_rtc6705.h"
#include "io/vtx_control.h"
#include "io/vtx_smartaudio.h"
@ -665,7 +666,10 @@ void init(void)
#ifdef VTX_CONTROL
vtxControlInit();
#if defined(VTX_COMMON)
vtxCommonInit();
vtxInit();
#endif
#ifdef VTX_SMARTAUDIO
vtxSmartAudioInit();

View File

@ -90,6 +90,8 @@
#include "io/servos.h"
#include "io/transponder_ir.h"
#include "io/vtx_control.h"
#include "io/vtx.h"
#include "io/vtx_string.h"
#include "msp/msp.h"
#include "msp/msp_protocol.h"
@ -1201,25 +1203,14 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
{
uint8_t deviceType = vtxCommonGetDeviceType();
if (deviceType != VTXDEV_UNKNOWN) {
uint8_t band=0, channel=0;
vtxCommonGetBandAndChannel(&band,&channel);
uint8_t powerIdx=0; // debug
vtxCommonGetPowerIndex(&powerIdx);
uint8_t pitmode=0;
vtxCommonGetPitMode(&pitmode);
uint16_t freq = 0;
vtxCommonGetFrequency(&freq);
sbufWriteU8(dst, deviceType);
sbufWriteU8(dst, band);
sbufWriteU8(dst, channel);
sbufWriteU8(dst, powerIdx);
sbufWriteU8(dst, vtxSettingsConfig()->band);
sbufWriteU8(dst, vtxSettingsConfig()->channel);
sbufWriteU8(dst, vtxSettingsConfig()->power);
sbufWriteU8(dst, pitmode);
sbufWriteU16(dst, freq);
sbufWriteU16(dst, vtxSettingsConfig()->freq);
// future extensions here...
} else {
sbufWriteU8(dst, VTXDEV_UNKNOWN); // no VTX detected
@ -1674,43 +1665,31 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
#ifdef VTX_COMMON
case MSP_SET_VTX_CONFIG:
{
const uint16_t tmp = sbufReadU16(src);
if (vtxCommonGetDeviceType() != VTXDEV_UNKNOWN) {
if (tmp <= VTXCOMMON_MSP_BANDCHAN_CHKVAL) { //value is band and channel
const uint8_t band = (tmp / 8) + 1;
const uint8_t channel = (tmp % 8) + 1;
uint8_t current_band = 0, current_channel = 0;
vtxCommonGetBandAndChannel(&current_band, &current_channel);
if ((current_band != band) || (current_channel != channel)) {
vtxCommonSetBandAndChannel(band, channel);
if (vtxCommonDeviceRegistered()) {
if (vtxCommonGetDeviceType() != VTXDEV_UNKNOWN) {
uint16_t newFrequency = sbufReadU16(src);
if (newFrequency <= VTXCOMMON_MSP_BANDCHAN_CHKVAL) { //value is band and channel
const uint8_t newBand = (newFrequency / 8) + 1;
const uint8_t newChannel = (newFrequency % 8) + 1;
vtxSettingsConfigMutable()->band = newBand;
vtxSettingsConfigMutable()->channel = newChannel;
vtxSettingsConfigMutable()->freq = vtx58_Bandchan2Freq(newBand, newChannel);
} else { //value is frequency in MHz
vtxSettingsConfigMutable()->band = 0;
vtxSettingsConfigMutable()->freq = newFrequency;
}
} else { //value is frequency in MHz
uint16_t currentFreq;
vtxCommonGetFrequency(&currentFreq);
if (currentFreq != tmp) {
vtxCommonSetFrequency(tmp);
if (sbufBytesRemaining(src) > 1) {
vtxSettingsConfigMutable()->power = sbufReadU8(src);
// Delegate pitmode to vtx directly
const uint8_t newPitmode = sbufReadU8(src);
uint8_t currentPitmode = 0;
vtxCommonGetPitMode(&currentPitmode);
if (currentPitmode != newPitmode) {
vtxCommonSetPitMode(newPitmode);
}
}
}
if (sbufBytesRemaining(src) < 2) {
break;
}
uint8_t power = sbufReadU8(src);
uint8_t current_power = 0;
vtxCommonGetPowerIndex(&current_power);
if (current_power != power) {
vtxCommonSetPowerByIndex(power);
}
uint8_t pitmode = sbufReadU8(src);
uint8_t current_pitmode = 0;
vtxCommonGetPitMode(&current_pitmode);
if (current_pitmode != pitmode) {
vtxCommonSetPitMode(pitmode);
}
}
}
break;

View File

@ -63,6 +63,7 @@
#include "io/transponder_ir.h"
#include "io/vtx_tramp.h" // Will be gone
#include "io/rcdevice_cam.h"
#include "io/vtx.h"
#include "msp/msp_serial.h"
@ -209,13 +210,13 @@ static void taskTelemetry(timeUs_t currentTimeUs)
#ifdef VTX_CONTROL
// Everything that listens to VTX devices
void taskVtxControl(uint32_t currentTime)
void taskVtxControl(timeUs_t currentTime)
{
if (ARMING_FLAG(ARMED))
if (ARMING_FLAG(ARMED) || cliMode)
return;
#ifdef VTX_COMMON
vtxCommonProcess(currentTime);
vtxProcess(currentTime);
#endif
}
#endif

View File

@ -41,6 +41,7 @@
#include "drivers/light_led.h"
#include "drivers/camera_control.h"
#include "drivers/max7456.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
#include "fc/controlrate_profile.h"
@ -65,7 +66,6 @@
#include "io/osd.h"
#include "io/vtx_control.h"
#include "io/vtx_rtc6705.h"
#include "io/vtx_settings_config.h"
#include "rx/rx.h"
#include "rx/spektrum.h"
@ -756,7 +756,7 @@ const clivalue_t valueTable[] = {
{ "pwr_on_arm_grace", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, powerOnArmingGraceTime) },
// PG_VTX_CONFIG
#ifdef VTX_SETTINGS_CONFIG
#ifdef VTX_COMMON
{ "vtx_band", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, VTX_SETTINGS_MAX_BAND }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, band) },
{ "vtx_channel", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VTX_SETTINGS_MIN_CHANNEL, VTX_SETTINGS_MAX_CHANNEL }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, channel) },
{ "vtx_power", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VTX_SETTINGS_MIN_POWER, VTX_SETTINGS_POWER_COUNT }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, power) },

110
src/main/io/vtx.c Normal file
View File

@ -0,0 +1,110 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/time.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
#include "io/vtx.h"
#include "io/vtx_string.h"
#if defined(VTX_COMMON)
PG_REGISTER_WITH_RESET_TEMPLATE(vtxSettingsConfig_t, vtxSettingsConfig, PG_VTX_SETTINGS_CONFIG, 0);
PG_RESET_TEMPLATE(vtxSettingsConfig_t, vtxSettingsConfig,
.band = VTX_SETTINGS_DEFAULT_BAND,
.channel = VTX_SETTINGS_DEFAULT_CHANNEL,
.power = VTX_SETTINGS_DEFAULT_POWER,
.freq = VTX_SETTINGS_DEFAULT_FREQ
);
#define VTX_PARAM_CYCLE_TIME_US 100000 // 10Hz
typedef enum {
VTX_PARAM_BANDCHAN = 0,
VTX_PARAM_POWER,
VTX_PARAM_COUNT
} vtxScheduleParams_e;
static uint8_t vtxParamScheduleCount;
static uint8_t vtxParamSchedule[VTX_PARAM_COUNT];
void vtxInit(void)
{
uint8_t index = 0;
vtxParamSchedule[index++] = VTX_PARAM_BANDCHAN;
vtxParamSchedule[index++] = VTX_PARAM_POWER;
vtxParamScheduleCount = index;
// sync frequency in parameter group when band/channel are specified
const uint16_t freq = vtx58_Bandchan2Freq(vtxSettingsConfig()->band, vtxSettingsConfig()->channel);
if (vtxSettingsConfig()->band && freq != vtxSettingsConfig()->freq) {
vtxSettingsConfigMutable()->freq = freq;
saveConfigAndNotify();
}
}
void vtxProcess(timeUs_t currentTimeUs)
{
static timeUs_t lastCycleTimeUs;
static uint8_t scheduleIndex;
if (vtxCommonDeviceRegistered()) {
uint8_t currentSchedule = vtxParamSchedule[scheduleIndex];
// Process VTX changes from the parameter group at 10Hz
if (currentTimeUs > lastCycleTimeUs + VTX_PARAM_CYCLE_TIME_US) {
switch (currentSchedule)
{
case VTX_PARAM_BANDCHAN:
if (vtxSettingsConfig()->band) {
uint8_t vtxBand;
uint8_t vtxChan;
if (vtxCommonGetBandAndChannel(&vtxBand, &vtxChan)) {
if (vtxSettingsConfig()->band != vtxBand || vtxSettingsConfig()->channel != vtxChan) {
vtxCommonSetBandAndChannel(vtxSettingsConfig()->band, vtxSettingsConfig()->channel);
}
}
#if defined(VTX_SETTINGS_FREQCMD)
} else {
uint16_t vtxFreq;
if (vtxCommonGetFrequency(&vtxFreq)) {
if (vtxSettingsConfig()->freq != vtxFreq) {
vtxCommonSetFrequency(vtxSettingsConfig()->freq);
}
}
#endif
}
break;
case VTX_PARAM_POWER: ;
uint8_t vtxPower;
if (vtxCommonGetPowerIndex(&vtxPower)) {
if (vtxSettingsConfig()->power != vtxPower) {
vtxCommonSetPowerByIndex(vtxSettingsConfig()->power);
}
}
break;
default:
break;
}
lastCycleTimeUs = currentTimeUs;
scheduleIndex = (scheduleIndex + 1) % vtxParamScheduleCount;
}
vtxCommonProcess(currentTimeUs);
}
}
#endif

35
src/main/io/vtx.h Normal file
View File

@ -0,0 +1,35 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "drivers/vtx_common.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
typedef struct vtxSettingsConfig_s {
uint8_t band; // 1=A, 2=B, 3=E, 4=F(Airwaves/Fatshark), 5=Raceband
uint8_t channel; // 1-8
uint8_t power; // 0 = lowest
uint16_t freq; // sets freq in MHz if band=0
} vtxSettingsConfig_t;
PG_DECLARE(vtxSettingsConfig_t, vtxSettingsConfig);
void vtxInit(void);
void vtxProcess(uint32_t currentTimeUs);

View File

@ -40,6 +40,7 @@
#include "io/beeper.h"
#include "io/osd.h"
#include "io/vtx_control.h"
#include "io/vtx.h"
@ -63,10 +64,9 @@ static void vtxUpdateBandAndChannel(uint8_t bandStep, uint8_t channelStep)
locked = 1;
}
if (!locked) {
uint8_t band = 0, channel = 0;
vtxCommonGetBandAndChannel(&band, &channel);
vtxCommonSetBandAndChannel(band + bandStep, channel + channelStep);
if (!locked && vtxCommonDeviceRegistered()) {
vtxSettingsConfigMutable()->band += bandStep;
vtxSettingsConfigMutable()->channel += channelStep;
}
}
@ -96,7 +96,7 @@ void vtxUpdateActivatedChannel(void)
locked = 1;
}
if (!locked) {
if (!locked && vtxCommonDeviceRegistered()) {
static uint8_t lastIndex = -1;
for (uint8_t index = 0; index < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT; index++) {
@ -106,7 +106,8 @@ void vtxUpdateActivatedChannel(void)
&& index != lastIndex) {
lastIndex = index;
vtxCommonSetBandAndChannel(vtxChannelActivationCondition->band, vtxChannelActivationCondition->channel);
vtxSettingsConfigMutable()->band = vtxChannelActivationCondition->band;
vtxSettingsConfigMutable()->channel = vtxChannelActivationCondition->channel;
break;
}
}
@ -115,49 +116,54 @@ void vtxUpdateActivatedChannel(void)
void vtxCycleBandOrChannel(const uint8_t bandStep, const uint8_t channelStep)
{
uint8_t band = 0, channel = 0;
vtxDeviceCapability_t capability;
if (vtxCommonDeviceRegistered()) {
uint8_t band = 0, channel = 0;
vtxDeviceCapability_t capability;
bool haveAllNeededInfo = vtxCommonGetBandAndChannel(&band, &channel) && vtxCommonGetDeviceCapability(&capability);
if (!haveAllNeededInfo) {
return;
bool haveAllNeededInfo = vtxCommonGetBandAndChannel(&band, &channel) && vtxCommonGetDeviceCapability(&capability);
if (!haveAllNeededInfo) {
return;
}
int newChannel = channel + channelStep;
if (newChannel > capability.channelCount) {
newChannel = 1;
} else if (newChannel < 1) {
newChannel = capability.channelCount;
}
int newBand = band + bandStep;
if (newBand > capability.bandCount) {
newBand = 1;
} else if (newBand < 1) {
newBand = capability.bandCount;
}
vtxSettingsConfigMutable()->band = newBand;
vtxSettingsConfigMutable()->channel = newChannel;
}
int newChannel = channel + channelStep;
if (newChannel > capability.channelCount) {
newChannel = 1;
} else if (newChannel < 1) {
newChannel = capability.channelCount;
}
int newBand = band + bandStep;
if (newBand > capability.bandCount) {
newBand = 1;
} else if (newBand < 1) {
newBand = capability.bandCount;
}
vtxCommonSetBandAndChannel(newBand, newChannel);
}
void vtxCyclePower(const uint8_t powerStep)
{
uint8_t power = 0;
vtxDeviceCapability_t capability;
if (vtxCommonDeviceRegistered()) {
uint8_t power = 0;
vtxDeviceCapability_t capability;
bool haveAllNeededInfo = vtxCommonGetPowerIndex(&power) && vtxCommonGetDeviceCapability(&capability);
if (!haveAllNeededInfo) {
return;
bool haveAllNeededInfo = vtxCommonGetPowerIndex(&power) && vtxCommonGetDeviceCapability(&capability);
if (!haveAllNeededInfo) {
return;
}
int newPower = power + powerStep;
if (newPower >= capability.powerCount) {
newPower = 0;
} else if (newPower < 0) {
newPower = capability.powerCount;
}
vtxSettingsConfigMutable()->power = newPower;
}
int newPower = power + powerStep;
if (newPower >= capability.powerCount) {
newPower = 0;
} else if (newPower < 0) {
newPower = capability.powerCount;
}
vtxCommonSetPowerByIndex(newPower);
}
/**

View File

@ -38,14 +38,14 @@
#include "drivers/system.h"
#include "drivers/time.h"
#include "drivers/vtx_common.h"
#include "drivers/vtx_rtc6705.h"
#include "drivers/vtx_common.h"
#include "fc/rc_controls.h"
#include "fc/runtime_config.h"
#include "io/vtx.h"
#include "io/vtx_rtc6705.h"
#include "io/vtx_settings_config.h"
#include "io/vtx_string.h"
bool canUpdateVTX(void);
@ -97,28 +97,9 @@ static void vtxRTC6705EnableAndConfigure(void)
}
#endif
void vtxRTC6705Process(uint32_t now)
void vtxRTC6705Process(timeUs_t now)
{
UNUSED(now);
static bool configured = false;
if (!configured) {
vtxRTC6705.band = vtxSettingsConfig()->band;
vtxRTC6705.channel = vtxSettingsConfig()->channel;
vtxRTC6705.powerIndex = MAX(vtxSettingsConfig()->power, VTX_RTC6705_MIN_POWER);
#ifdef RTC6705_POWER_PIN
if (vtxRTC6705.powerIndex > 0) {
vtxRTC6705EnableAndConfigure();
} else {
rtc6705Disable();
}
#else
vtxRTC6705Configure();
#endif
configured = true;
}
}
#ifdef VTX_COMMON
@ -145,8 +126,6 @@ void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel)
vtxRTC6705.band = band;
vtxRTC6705.channel = channel;
vtxSettingsSaveBandAndChannel(band, channel);
}
}
@ -154,8 +133,6 @@ void vtxRTC6705SetPowerByIndex(uint8_t index)
{
WAIT_FOR_VTX;
vtxSettingsSavePowerByIndex(index);
#ifdef RTC6705_POWER_PIN
if (index == 0) {
// power device off

View File

@ -1,153 +0,0 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include "platform.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "fc/config.h"
#include "io/vtx_settings_config.h"
#include "io/vtx_string.h"
#ifdef VTX_SETTINGS_CONFIG
PG_REGISTER_WITH_RESET_TEMPLATE(vtxSettingsConfig_t, vtxSettingsConfig, PG_VTX_SETTINGS_CONFIG, 0);
PG_RESET_TEMPLATE(vtxSettingsConfig_t, vtxSettingsConfig,
.band = VTX_SETTINGS_DEFAULT_BAND,
.channel = VTX_SETTINGS_DEFAULT_CHANNEL,
.power = VTX_SETTINGS_DEFAULT_POWER,
.freq = 0
);
static bool vtxChangePending = false;
static void vtxChangeSetting(bool changed)
{
if (changed && !vtxChangePending) {
vtxChangePending = true;
}
}
static bool vtxSetBand(uint8_t band)
{
if (band != vtxSettingsConfig()->band) {
vtxSettingsConfigMutable()->band = band;
return true;
}
return false;
}
static bool vtxSetChannel(uint8_t channel)
{
if (channel != vtxSettingsConfig()->channel) {
vtxSettingsConfigMutable()->channel = channel;
return true;
}
return false;
}
static bool vtxSetFreq(uint16_t freq)
{
if (freq && freq != vtxSettingsConfig()->freq) {
uint8_t band;
uint8_t channel;
if (vtx58_Freq2Bandchan(freq, &band, &channel)) {
vtxChangeSetting(vtxSetBand(band));
vtxChangeSetting(vtxSetChannel(channel));
} else {
vtxChangeSetting(vtxSetBand(0));
}
vtxSettingsConfigMutable()->freq = freq;
return true;
}
return false;
}
static bool vtxSetPower(uint8_t powerIndex)
{
if (powerIndex != vtxSettingsConfig()->power) {
vtxSettingsConfigMutable()->power = powerIndex;
return true;
}
return false;
}
static void vtxCommitChanges(void)
{
if (vtxChangePending) {
saveConfigAndNotify();
}
vtxChangePending = false;
}
//Saves the given band/channel values to configuration settings.
// band: Band value (1 to 5).
// channel: Channel value (1 to 8).
void vtxSettingsSaveBandAndChannel(uint8_t band, uint8_t channel)
{
vtxChangeSetting(vtxSetBand(band));
vtxChangeSetting(vtxSetChannel(channel));
if (band) {
vtxChangeSetting(vtxSetFreq(vtx58_Bandchan2Freq(band, channel)));
}
vtxCommitChanges();
}
//Saves the given power-index value to the configuration setting.
// index: Power-index value.
void vtxSettingsSavePowerByIndex(uint8_t index)
{
vtxChangeSetting(vtxSetPower(index));
vtxCommitChanges();
}
//Saves the given band/channel/power values to configuration settings.
// band: Band value (1 to 5).
// channel: Channel value (1 to 8).
// index: Power-index value.
void vtxSettingsSaveBandChanAndPower(uint8_t band, uint8_t channel, uint8_t index)
{
vtxChangeSetting(vtxSetBand(band));
vtxChangeSetting(vtxSetChannel(channel));
vtxChangeSetting(vtxSetPower(index));
if (band) {
vtxChangeSetting(vtxSetFreq(vtx58_Bandchan2Freq(band, channel)));
}
vtxCommitChanges();
}
//Saves the given frequency value to the configuration setting.
// freq: Frequency value in MHz.
void vtxSettingsSaveFrequency(uint16_t freq)
{
vtxChangeSetting(vtxSetFreq(freq));
vtxCommitChanges();
}
//Saves the given frequency/power values to configuration settings.
// freq: Frequency value in MHz.
// index: Power-index value.
void vtxSettingsSaveFreqAndPower(uint16_t freq, uint8_t index)
{
vtxChangeSetting(vtxSetFreq(freq));
vtxChangeSetting(vtxSetPower(index));
vtxCommitChanges();
}
#endif //VTX_SETTINGS_CONFIG

View File

@ -1,73 +0,0 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define VTX_SETTINGS_MIN_BAND 1
#define VTX_SETTINGS_MAX_BAND 5
#define VTX_SETTINGS_MIN_CHANNEL 1
#define VTX_SETTINGS_MAX_CHANNEL 8
#define VTX_SETTINGS_BAND_COUNT (VTX_SETTINGS_MAX_BAND - VTX_SETTINGS_MIN_BAND + 1)
#define VTX_SETTINGS_CHANNEL_COUNT (VTX_SETTINGS_MAX_CHANNEL - VTX_SETTINGS_MIN_CHANNEL + 1)
#define VTX_SETTINGS_DEFAULT_BAND 4 //Fatshark/Airwaves
#define VTX_SETTINGS_DEFAULT_CHANNEL 1 //CH1
#define VTX_SETTINGS_MAX_FREQUENCY_MHZ 5999 //max freq (in MHz) for 'vtx_freq' setting
#if defined(VTX_SMARTAUDIO) || defined(VTX_TRAMP)
#define VTX_SETTINGS_POWER_COUNT 5
#define VTX_SETTINGS_DEFAULT_POWER 1
#define VTX_SETTINGS_MIN_POWER 0
#define VTX_SETTINGS_CONFIG
#define VTX_SETTINGS_FREQCMD
#elif defined(VTX_RTC6705)
#include "io/vtx_rtc6705.h"
#define VTX_SETTINGS_POWER_COUNT VTX_RTC6705_POWER_COUNT
#define VTX_SETTINGS_DEFAULT_POWER VTX_RTC6705_DEFAULT_POWER
#define VTX_SETTINGS_MIN_POWER VTX_RTC6705_MIN_POWER
#define VTX_SETTINGS_CONFIG
#endif
#ifdef VTX_SETTINGS_CONFIG
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
typedef struct vtxSettingsConfig_s {
uint8_t band; // 1=A, 2=B, 3=E, 4=F(Airwaves/Fatshark), 5=Raceband
uint8_t channel; // 1-8
uint8_t power; // 0 = lowest
uint16_t freq; // sets freq in MHz if band=0
} vtxSettingsConfig_t;
PG_DECLARE(vtxSettingsConfig_t, vtxSettingsConfig);
void vtxSettingsSaveBandAndChannel(uint8_t band, uint8_t channel);
void vtxSettingsSavePowerByIndex(uint8_t index);
void vtxSettingsSaveBandChanAndPower(uint8_t band, uint8_t channel, uint8_t index);
void vtxSettingsSaveFrequency(uint16_t freq);
void vtxSettingsSaveFreqAndPower(uint16_t freq, uint8_t index);
#endif //VTX_SETTINGS_CONFIG

View File

@ -51,8 +51,8 @@
#include "io/serial.h"
#include "io/vtx_control.h"
#include "io/vtx.h"
#include "io/vtx_smartaudio.h"
#include "io/vtx_settings_config.h"
#include "io/vtx_string.h"
//#define SMARTAUDIO_DPRINTF
@ -262,7 +262,7 @@ static void saAutobaud(void)
// Transport level variables
static uint32_t sa_lastTransmission = 0;
static timeUs_t sa_lastTransmission = 0;
static uint8_t sa_outstanding = SA_CMD_NONE; // Outstanding command
static uint8_t sa_osbuf[32]; // Outstanding comamnd frame for retransmission
static int sa_oslen; // And associate length
@ -594,7 +594,6 @@ static void saDevSetFreq(uint16_t freq)
void saSetFreq(uint16_t freq)
{
saDevSetFreq(freq);
vtxSettingsSaveFrequency(freq);
}
void saSetPitFreq(uint16_t freq)
@ -628,7 +627,6 @@ static void saDevSetBandAndChannel(uint8_t band, uint8_t channel)
void saSetBandAndChannel(uint8_t band, uint8_t channel)
{
saDevSetBandAndChannel(band, channel);
vtxSettingsSaveBandAndChannel(band + 1, channel + 1);
}
void saSetMode(int mode)
@ -664,38 +662,6 @@ static void saDevSetPowerByIndex(uint8_t index)
void saSetPowerByIndex(uint8_t index)
{
saDevSetPowerByIndex(index);
vtxSettingsSavePowerByIndex(index + 1);
}
static bool saEnterInitBandChanAndPower(uint8_t band, uint8_t channel, uint8_t power)
{
if (!saValidateBandAndChannel(band, channel)) {
return false;
}
saDevSetBandAndChannel(band - 1, channel - 1);
uint8_t pwrIdx = constrain(power - 1, 0, VTX_SMARTAUDIO_POWER_COUNT - 1);
saDevSetPowerByIndex(pwrIdx);
// update 'vtx_freq' via band/channel table and enter
// power-index value (in case current value is out of range)
vtxSettingsSaveFreqAndPower(vtx58_Bandchan2Freq(band, channel), pwrIdx + 1);
return true;
}
static void saEnterInitFreqAndPower(uint16_t freq, uint8_t power)
{
if (saValidateFreq(freq)) {
saSetMode(0); //need to be in FREE mode to set freq
saDevSetFreq(freq);
}
uint8_t pwrIdx = constrain(power - 1, 0, VTX_SMARTAUDIO_POWER_COUNT - 1);
saDevSetPowerByIndex(pwrIdx);
// enter power-index value (in case current value is out of range)
vtxSettingsSavePowerByIndex(pwrIdx + 1);
}
bool vtxSmartAudioInit(void)
@ -731,7 +697,7 @@ bool vtxSmartAudioInit(void)
return true;
}
void vtxSAProcess(uint32_t now)
void vtxSAProcess(timeUs_t now)
{
static char initPhase = 0;
static bool initSettingsDoneFlag = false;
@ -784,14 +750,6 @@ void vtxSAProcess(uint32_t now)
if (!initSettingsDoneFlag) {
if (saDevice.version != 0) {
initSettingsDoneFlag = true;
// if vtx_band!=0 then enter 'vtx_band/chan' values (and power)
if (!saEnterInitBandChanAndPower(vtxSettingsConfig()->band,
vtxSettingsConfig()->channel, vtxSettingsConfig()->power)) {
// if vtx_band==0 then enter 'vtx_freq' value (and power)
if (vtxSettingsConfig()->band == 0) {
saEnterInitFreqAndPower(vtxSettingsConfig()->freq, vtxSettingsConfig()->power);
}
}
} else if (now - sa_lastTransmission >= 100) {
// device is not ready; repeat query
saGetSettings();

View File

@ -37,8 +37,8 @@
#include "io/serial.h"
#include "io/vtx_tramp.h"
#include "io/vtx_settings_config.h"
#include "io/vtx_control.h"
#include "io/vtx.h"
#include "io/vtx_string.h"
#if defined(USE_CMS) || defined(VTX_COMMON)
@ -149,7 +149,6 @@ void trampSetFreq(uint16_t freq)
{
trampSetByFreqFlag = true; //set freq via MHz value
trampDevSetFreq(freq);
vtxSettingsSaveFrequency(freq);
}
void trampSendFreq(uint16_t freq)
@ -367,41 +366,9 @@ void trampQueryS(void)
trampQuery('s');
}
static bool trampEnterInitBandChanAndPower(uint8_t band, uint8_t channel, uint8_t power)
void vtxTrampProcess(timeUs_t currentTimeUs)
{
if (!trampValidateBandAndChannel(band, channel)) {
return false;
}
trampSetByFreqFlag = false; //set freq via band/channel
trampDevSetBandAndChannel(band, channel);
uint8_t pwrIdx = constrain(power, 1, sizeof(trampPowerTable));
trampDevSetPowerByIndex(pwrIdx);
// update 'vtx_freq' via band/channel table and enter
// power-index value (in case current value is out of range)
vtxSettingsSaveFreqAndPower(vtx58_Bandchan2Freq(band, channel), pwrIdx);
return true;
}
static void trampEnterInitFreqAndPower(uint16_t freq, uint8_t power)
{
if (trampValidateFreq(freq)) {
trampSetByFreqFlag = true; //set freq via MHz value
trampDevSetFreq(freq);
}
uint8_t pwrIdx = constrain(power, 1, sizeof(trampPowerTable));
trampDevSetPowerByIndex(pwrIdx);
// enter power-index value (in case current value is out of range)
vtxSettingsSavePowerByIndex(pwrIdx);
}
void vtxTrampProcess(uint32_t currentTimeUs)
{
static uint32_t lastQueryTimeUs = 0;
static timeUs_t lastQueryTimeUs = 0;
static bool initSettingsDoneFlag = false;
#ifdef TRAMP_DEBUG
@ -428,13 +395,6 @@ void vtxTrampProcess(uint32_t currentTimeUs)
if (!initSettingsDoneFlag) {
initSettingsDoneFlag = true;
// if vtx_band!=0 then enter 'vtx_band/chan' values (and power)
if (!trampEnterInitBandChanAndPower(vtxSettingsConfig()->band, vtxSettingsConfig()->channel,
vtxSettingsConfig()->power)) {
// if vtx_band=0 then enter 'vtx_freq' value (and power)
if (vtxSettingsConfig()->band == 0) {
trampEnterInitFreqAndPower(vtxSettingsConfig()->freq, vtxSettingsConfig()->power);
}
}
}
}
break;
@ -544,15 +504,12 @@ void vtxTrampSetBandAndChannel(uint8_t band, uint8_t channel)
if (trampValidateBandAndChannel(band, channel)) {
trampSetBandAndChannel(band, channel);
trampCommitChanges();
vtxSettingsSaveBandAndChannel(band, channel);
}
}
void vtxTrampSetPowerByIndex(uint8_t index)
{
if (trampDevSetPowerByIndex(index)) {
vtxSettingsSavePowerByIndex(index);
}
trampDevSetPowerByIndex(index);
}
void vtxTrampSetPitMode(uint8_t onoff)

View File

@ -34,6 +34,7 @@
#include "drivers/vtx_common.h"
#include "io/serial.h"
#include "io/vtx_string.h"
#include "fc/config.h"
#include "fc/fc_dispatch.h"
@ -258,40 +259,60 @@ const uint8_t vtxTrampPi[] = { // Spektrum Spec Tx menu Tx sends
vtx.band = (vtxControl & SPEKTRUM_VTX_BAND_MASK) >> SPEKTRUM_VTX_BAND_SHIFT;
vtx.channel = (vtxControl & SPEKTRUM_VTX_CHANNEL_MASK) >> SPEKTRUM_VTX_CHANNEL_SHIFT;
const vtxSettingsConfig_t prevSettings = {
.band = vtxSettingsConfig()->band,
.channel = vtxSettingsConfig()->channel,
.freq = vtxSettingsConfig()->freq,
.power = vtxSettingsConfig()->power,
};
vtxSettingsConfig_t newSettings = prevSettings;
#ifdef USE_VTX_COMMON_FREQ_API
uint16_t freq = SpektrumVtxfrequencyTable[vtx.band][vtx.channel];
uint16_t currentFreq = 0;
vtxCommonGetFrequency(&currentFreq);
if (currentFreq != freq) {
vtxCommonSetBandAndChannel(VTX_COMMON_BAND_USER, vtx.channel);
vtxCommonSetFrequency(freq);
if (vtxCommonDeviceRegistered()) {
if (prevSettings.freq != freq) {
newSettings.band = VTX_COMMON_BAND_USER;
newSettings.channel = vtx.channel;
newSettings.freq = freq;
}
}
#else
// Convert to the internal Common Band index
uint8_t band = spek2commonBand[vtx.band];
uint8_t channel = vtx.channel +1; // 0 based to 1 based
uint8_t currentBand = 0, currentChannel = 0;
vtxCommonGetBandAndChannel(&currentBand, &currentChannel);
if ((currentBand != band) || (currentChannel != channel)) {
vtxCommonSetBandAndChannel(band, channel);
if (vtxCommonDeviceRegistered()) {
if ((prevSettings.band != band) || (prevSettings.channel != channel)) {
newSettings.band = band;
newSettings.channel = channel;
newSettings.freq = vtx58_Bandchan2Freq(band, channel);
}
}
#endif
// Seems to be no unified internal VTX API std for popwer levels/indexes, VTX device brand specific.
uint8_t power = convertSpektrumVtxPowerIndex(vtx.power);
uint8_t currentPower = 0;
vtxCommonGetPowerIndex(&currentPower);
if (currentPower != power) {
vtxCommonSetPowerByIndex(power);
if (vtxCommonDeviceRegistered()) {
if (prevSettings.power != power) {
newSettings.power = power;
}
}
// Everyone seems to agree on what PIT ON/OFF means
uint8_t currentPitMode = 0;
vtxCommonGetPitMode(&currentPitMode);
if (currentPitMode != vtx.pitMode) {
vtxCommonSetPitMode(vtx.pitMode);
if (vtxCommonDeviceRegistered()) {
vtxCommonGetPitMode(&currentPitMode);
if (currentPitMode != vtx.pitMode) {
vtxCommonSetPitMode(vtx.pitMode);
}
}
if(memcmp(&prevSettings,&newSettings,sizeof(vtxSettingsConfig_t))) {
vtxSettingsConfigMutable()->band = newSettings.band;
vtxSettingsConfigMutable()->channel = newSettings.channel;
vtxSettingsConfigMutable()->power = newSettings.power;
vtxSettingsConfigMutable()->freq = newSettings.freq;
saveConfigAndNotify();
}
}

View File

@ -185,7 +185,6 @@
#define LSM303DLHC_I2C_INT1_PIN PE4
#define LSM303DLHC_I2C_INT2_PIN PE5
#define USE_ADC
#define ADC_INSTANCE ADC1
#define VBAT_ADC_PIN PC0

View File

@ -34,6 +34,8 @@ extern "C" {
#include "config/parameter_group_ids.h"
#include "sensors/battery.h"
#include "drivers/buf_writer.h"
#include "drivers/vtx_common.h"
#include "io/vtx.h"
#include "flight/mixer.h"
#include "flight/servos.h"
#include "flight/pid.h"