From bcb5729944e8034b0382a314bc21c7ef6b7b1646 Mon Sep 17 00:00:00 2001 From: Bernd Giesecke Date: Sat, 9 Jan 2016 23:43:37 +0800 Subject: [PATCH] Changed return value of getEvent value of 0 could be a valid value in darkness, better to return a value > 65535 to report saturation and return false from getEvent in that case! --- Adafruit_TSL2561_U.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Adafruit_TSL2561_U.cpp b/Adafruit_TSL2561_U.cpp index 0111ef6..0517185 100644 --- a/Adafruit_TSL2561_U.cpp +++ b/Adafruit_TSL2561_U.cpp @@ -385,10 +385,10 @@ uint32_t Adafruit_TSL2561_Unified::calculateLux(uint16_t broadband, uint16_t ir) break; } - /* Return 0 lux if the sensor is saturated */ + /* Return 65536 lux if the sensor is saturated */ if ((broadband > clipThreshold) || (ir > clipThreshold)) { - return 0; + return 65536; } /* Get the correct scale depending on the intergration time */ @@ -476,6 +476,8 @@ uint32_t Adafruit_TSL2561_Unified::calculateLux(uint16_t broadband, uint16_t ir) /**************************************************************************/ /*! @brief Gets the most recent sensor event + returns true if sensor reading is between 0 and 65535 lux + returns false if sensor is saturated */ /**************************************************************************/ bool Adafruit_TSL2561_Unified::getEvent(sensors_event_t *event) @@ -494,6 +496,9 @@ bool Adafruit_TSL2561_Unified::getEvent(sensors_event_t *event) getLuminosity(&broadband, &ir); event->light = calculateLux(broadband, ir); + if (event->light == 65536) { + return false; + } return true; }