From 2c35e729e70b70e360062f75901e75e4cec3bcd3 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Mon, 28 Jun 2021 10:59:57 +0100 Subject: [PATCH] Move SPI buffer new (memory allocation) to before isConnected --- src/SparkFun_u-blox_GNSS_Arduino_Library.cpp | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp index ebb119a..441d902 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp @@ -469,15 +469,6 @@ boolean SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpee createFileBuffer(); - // Call isConnected up to three times - boolean connected = isConnected(); - - if (!connected) - connected = isConnected(); - - if (!connected) - connected = isConnected(); - //Create the SPI buffer if (spiBuffer == NULL) //Memory has not yet been allocated - so use new { @@ -488,7 +479,8 @@ boolean SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpee { if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging { - _debugSerial->print(F("begin (SPI): memory allocation failed for SPI Buffer!")); + _debugSerial->print(F("begin (SPI): memory allocation failed for SPI Buffer!")); + return (false); } } else @@ -500,6 +492,15 @@ boolean SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpee } } + // Call isConnected up to three times + boolean connected = isConnected(); + + if (!connected) + connected = isConnected(); + + if (!connected) + connected = isConnected(); + return (connected); }