mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
Update common telemetry code so that it verifies that the telemetry
configuration is valid. Internally this uses a flag so that the configuration is not continually verified.
This commit is contained in:
parent
1c0e0618e5
commit
9b86d0d833
1 changed files with 31 additions and 4 deletions
|
@ -4,6 +4,8 @@
|
||||||
#include "telemetry_frsky.h"
|
#include "telemetry_frsky.h"
|
||||||
#include "telemetry_hott.h"
|
#include "telemetry_hott.h"
|
||||||
|
|
||||||
|
static bool isTelemetryConfigurationValid = false; // flag used to avoid repeated configuration checks
|
||||||
|
|
||||||
bool isTelemetryProviderFrSky(void)
|
bool isTelemetryProviderFrSky(void)
|
||||||
{
|
{
|
||||||
return mcfg.telemetry_provider == TELEMETRY_PROVIDER_FRSKY;
|
return mcfg.telemetry_provider == TELEMETRY_PROVIDER_FRSKY;
|
||||||
|
@ -14,12 +16,37 @@ bool isTelemetryProviderHoTT(void)
|
||||||
return mcfg.telemetry_provider == TELEMETRY_PROVIDER_HOTT;
|
return mcfg.telemetry_provider == TELEMETRY_PROVIDER_HOTT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool canUseTelemetryWithCurrentConfiguration(void) {
|
||||||
|
|
||||||
|
if (!feature(FEATURE_TELEMETRY)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!feature(FEATURE_SOFTSERIAL)) {
|
||||||
|
if (mcfg.telemetry_port == TELEMETRY_PORT_SOFTSERIAL_1 || mcfg.telemetry_port == TELEMETRY_PORT_SOFTSERIAL_1) {
|
||||||
|
// softserial feature must be enabled to use telemetry on softserial ports
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTelemetryProviderHoTT()) {
|
||||||
|
if (mcfg.telemetry_port == TELEMETRY_PORT_UART) {
|
||||||
|
// HoTT requires a serial port that supports RX/TX mode swapping
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void initTelemetry(void)
|
void initTelemetry(void)
|
||||||
{
|
{
|
||||||
// Sanity check for softserial vs. telemetry port
|
// Force telemetry to uart when softserial disabled
|
||||||
if (!feature(FEATURE_SOFTSERIAL))
|
if (!feature(FEATURE_SOFTSERIAL))
|
||||||
mcfg.telemetry_port = TELEMETRY_PORT_UART;
|
mcfg.telemetry_port = TELEMETRY_PORT_UART;
|
||||||
|
|
||||||
|
isTelemetryConfigurationValid = canUseTelemetryWithCurrentConfiguration();
|
||||||
|
|
||||||
if (mcfg.telemetry_port == TELEMETRY_PORT_SOFTSERIAL_1)
|
if (mcfg.telemetry_port == TELEMETRY_PORT_SOFTSERIAL_1)
|
||||||
core.telemport = &(softSerialPorts[0].port);
|
core.telemport = &(softSerialPorts[0].port);
|
||||||
else if (mcfg.telemetry_port == TELEMETRY_PORT_SOFTSERIAL_2)
|
else if (mcfg.telemetry_port == TELEMETRY_PORT_SOFTSERIAL_2)
|
||||||
|
@ -51,7 +78,7 @@ bool shouldChangeTelemetryStateNow(bool telemetryCurrentlyEnabled)
|
||||||
return telemetryCurrentlyEnabled != telemetryEnabled;
|
return telemetryCurrentlyEnabled != telemetryEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void configureTelemetryPort(void) {
|
static void configureTelemetryPort(void) {
|
||||||
if (isTelemetryProviderFrSky()) {
|
if (isTelemetryProviderFrSky()) {
|
||||||
configureFrSkyTelemetryPort();
|
configureFrSkyTelemetryPort();
|
||||||
}
|
}
|
||||||
|
@ -73,7 +100,7 @@ void freeTelemetryPort(void) {
|
||||||
|
|
||||||
void checkTelemetryState(void)
|
void checkTelemetryState(void)
|
||||||
{
|
{
|
||||||
if (!feature(FEATURE_TELEMETRY)) {
|
if (!isTelemetryConfigurationValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +120,7 @@ void checkTelemetryState(void)
|
||||||
|
|
||||||
void handleTelemetry(void)
|
void handleTelemetry(void)
|
||||||
{
|
{
|
||||||
if (!isTelemetryEnabled())
|
if (!isTelemetryConfigurationValid || !isTelemetryEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isTelemetryProviderFrSky()) {
|
if (isTelemetryProviderFrSky()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue