Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/BH1750.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe out of place in this PR. I can move it if preferred.
This exits early in the case that nothing was sent over the bus. If nothing was sent then there is no need to check for an ACK or print another error

}

// Check result code
Expand All @@ -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;
Expand All @@ -130,6 +134,7 @@ bool BH1750::configure(Mode mode) {
default:
Serial.println(F("[BH1750] ERROR: undefined error"));
break;
#endif
}

return false;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -184,6 +192,7 @@ bool BH1750::setMTreg(byte MTreg) {
default:
Serial.println(F("[BH1750] ERROR: undefined error"));
break;
#endif
}

return false;
Expand Down Expand Up @@ -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;
}

Expand Down