add flysky rx indicating led (#5476)
* add flysky rx indicating led add flysky rx indicating led * add Conditional compilation directives add Conditional compilation directives * rewrite some code rewrite some code and add some definitions/defines according to comments * delete extra whitespace
This commit is contained in:
parent
062ef77276
commit
b2e807be6c
|
@ -117,6 +117,9 @@ static bool waitTx = false;
|
|||
static uint16_t errorRate = 0;
|
||||
static uint16_t rssi_dBm = 0;
|
||||
static uint8_t rfChannelMap[FLYSKY_FREQUENCY_COUNT] = {0};
|
||||
#ifdef USE_RX_FLYSKY_SPI_LED
|
||||
static IO_t flySkyLedPin;
|
||||
#endif /* USE_RX_FLYSKY_SPI_LED */
|
||||
|
||||
|
||||
static uint8_t getNextChannel (uint8_t step)
|
||||
|
@ -360,6 +363,12 @@ bool flySkyInit (const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rx
|
|||
IO_t bindPin = IOGetByTag(IO_TAG(BINDPLUG_PIN));
|
||||
IOInit(bindPin, OWNER_RX_BIND, 0);
|
||||
IOConfigGPIO(bindPin, IOCFG_IPU);
|
||||
#ifdef USE_RX_FLYSKY_SPI_LED
|
||||
flySkyLedPin = IOGetByTag(IO_TAG(RX_FLYSKY_SPI_LED_PIN));
|
||||
IOInit(flySkyLedPin, OWNER_LED, 0);
|
||||
IOConfigGPIO(flySkyLedPin, IOCFG_OUT_PP);
|
||||
IOLo(flySkyLedPin);
|
||||
#endif /* USE_RX_FLYSKY_SPI_LED */
|
||||
|
||||
uint8_t startRxChannel;
|
||||
|
||||
|
@ -413,6 +422,11 @@ void flySkySetRcDataFromPayload (uint16_t *rcData, const uint8_t *payload)
|
|||
|
||||
rx_spi_received_e flySkyDataReceived (uint8_t *payload)
|
||||
{
|
||||
#ifdef USE_RX_FLYSKY_SPI_LED
|
||||
static uint16_t rxLossCount = 0;
|
||||
static timeMs_t ledLastUpdate = 0;
|
||||
static bool ledOn = false;
|
||||
#endif /* USE_RX_FLYSKY_SPI_LED */
|
||||
rx_spi_received_e result = RX_SPI_RECEIVED_NONE;
|
||||
uint32_t timeStamp;
|
||||
|
||||
|
@ -442,6 +456,27 @@ rx_spi_received_e flySkyDataReceived (uint8_t *payload)
|
|||
|
||||
if (bound) {
|
||||
checkTimeout();
|
||||
#ifdef USE_RX_FLYSKY_SPI_LED
|
||||
if (result == RX_SPI_RECEIVED_DATA) {
|
||||
rxLossCount = 0;
|
||||
IOHi(flySkyLedPin);
|
||||
} else {
|
||||
if (rxLossCount < RX_LOSS_COUNT) {
|
||||
rxLossCount++;
|
||||
} else {
|
||||
timeMs_t now = millis();
|
||||
if (now - ledLastUpdate > INTERVAL_RX_LOSS_MS) {
|
||||
ledLastUpdate = now;
|
||||
if (ledOn) {
|
||||
IOLo(flySkyLedPin);
|
||||
} else {
|
||||
IOHi(flySkyLedPin);
|
||||
}
|
||||
ledOn = !ledOn;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* USE_RX_FLYSKY_SPI_LED */
|
||||
} else {
|
||||
if ((micros() - timeLastBind) > BIND_TIMEOUT && rfChannelMap[0] != 0 && txId != 0) {
|
||||
result = RX_SPI_RECEIVED_BIND;
|
||||
|
@ -451,6 +486,18 @@ rx_spi_received_e flySkyDataReceived (uint8_t *payload)
|
|||
flySkyConfigMutable()->protocol = protocol;
|
||||
writeEEPROM();
|
||||
}
|
||||
#ifdef USE_RX_FLYSKY_SPI_LED
|
||||
timeMs_t now = millis();
|
||||
if (now - ledLastUpdate > INTERVAL_RX_BIND_MS) {
|
||||
ledLastUpdate = now;
|
||||
if (ledOn) {
|
||||
IOLo(flySkyLedPin);
|
||||
} else {
|
||||
IOHi(flySkyLedPin);
|
||||
}
|
||||
ledOn = !ledOn;
|
||||
}
|
||||
#endif /* USE_RX_FLYSKY_SPI_LED */
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
|
||||
#define TX_DELAY 500
|
||||
#define BIND_TIMEOUT 200000
|
||||
#define INTERVAL_RX_LOSS_MS 1000
|
||||
#define INTERVAL_RX_BIND_MS 250
|
||||
#define RX_LOSS_COUNT 1000
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t type;
|
||||
|
|
Loading…
Reference in New Issue