mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +03:00
Removed vtx_settings_config in favor of vtx_common. Removed implicit EEPROM writes for vtx_ changes.
Updated MSP_VTX_CONFIG Updated MSP_SET_VTX_CONFIG Updated MSP_VTX_CONFIG (again) Implemented VTX update schedule Removed unneeded initialization blocks from io/vtx implementations Prevent VTX settings from being applied in CLI. Sync Band/Chan/Freq on init Correct issues in SA CMS Moved vtxCommonInit and vtxCommonProcess to io/vtx
This commit is contained in:
parent
c497b44b83
commit
d9caabefa1
22 changed files with 419 additions and 548 deletions
110
src/main/io/vtx.c
Normal file
110
src/main/io/vtx.c
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue