mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +03:00
Poll state change after command several times, not continuous
This commit is contained in:
parent
a03b586eb8
commit
ed68e57d48
1 changed files with 88 additions and 98 deletions
|
@ -55,6 +55,12 @@
|
|||
#include "io/vtx_smartaudio.h"
|
||||
#include "io/vtx_string.h"
|
||||
|
||||
// Timing parameters
|
||||
// Note that vtxSAProcess() is normally called at 200ms interval
|
||||
#define SMARTAUDIO_CMD_TIMEOUT 120 // Time until the command is considered lost
|
||||
#define SMARTAUDIO_POLLING_INTERVAL 150 // Minimum time between state polling
|
||||
#define SMARTAUDIO_POLLING_WINDOW 1000 // Time window after command polling for state change
|
||||
|
||||
//#define SMARTAUDIO_DPRINTF
|
||||
//#define SMARTAUDIO_DEBUG_MONITOR
|
||||
|
||||
|
@ -219,8 +225,6 @@ uint16_t sa_smartbaud = SMARTBAUD_MIN;
|
|||
static int sa_adjdir = 1; // -1=going down, 1=going up
|
||||
static int sa_baudstep = 50;
|
||||
|
||||
#define SMARTAUDIO_CMD_TIMEOUT 120
|
||||
|
||||
static void saAutobaud(void)
|
||||
{
|
||||
if (saStat.pktsent < 10) {
|
||||
|
@ -262,7 +266,7 @@ static void saAutobaud(void)
|
|||
|
||||
// Transport level variables
|
||||
|
||||
static timeUs_t sa_lastTransmission = 0;
|
||||
static timeUs_t sa_lastTransmissionMs = 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
|
||||
|
@ -448,7 +452,7 @@ static void saSendFrame(uint8_t *buf, int len)
|
|||
|
||||
serialWrite(smartAudioSerialPort, 0x00); // XXX Probably don't need this
|
||||
|
||||
sa_lastTransmission = millis();
|
||||
sa_lastTransmissionMs = millis();
|
||||
saStat.pktsent++;
|
||||
}
|
||||
|
||||
|
@ -702,8 +706,10 @@ bool vtxSmartAudioInit(void)
|
|||
#define SA_INITPHASE_WAIT_PITFREQ 2 // SA_FREQ_GETPIT sent and waiting for reply.
|
||||
#define SA_INITPHASE_DONE 3
|
||||
|
||||
void vtxSAProcess(timeUs_t now)
|
||||
void vtxSAProcess(timeUs_t currentTimeUs)
|
||||
{
|
||||
UNUSED(currentTimeUs);
|
||||
|
||||
static char initPhase = SA_INITPHASE_START;
|
||||
|
||||
if (smartAudioSerialPort == NULL) {
|
||||
|
@ -750,41 +756,25 @@ void vtxSAProcess(timeUs_t now)
|
|||
|
||||
// Command queue control
|
||||
|
||||
if ((sa_outstanding != SA_CMD_NONE) && (now - sa_lastTransmission > SMARTAUDIO_CMD_TIMEOUT)) {
|
||||
timeMs_t nowMs = millis(); // Don't substitute with "currentTimeUs / 1000"; sa_lastTransmissionMs is based on millis().
|
||||
static timeMs_t lastCommandSentMs = 0; // Last non-GET_SETTINGS sent
|
||||
|
||||
if ((sa_outstanding != SA_CMD_NONE) && (nowMs - sa_lastTransmissionMs > SMARTAUDIO_CMD_TIMEOUT)) {
|
||||
// Last command timed out
|
||||
// dprintf(("process: resending 0x%x\r\n", sa_outstanding));
|
||||
// XXX Todo: Resend termination and possible offline transition
|
||||
saResendCmd();
|
||||
lastCommandSentMs = nowMs;
|
||||
} else if (!saQueueEmpty()) {
|
||||
// Command pending. Send it.
|
||||
// dprintf(("process: sending queue\r\n"));
|
||||
saSendQueue();
|
||||
} else if (saDevice.version != 0 && now - sa_lastTransmission >= 1000) {
|
||||
// Heart beat for autobauding
|
||||
//dprintf(("process: sending heartbeat\r\n"));
|
||||
lastCommandSentMs = nowMs;
|
||||
} else if ((nowMs - lastCommandSentMs < SMARTAUDIO_POLLING_WINDOW) && (nowMs - sa_lastTransmissionMs >= SMARTAUDIO_POLLING_INTERVAL)) {
|
||||
//dprintf(("process: sending status change polling\r\n"));
|
||||
saGetSettings();
|
||||
saSendQueue();
|
||||
}
|
||||
|
||||
#ifdef SMARTAUDIO_TEST_VTX_COMMON
|
||||
// Testing VTX_COMMON API
|
||||
{
|
||||
static uint32_t lastMonitorUs = 0;
|
||||
if (cmp32(now, lastMonitorUs) < 5 * 1000 * 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
static uint8_t monBand;
|
||||
static uint8_t monChan;
|
||||
static uint8_t monPower;
|
||||
|
||||
vtxCommonGetBandAndChannel(&monBand, &monChan);
|
||||
vtxCommonGetPowerIndex(&monPower);
|
||||
debug[0] = monBand;
|
||||
debug[1] = monChan;
|
||||
debug[2] = monPower;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VTX_COMMON
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue