Skip to content

Commit f40fb2c

Browse files
committed
Add properties for the typical and maximum measurement time
Changed_BME280_OVERSCANS from frozenset to dict to allow lookup of the associated value for the measurement time calculation
1 parent 79d4e85 commit f40fb2c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

adafruit_bme280.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
OVERSCAN_X8 = const(0x04)
8686
OVERSCAN_X16 = const(0x05)
8787

88-
_BME280_OVERSCANS = frozenset((OVERSCAN_DISABLE, OVERSCAN_X1, OVERSCAN_X2,
89-
OVERSCAN_X4, OVERSCAN_X8, OVERSCAN_X16))
88+
_BME280_OVERSCANS = {OVERSCAN_DISABLE:0, OVERSCAN_X1:1, OVERSCAN_X2:2,
89+
OVERSCAN_X4:4, OVERSCAN_X8:8, OVERSCAN_X16:16}
9090

9191
"""mode values"""
9292
MODE_SLEEP = const(0x00)
@@ -300,6 +300,30 @@ def _ctrl_meas(self):
300300
ctrl_meas += self.mode
301301
return ctrl_meas
302302

303+
@property
304+
def measurement_time_typical(self):
305+
"""Typical time in milliseconds required to complete a measurement in normal mode"""
306+
meas_time_ms = 1.0
307+
if self.overscan_temperature != OVERSCAN_DISABLE:
308+
meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_temperature))
309+
if self.overscan_pressure != OVERSCAN_DISABLE:
310+
meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.5)
311+
if self.overscan_humidity != OVERSCAN_DISABLE:
312+
meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.5)
313+
return meas_time_ms
314+
315+
@property
316+
def measurement_time_max(self):
317+
"""Maximum time in milliseconds required to complete a measurement in normal mode"""
318+
meas_time_ms = 1.25
319+
if self.overscan_temperature != OVERSCAN_DISABLE:
320+
meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_temperature))
321+
if self.overscan_pressure != OVERSCAN_DISABLE:
322+
meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.575)
323+
if self.overscan_humidity != OVERSCAN_DISABLE:
324+
meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.575)
325+
return meas_time_ms
326+
303327
@property
304328
def temperature(self):
305329
"""The compensated temperature in degrees celsius."""

0 commit comments

Comments
 (0)