mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 19:40:31 +03:00
VTX improvements from iNav.
This commit is contained in:
parent
43e6ea31da
commit
b4db764b46
8 changed files with 54 additions and 11 deletions
|
@ -279,3 +279,10 @@ Click on a variable to jump to the relevant documentation page.
|
||||||
| `magzero_x` | Magnetometer calibration X offset | -32768 | 32767 | 0 | Master | INT16 |
|
| `magzero_x` | Magnetometer calibration X offset | -32768 | 32767 | 0 | Master | INT16 |
|
||||||
| `magzero_y` | Magnetometer calibration Y offset | -32768 | 32767 | 0 | Master | INT16 |
|
| `magzero_y` | Magnetometer calibration Y offset | -32768 | 32767 | 0 | Master | INT16 |
|
||||||
| `magzero_z` | Magnetometer calibration Z offset | -32768 | 32767 | 0 | Master | INT16 |
|
| `magzero_z` | Magnetometer calibration Z offset | -32768 | 32767 | 0 | Master | INT16 |
|
||||||
|
| `vtx_band` | Configure the VTX band. Set to zero to use `vtx_freq`. Bands: 1: A, 2: B, 3: E, 4: F, 5: Race. | 0 | 5 | 4 | Master | UINT8 |
|
||||||
|
| `vtx_channel` | Channel to use within the configured `vtx_band`. Valid values are [1, 8]. | 1 | 8 | 1 | Master | UINT8 |
|
||||||
|
| `vtx_freq` | Set the VTX frequency using raw MHz. This parameter is ignored unless `vtx_band` is 0. | 0 | 5900 | 5740 | Master | UINT16 |
|
||||||
|
| `vtx_halfduplex` | Use half duplex UART to communicate with the VTX, using only a TX pin in the FC. | OFF | ON | ON | Master | UINT8 |
|
||||||
|
| `vtx_low_power_disarm` | When the craft is disarmed, set the VTX to its lowest power. `ON` will set the power to its minimum value on startup, increase it to `vtx_power` when arming and change it back to its lowest setting after disarming. `UNTIL_FIRST_ARM` will start with minimum power, but once the craft is armed it will increase to `vtx_power` and it will never decrease until the craft is power cycled. | | | OFF | Master | UINT8 |
|
||||||
|
| `vtx_pit_mode_freq` | Frequency to use (in MHz) when the VTX is in pit mode. | 0 | 5900 | 0 | Master | UINT16 |
|
||||||
|
| `vtx_power` | VTX RF power level to use. The exact number of mw depends on the VTX hardware. | 0 | 3 | 1 | Master | UINT8 |
|
||||||
|
|
|
@ -57,6 +57,15 @@ vtxDevType_e vtxCommonGetDeviceType(const vtxDevice_t *vtxDevice)
|
||||||
return vtxDevice->vTable->getDeviceType(vtxDevice);
|
return vtxDevice->vTable->getDeviceType(vtxDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool vtxCommonDeviceIsReady(const vtxDevice_t *vtxDevice)
|
||||||
|
{
|
||||||
|
if (vtxDevice && vtxDevice->vTable->isReady) {
|
||||||
|
return vtxDevice->vTable->isReady(vtxDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void vtxCommonProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
|
void vtxCommonProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
if (vtxDevice) {
|
if (vtxDevice) {
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#define VTX_SETTINGS_DEFAULT_CHANNEL 1
|
#define VTX_SETTINGS_DEFAULT_CHANNEL 1
|
||||||
#define VTX_SETTINGS_DEFAULT_FREQ 5740
|
#define VTX_SETTINGS_DEFAULT_FREQ 5740
|
||||||
#define VTX_SETTINGS_DEFAULT_PITMODE_FREQ 0
|
#define VTX_SETTINGS_DEFAULT_PITMODE_FREQ 0
|
||||||
#define VTX_SETTINGS_DEFAULT_LOW_POWER_DISARM 0
|
|
||||||
|
|
||||||
#define VTX_SETTINGS_MAX_FREQUENCY_MHZ 5999 //max freq (in MHz) for 'vtx_freq' setting
|
#define VTX_SETTINGS_MAX_FREQUENCY_MHZ 5999 //max freq (in MHz) for 'vtx_freq' setting
|
||||||
|
|
||||||
|
@ -167,6 +166,7 @@ vtxDevice_t *vtxCommonDevice(void);
|
||||||
// VTable functions
|
// VTable functions
|
||||||
void vtxCommonProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs);
|
void vtxCommonProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs);
|
||||||
vtxDevType_e vtxCommonGetDeviceType(const vtxDevice_t *vtxDevice);
|
vtxDevType_e vtxCommonGetDeviceType(const vtxDevice_t *vtxDevice);
|
||||||
|
bool vtxCommonDeviceIsReady(const vtxDevice_t *vtxDevice);
|
||||||
void vtxCommonSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel);
|
void vtxCommonSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel);
|
||||||
void vtxCommonSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t level);
|
void vtxCommonSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t level);
|
||||||
void vtxCommonSetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff);
|
void vtxCommonSetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff);
|
||||||
|
|
|
@ -1363,11 +1363,13 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
|
||||||
case MSP_VTX_CONFIG:
|
case MSP_VTX_CONFIG:
|
||||||
{
|
{
|
||||||
const vtxDevice_t *vtxDevice = vtxCommonDevice();
|
const vtxDevice_t *vtxDevice = vtxCommonDevice();
|
||||||
uint8_t pitmode=0;
|
uint8_t pitmode = 0;
|
||||||
vtxDevType_e vtxType = VTXDEV_UNKNOWN;
|
vtxDevType_e vtxType = VTXDEV_UNKNOWN;
|
||||||
|
uint8_t deviceIsReady = 0;
|
||||||
if (vtxDevice) {
|
if (vtxDevice) {
|
||||||
vtxCommonGetPitMode(vtxDevice, &pitmode);
|
vtxCommonGetPitMode(vtxDevice, &pitmode);
|
||||||
vtxType = vtxCommonGetDeviceType(vtxDevice);
|
vtxType = vtxCommonGetDeviceType(vtxDevice);
|
||||||
|
deviceIsReady = vtxCommonDeviceIsReady(vtxDevice) ? 1 : 0;
|
||||||
}
|
}
|
||||||
sbufWriteU8(dst, vtxType);
|
sbufWriteU8(dst, vtxType);
|
||||||
sbufWriteU8(dst, vtxSettingsConfig()->band);
|
sbufWriteU8(dst, vtxSettingsConfig()->band);
|
||||||
|
@ -1375,6 +1377,8 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
|
||||||
sbufWriteU8(dst, vtxSettingsConfig()->power);
|
sbufWriteU8(dst, vtxSettingsConfig()->power);
|
||||||
sbufWriteU8(dst, pitmode);
|
sbufWriteU8(dst, pitmode);
|
||||||
sbufWriteU16(dst, vtxSettingsConfig()->freq);
|
sbufWriteU16(dst, vtxSettingsConfig()->freq);
|
||||||
|
sbufWriteU8(dst, deviceIsReady);
|
||||||
|
sbufWriteU8(dst, vtxSettingsConfig()->lowPowerDisarm);
|
||||||
// future extensions here...
|
// future extensions here...
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2026,18 +2030,19 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
||||||
vtxType = vtxCommonGetDeviceType(vtxDevice);
|
vtxType = vtxCommonGetDeviceType(vtxDevice);
|
||||||
}
|
}
|
||||||
uint16_t newFrequency = sbufReadU16(src);
|
uint16_t newFrequency = sbufReadU16(src);
|
||||||
if (newFrequency <= VTXCOMMON_MSP_BANDCHAN_CHKVAL) { //value is band and channel
|
if (newFrequency <= VTXCOMMON_MSP_BANDCHAN_CHKVAL) { // Value is band and channel
|
||||||
const uint8_t newBand = (newFrequency / 8) + 1;
|
const uint8_t newBand = (newFrequency / 8) + 1;
|
||||||
const uint8_t newChannel = (newFrequency % 8) + 1;
|
const uint8_t newChannel = (newFrequency % 8) + 1;
|
||||||
vtxSettingsConfigMutable()->band = newBand;
|
vtxSettingsConfigMutable()->band = newBand;
|
||||||
vtxSettingsConfigMutable()->channel = newChannel;
|
vtxSettingsConfigMutable()->channel = newChannel;
|
||||||
vtxSettingsConfigMutable()->freq = vtx58_Bandchan2Freq(newBand, newChannel);
|
vtxSettingsConfigMutable()->freq = vtx58_Bandchan2Freq(newBand, newChannel);
|
||||||
} else { //value is frequency in MHz
|
} else if (newFrequency <= VTX_SETTINGS_MAX_FREQUENCY_MHZ) { // Value is frequency in MHz
|
||||||
vtxSettingsConfigMutable()->band = 0;
|
vtxSettingsConfigMutable()->band = 0;
|
||||||
|
vtxSettingsConfigMutable()->channel = 0;
|
||||||
vtxSettingsConfigMutable()->freq = newFrequency;
|
vtxSettingsConfigMutable()->freq = newFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sbufBytesRemaining(src) > 1) {
|
if (sbufBytesRemaining(src) >= 2) {
|
||||||
vtxSettingsConfigMutable()->power = sbufReadU8(src);
|
vtxSettingsConfigMutable()->power = sbufReadU8(src);
|
||||||
if (vtxType != VTXDEV_UNKNOWN) {
|
if (vtxType != VTXDEV_UNKNOWN) {
|
||||||
// Delegate pitmode to vtx directly
|
// Delegate pitmode to vtx directly
|
||||||
|
@ -2047,6 +2052,10 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
||||||
if (currentPitmode != newPitmode) {
|
if (currentPitmode != newPitmode) {
|
||||||
vtxCommonSetPitMode(vtxDevice, newPitmode);
|
vtxCommonSetPitMode(vtxDevice, newPitmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sbufBytesRemaining(src)) {
|
||||||
|
vtxSettingsConfigMutable()->lowPowerDisarm = sbufReadU8(src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,6 +381,12 @@ static const char * const lookupTableDynamicFilterRange[] = {
|
||||||
};
|
};
|
||||||
#endif // USE_GYRO_DATA_ANALYSE
|
#endif // USE_GYRO_DATA_ANALYSE
|
||||||
|
|
||||||
|
#ifdef USE_VTX_COMMON
|
||||||
|
static const char * const lookupTableVtxLowPowerDisarm[] = {
|
||||||
|
"OFF", "ON", "UNTIL_FIRST_ARM"
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
||||||
|
|
||||||
const lookupTableEntry_t lookupTables[] = {
|
const lookupTableEntry_t lookupTables[] = {
|
||||||
|
@ -474,7 +480,9 @@ const lookupTableEntry_t lookupTables[] = {
|
||||||
LOOKUP_TABLE_ENTRY(lookupTableDynamicFftLocation),
|
LOOKUP_TABLE_ENTRY(lookupTableDynamicFftLocation),
|
||||||
LOOKUP_TABLE_ENTRY(lookupTableDynamicFilterRange),
|
LOOKUP_TABLE_ENTRY(lookupTableDynamicFilterRange),
|
||||||
#endif // USE_GYRO_DATA_ANALYSE
|
#endif // USE_GYRO_DATA_ANALYSE
|
||||||
|
#ifdef USE_VTX_COMMON
|
||||||
|
LOOKUP_TABLE_ENTRY(lookupTableVtxLowPowerDisarm),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef LOOKUP_TABLE_ENTRY
|
#undef LOOKUP_TABLE_ENTRY
|
||||||
|
@ -1040,7 +1048,7 @@ const clivalue_t valueTable[] = {
|
||||||
{ "vtx_band", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VTX_SETTINGS_NO_BAND, VTX_SETTINGS_MAX_BAND }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, band) },
|
{ "vtx_band", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VTX_SETTINGS_NO_BAND, 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_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-1 }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, power) },
|
{ "vtx_power", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VTX_SETTINGS_MIN_POWER, VTX_SETTINGS_POWER_COUNT-1 }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, power) },
|
||||||
{ "vtx_low_power_disarm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, lowPowerDisarm) },
|
{ "vtx_low_power_disarm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_VTX_LOW_POWER_DISARM }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, lowPowerDisarm) },
|
||||||
#ifdef VTX_SETTINGS_FREQCMD
|
#ifdef VTX_SETTINGS_FREQCMD
|
||||||
{ "vtx_freq", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, VTX_SETTINGS_MAX_FREQUENCY_MHZ }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, freq) },
|
{ "vtx_freq", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, VTX_SETTINGS_MAX_FREQUENCY_MHZ }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, freq) },
|
||||||
{ "vtx_pit_mode_freq", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, VTX_SETTINGS_MAX_FREQUENCY_MHZ }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, pitModeFreq) },
|
{ "vtx_pit_mode_freq", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, VTX_SETTINGS_MAX_FREQUENCY_MHZ }, PG_VTX_SETTINGS_CONFIG, offsetof(vtxSettingsConfig_t, pitModeFreq) },
|
||||||
|
|
|
@ -116,7 +116,9 @@ typedef enum {
|
||||||
TABLE_DYNAMIC_FFT_LOCATION,
|
TABLE_DYNAMIC_FFT_LOCATION,
|
||||||
TABLE_DYNAMIC_FILTER_RANGE,
|
TABLE_DYNAMIC_FILTER_RANGE,
|
||||||
#endif // USE_GYRO_DATA_ANALYSE
|
#endif // USE_GYRO_DATA_ANALYSE
|
||||||
|
#ifdef USE_VTX_COMMON
|
||||||
|
TABLE_VTX_LOW_POWER_DISARM,
|
||||||
|
#endif
|
||||||
LOOKUP_TABLE_COUNT
|
LOOKUP_TABLE_COUNT
|
||||||
} lookupTableIndex_e;
|
} lookupTableIndex_e;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ PG_RESET_TEMPLATE(vtxSettingsConfig_t, vtxSettingsConfig,
|
||||||
.power = VTX_SETTINGS_DEFAULT_POWER,
|
.power = VTX_SETTINGS_DEFAULT_POWER,
|
||||||
.freq = VTX_SETTINGS_DEFAULT_FREQ,
|
.freq = VTX_SETTINGS_DEFAULT_FREQ,
|
||||||
.pitModeFreq = VTX_SETTINGS_DEFAULT_PITMODE_FREQ,
|
.pitModeFreq = VTX_SETTINGS_DEFAULT_PITMODE_FREQ,
|
||||||
.lowPowerDisarm = VTX_SETTINGS_DEFAULT_LOW_POWER_DISARM,
|
.lowPowerDisarm = VTX_LOW_POWER_DISARM_OFF,
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -111,7 +111,9 @@ STATIC_UNIT_TESTED vtxSettingsConfig_t vtxGetSettings(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!ARMING_FLAG(ARMED) && settings.lowPowerDisarm && !failsafeIsActive()) {
|
if (!ARMING_FLAG(ARMED) && !failsafeIsActive() &&
|
||||||
|
(settings.lowPowerDisarm == VTX_LOW_POWER_DISARM_ALWAYS ||
|
||||||
|
(settings.lowPowerDisarm == VTX_LOW_POWER_DISARM_UNTIL_FIRST_ARM && !ARMING_FLAG(WAS_EVER_ARMED)))) {
|
||||||
settings.power = VTX_SETTINGS_DEFAULT_POWER;
|
settings.power = VTX_SETTINGS_DEFAULT_POWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,19 @@
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
#include "pg/pg.h"
|
#include "pg/pg.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VTX_LOW_POWER_DISARM_OFF = 0,
|
||||||
|
VTX_LOW_POWER_DISARM_ALWAYS,
|
||||||
|
VTX_LOW_POWER_DISARM_UNTIL_FIRST_ARM, // Set low power until arming for the first time
|
||||||
|
} vtxLowerPowerDisarm_e;
|
||||||
|
|
||||||
typedef struct vtxSettingsConfig_s {
|
typedef struct vtxSettingsConfig_s {
|
||||||
uint8_t band; // 1=A, 2=B, 3=E, 4=F(Airwaves/Fatshark), 5=Raceband
|
uint8_t band; // 1=A, 2=B, 3=E, 4=F(Airwaves/Fatshark), 5=Raceband
|
||||||
uint8_t channel; // 1-8
|
uint8_t channel; // 1-8
|
||||||
uint8_t power; // 0 = lowest
|
uint8_t power; // 0 = lowest
|
||||||
uint16_t freq; // sets freq in MHz if band=0
|
uint16_t freq; // sets freq in MHz if band=0
|
||||||
uint16_t pitModeFreq; // sets out-of-range pitmode frequency
|
uint16_t pitModeFreq; // sets out-of-range pitmode frequency
|
||||||
uint8_t lowPowerDisarm; // min power while disarmed
|
uint8_t lowPowerDisarm; // min power while disarmed, from vtxLowerPowerDisarm_e
|
||||||
} vtxSettingsConfig_t;
|
} vtxSettingsConfig_t;
|
||||||
|
|
||||||
PG_DECLARE(vtxSettingsConfig_t, vtxSettingsConfig);
|
PG_DECLARE(vtxSettingsConfig_t, vtxSettingsConfig);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue