From 3006a6a08204649d3dc4cda4e87e1ea5644061bc Mon Sep 17 00:00:00 2001 From: Michael Kolomiets Date: Wed, 21 Apr 2021 10:25:14 +0300 Subject: [PATCH] Issue with float in ISR on ESP32 --- src/LoRa.cpp | 9 +++++++++ src/LoRa.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/LoRa.cpp b/src/LoRa.cpp index 210a589..29a6382 100644 --- a/src/LoRa.cpp +++ b/src/LoRa.cpp @@ -266,7 +266,11 @@ int LoRaClass::packetRssi() return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT)); } +#if !defined(ESP32) float LoRaClass::packetSnr() +#else +double LoRaClass::packetSnr() +#endif { return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25; } @@ -284,8 +288,13 @@ long LoRaClass::packetFrequencyError() freqError -= 524288; // B1000'0000'0000'0000'0000 } +#if !defined(ESP32) const float fXtal = 32E6; // FXOSC: crystal oscillator (XTAL) frequency (2.5. Chip Specification, p. 14) const float fError = ((static_cast(freqError) * (1L << 24)) / fXtal) * (getSignalBandwidth() / 500000.0f); // p. 37 +#else + const double fXtal = 32E6; // FXOSC: crystal oscillator (XTAL) frequency (2.5. Chip Specification, p. 14) + const double fError = ((static_cast(freqError) * (1L << 24)) / fXtal) * (getSignalBandwidth() / 500000.0); // p. 37 +#endif return static_cast(fError); } diff --git a/src/LoRa.h b/src/LoRa.h index b312db5..bcc3e98 100644 --- a/src/LoRa.h +++ b/src/LoRa.h @@ -42,7 +42,11 @@ class LoRaClass : public Stream { int parsePacket(int size = 0); int packetRssi(); +#if !defined(ESP32) float packetSnr(); +#else + double packetSnr(); +#endif long packetFrequencyError(); int rssi();