From a6b5946a68f8e3262f9d41d71ecf26e5bbb0e3d2 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Tue, 24 Oct 2017 21:08:04 +0200 Subject: [PATCH] close #12 --- crossbow.ino | 17 ++++++++++++----- variables.h | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crossbow.ino b/crossbow.ino index 9b9f205..d5a2926 100644 --- a/crossbow.ino +++ b/crossbow.ino @@ -42,6 +42,7 @@ PPMReader ppmReader(PPM_INPUT_PIN, PPM_INPUT_INTERRUPT, true); #ifdef DEVICE_MODE_RX uint32_t sbusTime = 0; uint8_t sbusPacket[SBUS_PACKET_LENGTH] = {0}; + uint32_t lastRxStateTaskTime = 0; #endif /* @@ -54,8 +55,8 @@ RxDeviceState_t rxDeviceState = {}; uint8_t getRadioRssi(void) { - //Map from -164:0 to 0:100 - return map(constrain(LoRa.packetRssi() * -1, 0, 164), 0, 164, 100, 0); + //Map from -164:0 to 0:255 + return map(constrain(LoRa.packetRssi() * -1, 0, 164), 0, 164, 255, 0); } float getRadioSnr(void) @@ -278,6 +279,15 @@ void loop(void) } /* + * This routine updates RX device state and updates one of radio channels with RSSI value + */ + if (currentMillis - lastRxStateTaskTime > RX_TASK_HEALTH) { + lastRxStateTaskTime = currentMillis; + updateRxDeviceState(&rxDeviceState); + ppm[RSSI_CHANNEL - 1] = map(rxDeviceState.rssi, 0, 255, 1000, 2000); + } + + /* * RX_HEALTH QSP frame */ if ( @@ -287,9 +297,6 @@ void loop(void) ) { qsp.lastFrameTransmitedAt[QSP_FRAME_RX_HEALTH] = currentMillis; - - updateRxDeviceState(&rxDeviceState); - qspClearPayload(&qsp); encodeRxHealthPayload(&qsp, &rxDeviceState); qsp.frameToSend = QSP_FRAME_RX_HEALTH; diff --git a/variables.h b/variables.h index 35f4ab9..43f06d6 100644 --- a/variables.h +++ b/variables.h @@ -6,6 +6,9 @@ #define RC_CHANNEL_MIN 990 #define RC_CHANNEL_MAX 2010 +#define RX_TASK_HEALTH 200 //5Hz should be enough +#define RSSI_CHANNEL 11 + #define RX_RX_HEALTH_FRAME_RATE 1000 #define TX_RC_FRAME_RATE 500 //ms #define RX_FAILSAFE_DELAY (TX_RC_FRAME_RATE * 8)