[TSL2591] Perform async reading of sensor prevent blocking calls

This commit is contained in:
TD-er
2020-10-28 17:19:54 +01:00
parent cfe7d2f2cf
commit 46ee0ffe19
3 changed files with 109 additions and 30 deletions
+23
View File
@@ -250,6 +250,29 @@ uint32_t Adafruit_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1)
return (uint32_t) calculateLuxf(ch0, ch1);
}
uint32_t Adafruit_TSL2591::getFullLuminosity (bool& finished)
{
const uint8_t status = read8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_DEVICE_STATUS);
// ALS Valid. Indicates that the ADC channels have completed an
// integration cycle since the AEN bit was asserted.
finished = status & 0x01;
if (!finished) {
return 0;
}
uint32_t x;
uint16_t y = 0;
y |= read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN0_LOW);
x = read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN1_LOW);
x <<= 16;
x |= y;
disable();
return x;
}
uint32_t Adafruit_TSL2591::getFullLuminosity (void)
{
if (!_initialized)
+1
View File
@@ -163,6 +163,7 @@ class Adafruit_TSL2591 : public Adafruit_Sensor
void setTiming ( tsl2591IntegrationTime_t integration );
uint16_t getLuminosity (uint8_t channel );
uint32_t getFullLuminosity ( );
uint32_t getFullLuminosity (bool& finished);
tsl2591IntegrationTime_t getTiming();
tsl2591Gain_t getGain();