From a651fcc05ecef6bff2db5d47533d02bf8c81ff6c Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Thu, 19 Apr 2018 16:24:17 +0200 Subject: [PATCH] imporved sbus input handling on TX module --- crossbow/config.h | 4 ++-- crossbow/crossbow.ino | 13 +++++++++++++ crossbow/sbus.cpp | 10 ++++++++-- crossbow/sbus.h | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crossbow/config.h b/crossbow/config.h index 9706f06..3e1a467 100644 --- a/crossbow/config.h +++ b/crossbow/config.h @@ -13,8 +13,8 @@ * DEVICE_MODE_TX * DEVICE_MODE_RX */ -// #define DEVICE_MODE_TX -#define DEVICE_MODE_RX +#define DEVICE_MODE_TX +// #define DEVICE_MODE_RX // #define FEATURE_TX_OLED // #define FORCE_TX_WITHOUT_INPUT diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index 0678e3b..4dd5840 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -327,6 +327,19 @@ void loop(void) uint32_t currentMillis = millis(); /* + * If we are not receiving SBUS frames from radio, try to restart serial + */ +#ifdef DEVICE_MODE_TX + + static uint32_t serialRestartMillis = 0; + + if (!txInput.isReceiving() && serialRestartMillis + 100 < currentMillis) { + txInput.restart(); + serialRestartMillis = currentMillis; + } +#endif + + /* * This routine handles resync of TX/RX while hoppping frequencies */ #ifdef DEVICE_MODE_RX diff --git a/crossbow/sbus.cpp b/crossbow/sbus.cpp index 881ccbc..47642ef 100644 --- a/crossbow/sbus.cpp +++ b/crossbow/sbus.cpp @@ -13,7 +13,7 @@ #define SBUS_STATE_FAILSAFE 0x08 #define SBUS_STATE_SIGNALLOSS 0x04 -#define SBUS_IS_RECEIVING_THRESHOLD 250 //If there is no SBUS input for 250ms, assume connection is broken +#define SBUS_IS_RECEIVING_THRESHOLD 125 //If there is no SBUS input for 125ms, assume connection is broken /* Precomputed mapping from 990-2010 to 173:1811 @@ -93,7 +93,13 @@ void SbusInput::loop(void) void SbusInput::start(void) { - _serial.begin(100000, SERIAL_8N2); + _serial.begin(100000, SERIAL_8N2); +} + +void SbusInput::restart(void) +{ + _serial.end(); + start(); } void SbusInput::sbusRead() { diff --git a/crossbow/sbus.h b/crossbow/sbus.h index 261b49e..9b92ecc 100644 --- a/crossbow/sbus.h +++ b/crossbow/sbus.h @@ -11,6 +11,7 @@ class SbusInput : public TxInput public: SbusInput(HardwareSerial &serial); void start(void); + void restart(void); void loop(void); bool isReceiving(void); private: