From e49a14e40c8e225c75e80c43c1a9d157252c5c2c Mon Sep 17 00:00:00 2001 From: QuentinTorg Date: Fri, 18 Aug 2023 16:09:10 -0400 Subject: [PATCH] add guards around all debug prints to prevent unwanted noise in serial terminal when not debugging BH1750 --- src/BH1750.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/BH1750.cpp b/src/BH1750.cpp index 3eb9a5d..1be10e3 100644 --- a/src/BH1750.cpp +++ b/src/BH1750.cpp @@ -105,8 +105,11 @@ bool BH1750::configure(Mode mode) { default: // Invalid measurement mode +#ifdef BH1750_DEBUG Serial.println(F("[BH1750] ERROR: Invalid mode")); - break; +#endif + // out of range input, safe to return early + return false; } // Check result code @@ -115,6 +118,7 @@ bool BH1750::configure(Mode mode) { BH1750_MODE = mode; lastReadTimestamp = millis(); return true; +#ifdef BH1750_DEBUG case 1: // too long for transmit buffer Serial.println(F("[BH1750] ERROR: too long for transmit buffer")); break; @@ -130,6 +134,7 @@ bool BH1750::configure(Mode mode) { default: Serial.println(F("[BH1750] ERROR: undefined error")); break; +#endif } return false; @@ -144,7 +149,9 @@ bool BH1750::configure(Mode mode) { */ bool BH1750::setMTreg(byte MTreg) { if (MTreg < BH1750_MTREG_MIN || MTreg > BH1750_MTREG_MAX) { +#ifdef BH1750_DEBUG Serial.println(F("[BH1750] ERROR: MTreg out of range")); +#endif return false; } byte ack = 5; @@ -169,6 +176,7 @@ bool BH1750::setMTreg(byte MTreg) { case 0: BH1750_MTreg = MTreg; return true; +#ifdef BH1750_DEBUG case 1: // too long for transmit buffer Serial.println(F("[BH1750] ERROR: too long for transmit buffer")); break; @@ -184,6 +192,7 @@ bool BH1750::setMTreg(byte MTreg) { default: Serial.println(F("[BH1750] ERROR: undefined error")); break; +#endif } return false; @@ -239,7 +248,9 @@ bool BH1750::measurementReady(bool maxWait) { float BH1750::readLightLevel() { if (BH1750_MODE == UNCONFIGURED) { +#ifdef BH1750_DEBUG Serial.println(F("[BH1750] Device is not configured!")); +#endif return -2.0; }