adafruit / Adafruit_TSL2591_Library

This is an Arduino library for the TSL2591 digital luminosity (light) sensors.
58 stars 48 forks source link

allow for 'non-blocking' read of values #27

Open s-light opened 5 years ago

s-light commented 5 years ago

currently the library blocks on every reading of the sensor values:

uint32_t Adafruit_TSL2591::getFullLuminosity (void) {
  // ....
  // Wait x ms for ADC to complete
  for (uint8_t d=0; d<=_integration; d++)
  {
    delay(120);
  }
  // ....
}

(all specialized readings are calling the getFullLuminosity function)

this delay is needed because the lib enables the sensor for every interaction and disables it afterwards. but i think a ~100-600ms blocking delay just for getting a sensor reading is not a nice thing to do.. → if the sensor is left running you just can read a value and be happy ;-)

if you want to make sure you get a valid reading - first check the Status Register for AVALID. if the lib needs to make sure it always gets a new conversion value i think after the read we could disable only the AEN flag (Enable Register) and re enable it directly again. this should clear the AVALID flag.

i would try and create a pull-request - but i first need a ok/info for how to do this in line with the adafruit goals!

so the fix for this should also fix #12