From 8c68d888c80f0199021c6753b088d670d4a8f7bd Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:23:37 +0100 Subject: [PATCH] SX126x: Try next Interface when chip not found (#2363) * If chip was not found, return false for init() * SX1268: Only overwrite frequency when out of bounds Happens when region is still UNSET --- src/mesh/SX1268Interface.cpp | 9 +++++++++ src/mesh/SX1268Interface.h | 3 +-- src/mesh/SX126xInterface.cpp | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mesh/SX1268Interface.cpp b/src/mesh/SX1268Interface.cpp index cae4bac41..62cdfefe0 100644 --- a/src/mesh/SX1268Interface.cpp +++ b/src/mesh/SX1268Interface.cpp @@ -6,4 +6,13 @@ SX1268Interface::SX1268Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RA SPIClass &spi) : SX126xInterface(cs, irq, rst, busy, spi) { +} + +float SX1268Interface::getFreq() +{ + // Set frequency to default of EU_433 if outside of allowed range (e.g. when region is UNSET) + if (savedFreq < 410 || savedFreq > 810) + return 433.125f; + else + return savedFreq; } \ No newline at end of file diff --git a/src/mesh/SX1268Interface.h b/src/mesh/SX1268Interface.h index a288cdd09..f40fcf37b 100644 --- a/src/mesh/SX1268Interface.h +++ b/src/mesh/SX1268Interface.h @@ -8,8 +8,7 @@ class SX1268Interface : public SX126xInterface { public: - /// override frequency of the SX1268 module regardless of the region (use EU433 value) - virtual float getFreq() override { return 433.175f; } + virtual float getFreq() override; SX1268Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi); }; diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index c4145a30c..acf84d1b6 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -47,6 +47,8 @@ template bool SX126xInterface::init() int res = lora.begin(getFreq(), bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO); // \todo Display actual typename of the adapter, not just `SX126x` LOG_INFO("SX126x init result %d\n", res); + if (res == RADIOLIB_ERR_CHIP_NOT_FOUND) + return false; LOG_INFO("Frequency set to %f\n", getFreq()); LOG_INFO("Bandwidth set to %f\n", bw);