forked from adafruit/Adafruit_TSL2561
Merge pull request #3 from beegee-tokyo/master
Changed return value of getEvent and value of event.light in case of saturation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sen
|
||||
tsl.enableAutoGain(true); /* Auto-gain ... switches automatically between 1x and 16x */
|
||||
```
|
||||
|
||||
The driver also supports as automatic clipping detection, and will return '0' lux when the sensor is saturated and data is unreliable.
|
||||
The driver also supports as automatic clipping detection, and will return '65536' lux when the sensor is saturated and data is unreliable. tsl.getEvent will return false in case of saturation and true in case of valid light data.
|
||||
|
||||
## About the TSL2561 ##
|
||||
|
||||
@@ -44,4 +44,4 @@ Light sensors will always report units in lux, gyroscopes will always report uni
|
||||
|
||||
Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||
|
||||
Written by Kevin (KTOWN) Townsend for Adafruit Industries.
|
||||
Written by Kevin (KTOWN) Townsend for Adafruit Industries.
|
||||
|
Reference in New Issue
Block a user