adafruit / Adafruit_BMP085_Unified

Unified sensor driver for Adafruit's BMP085 & BMP180 breakouts
93 stars 60 forks source link

Support for a non-blocking access pattern #24

Open JeffyW opened 8 years ago

JeffyW commented 8 years ago

In this library, the standard readRawTemperature and ReadRawPressure code makes use of delays to allow the sensor to perform the reads as per the datasheet. When reading the pressure at higher resolutions, these delays can exceed 31ms (5ms for temp and another 26ms for the highest resolution pressure).

On an Arduino Mega 2560 with a 16mhz board hooked up to a 10DoF, it takes approximately:

Rather than wasting that time sitting in a delay, we could be processing data from other sensors.

I'd like to propose adding a method like "isDataReady()" which internally would issue the requests and record what time the request would complete, and when called after that time has passed, read the data into a persisted variable and kick off the next request. When polling in this mode, the getTemperature and getPressure calls would simply use the persisted variable rather than requesting / reading the data directly.