@@ -288,7 +288,10 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
288288 if (lsb == 0xFF )
289289 {
290290 // I believe this is a Ublox bug. Device should never present an 0xFF.
291- debugPrintln ((char *)F (" checkUbloxI2C: Ublox bug, no bytes available" ));
291+ if (_printDebug == true )
292+ {
293+ _debugSerial->println (F (" checkUbloxI2C: Ublox bug, no bytes available" ));
294+ }
292295 if (checksumFailurePin >= 0 )
293296 {
294297 digitalWrite ((uint8_t )checksumFailurePin, LOW);
@@ -303,7 +306,10 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
303306
304307 if (bytesAvailable == 0 )
305308 {
306- debugPrintln ((char *)F (" checkUbloxI2C: OK, zero bytes available" ));
309+ if (_printDebug == true )
310+ {
311+ _debugSerial->println (F (" checkUbloxI2C: OK, zero bytes available" ));
312+ }
307313 lastCheck = millis (); // Put off checking to avoid I2C bus traffic
308314 return (false );
309315 }
@@ -375,7 +381,10 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
375381 {
376382 if (incoming == 0x7F )
377383 {
378- debugPrintln ((char *)F (" checkUbloxU2C: Ublox error, module not ready with data" ));
384+ if (_printDebug == true )
385+ {
386+ _debugSerial->println (F (" checkUbloxU2C: Ublox error, module not ready with data" ));
387+ }
379388 delay (5 ); // In logic analyzation, the module starting responding after 1.48ms
380389 if (checksumFailurePin >= 0 )
381390 {
@@ -609,9 +618,19 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
609618 printPacket (incomingUBX);
610619
611620 if (packetCfg.valid == true )
612- debugPrintln ((char *)F (" packetCfg now valid" ));
621+ {
622+ if (_printDebug == true )
623+ {
624+ _debugSerial->println (F (" packetCfg now valid" ));
625+ }
626+ }
613627 if (packetAck.valid == true )
614- debugPrintln ((char *)F (" packetAck now valid" ));
628+ {
629+ if (_printDebug == true )
630+ {
631+ _debugSerial->println (F (" packetAck now valid" ));
632+ }
633+ }
615634 }
616635
617636 processUBXpacket (incomingUBX); // We've got a valid packet, now do something with it
@@ -628,7 +647,7 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
628647 digitalWrite ((uint8_t )checksumFailurePin, HIGH);
629648 }
630649
631- debugPrint (( char *) F (" Checksum failed:" ));
650+ _debugSerial-> print ( F (" Checksum failed:" ));
632651 _debugSerial->print (F (" checksumA: " ));
633652 _debugSerial->print (incomingUBX->checksumA );
634653 _debugSerial->print (F (" checksumB: " ));
@@ -686,13 +705,19 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
686705 if (msg->id == UBX_ACK_ACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
687706 {
688707 // The ack we just received matched the CLS/ID of last packetCfg sent (or received)
689- debugPrintln ((char *)F (" UBX ACK: Command sent/ack'd successfully" ));
708+ if (_printDebug == true )
709+ {
710+ _debugSerial->println (F (" UBX ACK: Command sent/ack'd successfully" ));
711+ }
690712 commandAck = UBX_ACK_ACK;
691713 }
692714 else if (msg->id == UBX_ACK_NACK && msg->payload [0 ] == packetCfg.cls && msg->payload [1 ] == packetCfg.id )
693715 {
694716 // The ack we just received matched the CLS/ID of last packetCfg sent
695- debugPrintln ((char *)F (" UBX ACK: Not-Acknowledged" ));
717+ if (_printDebug == true )
718+ {
719+ _debugSerial->println (F (" UBX ACK: Not-Acknowledged" ));
720+ }
696721 commandAck = UBX_ACK_NACK;
697722 }
698723 break ;
@@ -817,7 +842,10 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
817842 retVal = sendI2cCommand (outgoingUBX, maxWait);
818843 if (retVal != SFE_UBLOX_STATUS_SUCCESS)
819844 {
820- debugPrintln ((char *)F (" Send I2C Command failed" ));
845+ if (_printDebug == true )
846+ {
847+ _debugSerial->println (F (" Send I2C Command failed" ));
848+ }
821849 return retVal;
822850 }
823851 }
@@ -831,12 +859,18 @@ sfe_ublox_status_e SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t ma
831859 // Depending on what we just sent, either we need to look for an ACK or not
832860 if (outgoingUBX.cls == UBX_CLASS_CFG)
833861 {
834- debugPrintln ((char *)F (" sendCommand: Waiting for ACK response" ));
862+ if (_printDebug == true )
863+ {
864+ _debugSerial->println (F (" sendCommand: Waiting for ACK response" ));
865+ }
835866 retVal = waitForACKResponse (outgoingUBX.cls , outgoingUBX.id , maxWait); // Wait for Ack response
836867 }
837868 else
838869 {
839- debugPrintln ((char *)F (" sendCommand: Waiting for No ACK response" ));
870+ if (_printDebug == true )
871+ {
872+ _debugSerial->println (F (" sendCommand: Waiting for No ACK response" ));
873+ }
840874 retVal = waitForNoACKResponse (outgoingUBX.cls , outgoingUBX.id , maxWait); // Wait for Ack response
841875 }
842876 }
@@ -1075,21 +1109,30 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
10751109 else
10761110 {
10771111 // Reset packet and continue checking incoming data for matching cls/id
1078- debugPrintln ((char *)F (" waitForACKResponse: CLS/ID mismatch, continue to wait..." ));
1112+ if (_printDebug == true )
1113+ {
1114+ _debugSerial->println (F (" waitForACKResponse: CLS/ID mismatch, continue to wait..." ));
1115+ }
10791116 packetCfg.valid = false ; // This will go true when we receive a response to the packet we sent
10801117 }
10811118 }
10821119 else
10831120 {
10841121 // We were expecting data but didn't get a valid config packet
1085- debugPrintln ((char *)F (" waitForACKResponse: Invalid config packet" ));
1122+ if (_printDebug == true )
1123+ {
1124+ _debugSerial->println (F (" waitForACKResponse: Invalid config packet" ));
1125+ }
10861126 return (SFE_UBLOX_STATUS_FAIL); // We got an ACK, we're never going to get valid config data
10871127 }
10881128 }
10891129 else
10901130 {
10911131 // We have sent new data. We expect an ACK but no return config packet.
1092- debugPrintln ((char *)F (" waitForACKResponse: New data successfully sent" ));
1132+ if (_printDebug == true )
1133+ {
1134+ _debugSerial->println (F (" waitForACKResponse: New data successfully sent" ));
1135+ }
10931136 return (SFE_UBLOX_STATUS_DATA_SENT); // New data successfully sent
10941137 }
10951138 }
@@ -1112,7 +1155,10 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForACKResponse(uint8_t requestedClass, uin
11121155 // Through debug warning, This command might not get an ACK
11131156 if (packetCfg.valid == true )
11141157 {
1115- debugPrintln ((char *)F (" waitForACKResponse: Config was valid but ACK not received" ));
1158+ if (_printDebug == true )
1159+ {
1160+ _debugSerial->println (F (" waitForACKResponse: Config was valid but ACK not received" ));
1161+ }
11161162 }
11171163
11181164 if (_printDebug == true )
@@ -1156,7 +1202,10 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
11561202 }
11571203 else
11581204 {
1159- debugPrintln ((char *)F (" waitForNoACKResponse: CLS/ID match but failed CRC" ));
1205+ if (_printDebug == true )
1206+ {
1207+ _debugSerial->println (F (" waitForNoACKResponse: CLS/ID match but failed CRC" ));
1208+ }
11601209 return (SFE_UBLOX_STATUS_CRC_FAIL); // We got the right packet but it was corrupt
11611210 }
11621211 }
@@ -1165,7 +1214,7 @@ sfe_ublox_status_e SFE_UBLOX_GPS::waitForNoACKResponse(uint8_t requestedClass, u
11651214 // Reset packet and continue checking incoming data for matching cls/id
11661215 if (_printDebug == true )
11671216 {
1168- debugPrint (( char *) F (" waitForNoACKResponse: CLS/ID mismatch: " ));
1217+ _debugSerial-> print ( F (" waitForNoACKResponse: CLS/ID mismatch: " ));
11691218 _debugSerial->print (F (" CLS: " ));
11701219 _debugSerial->print (packetCfg.cls , HEX);
11711220 _debugSerial->print (F (" ID: " ));
@@ -1758,7 +1807,10 @@ boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings,
17581807
17591808 if (commandAck != UBX_ACK_ACK)
17601809 {
1761- debugPrintln ((char *)F (" setPortOutput failed to ACK" ));
1810+ if (_printDebug == true )
1811+ {
1812+ _debugSerial->println (F (" setPortOutput failed to ACK" ));
1813+ }
17621814 return (false );
17631815 }
17641816
@@ -2145,7 +2197,10 @@ boolean SFE_UBLOX_GPS::powerSaveMode(bool power_save, uint16_t maxWait)
21452197 */
21462198 if (protVer >= 27 )
21472199 {
2148- debugPrintln ((char *)F (" powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version" ));
2200+ if (_printDebug == true )
2201+ {
2202+ _debugSerial->println (F (" powerSaveMode (UBX-CFG-RXM) is not supported by this protocol version" ));
2203+ }
21492204 return (false );
21502205 }
21512206
@@ -2303,19 +2358,28 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
23032358 if (autoPVT && autoPVTImplicitUpdate)
23042359 {
23052360 // The GPS is automatically reporting, we just check whether we got unread data
2306- debugPrintln ((char *)F (" getPVT: Autoreporting" ));
2361+ if (_printDebug == true )
2362+ {
2363+ _debugSerial->println (F (" getPVT: Autoreporting" ));
2364+ }
23072365 checkUblox ();
23082366 return moduleQueried.all ;
23092367 }
23102368 else if (autoPVT && !autoPVTImplicitUpdate)
23112369 {
23122370 // Someone else has to call checkUblox for us...
2313- debugPrintln ((char *)F (" getPVT: Exit immediately" ));
2371+ if (_printDebug == true )
2372+ {
2373+ _debugSerial->println (F (" getPVT: Exit immediately" ));
2374+ }
23142375 return (false );
23152376 }
23162377 else
23172378 {
2318- debugPrintln ((char *)F (" getPVT: Polling" ));
2379+ if (_printDebug == true )
2380+ {
2381+ _debugSerial->println (F (" getPVT: Polling" ));
2382+ }
23192383
23202384 // The GPS is not automatically reporting navigation position so we have to poll explicitly
23212385 packetCfg.cls = UBX_CLASS_NAV;
0 commit comments