Code cleanup
This commit is contained in:
23
crossbow.ino
23
crossbow.ino
@@ -1,7 +1,7 @@
|
|||||||
#define LORA_HARDWARE_SPI
|
#define LORA_HARDWARE_SPI
|
||||||
|
|
||||||
#define DEVICE_MODE_TX
|
// #define DEVICE_MODE_TX
|
||||||
// #define DEVICE_MODE_RX
|
#define DEVICE_MODE_RX
|
||||||
|
|
||||||
#define FEATURE_TX_OLED
|
#define FEATURE_TX_OLED
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ uint32_t lastOledTaskTime = 0;
|
|||||||
*/
|
*/
|
||||||
volatile QspConfiguration_t qsp = {};
|
volatile QspConfiguration_t qsp = {};
|
||||||
volatile RxDeviceState_t rxDeviceState = {};
|
volatile RxDeviceState_t rxDeviceState = {};
|
||||||
|
volatile TxDeviceState_t txDeviceState = {};
|
||||||
|
|
||||||
#ifdef LORA_HARDWARE_SPI
|
#ifdef LORA_HARDWARE_SPI
|
||||||
|
|
||||||
@@ -272,20 +273,16 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
volatile bool readPacket = false;
|
|
||||||
uint8_t myRssi = 0;
|
|
||||||
uint8_t mySnr = 0;
|
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
#ifdef DEVICE_MODE_TX
|
#ifdef DEVICE_MODE_TX
|
||||||
if (readPacket) {
|
if (txDeviceState.readPacket) {
|
||||||
while (LoRa.available()) {
|
while (LoRa.available()) {
|
||||||
qspDecodeIncomingFrame(&qsp, LoRa.read(), ppm, &rxDeviceState);
|
qspDecodeIncomingFrame(&qsp, LoRa.read(), ppm, &rxDeviceState);
|
||||||
}
|
}
|
||||||
myRssi = getRadioRssi();
|
txDeviceState.rssi = getRadioRssi();
|
||||||
mySnr = getRadioSnr();
|
txDeviceState.snr = getRadioSnr();
|
||||||
readPacket = false;
|
txDeviceState.readPacket = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -411,11 +408,11 @@ void loop(void)
|
|||||||
display.setTextColor(WHITE, BLACK);
|
display.setTextColor(WHITE, BLACK);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("TX RSSI: ");
|
display.print("TX RSSI: ");
|
||||||
display.print(map(myRssi, 0, 255, 0, 100));
|
display.print(map(txDeviceState.rssi, 0, 255, 0, 100));
|
||||||
|
|
||||||
display.setCursor(0, 12);
|
display.setCursor(0, 12);
|
||||||
display.print("TX SNR: ");
|
display.print("TX SNR: ");
|
||||||
display.print(mySnr);
|
display.print(txDeviceState.snr);
|
||||||
|
|
||||||
display.setCursor(0, 24);
|
display.setCursor(0, 24);
|
||||||
display.print("RX RSSI: ");
|
display.print("RX RSSI: ");
|
||||||
@@ -452,7 +449,7 @@ void onReceive(int packetSize)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_TX
|
#ifdef DEVICE_MODE_TX
|
||||||
readPacket = true;
|
txDeviceState.readPacket = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_RX
|
#ifdef DEVICE_MODE_RX
|
||||||
|
|||||||
10
variables.h
10
variables.h
@@ -11,7 +11,7 @@
|
|||||||
#define RX_TASK_HEALTH 200 //5Hz should be enough
|
#define RX_TASK_HEALTH 200 //5Hz should be enough
|
||||||
#define RSSI_CHANNEL 11
|
#define RSSI_CHANNEL 11
|
||||||
|
|
||||||
#define TX_TRANSMIT_SLOT_RATE 57 //ms
|
#define TX_TRANSMIT_SLOT_RATE 50 //ms
|
||||||
#define RX_FAILSAFE_DELAY (TX_TRANSMIT_SLOT_RATE * 8)
|
#define RX_FAILSAFE_DELAY (TX_TRANSMIT_SLOT_RATE * 8)
|
||||||
|
|
||||||
#define CHANNEL_ID 0x01
|
#define CHANNEL_ID 0x01
|
||||||
@@ -82,6 +82,14 @@ struct QspConfiguration_t {
|
|||||||
bool transmitWindowOpen = false;
|
bool transmitWindowOpen = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TxDeviceState_t {
|
||||||
|
uint8_t rssi = 0;
|
||||||
|
uint8_t snr = 0;
|
||||||
|
uint8_t flags = 0;
|
||||||
|
uint32_t roundtrip = 0;
|
||||||
|
bool readPacket = false;
|
||||||
|
};
|
||||||
|
|
||||||
struct RxDeviceState_t {
|
struct RxDeviceState_t {
|
||||||
uint8_t rssi = 0;
|
uint8_t rssi = 0;
|
||||||
uint8_t snr = 0;
|
uint8_t snr = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user