Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://github.com/adafruit/Adafruit_CircuitPython_BME680/issues/67 #68

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions adafruit_bme680.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def __init__(self, *, refresh_rate: int = 10) -> None:
self._humidity_oversample = 0b010
self._filter = 0b010

# Gas measurements, as a mask applied to _BME680_RUNGAS
self._run_gas = 0xFF

self._adc_pres = None
self._adc_temp = None
self._adc_hum = None
Expand Down Expand Up @@ -389,9 +392,9 @@ def _perform_reading(self) -> None:
self._write(_BME680_REG_CTRL_HUM, [self._humidity_oversample])
# gas measurements enabled
if self._chip_variant == 0x01:
self._write(_BME680_REG_CTRL_GAS, [_BME680_RUNGAS << 1])
self._write(_BME680_REG_CTRL_GAS, [(self._run_gas & _BME680_RUNGAS) << 1])
else:
self._write(_BME680_REG_CTRL_GAS, [_BME680_RUNGAS])
self._write(_BME680_REG_CTRL_GAS, [(self._run_gas & _BME680_RUNGAS)])
ctrl = self._read_byte(_BME680_REG_CTRL_MEAS)
ctrl = (ctrl & 0xFC) | 0x01 # enable single shot!
self._write(_BME680_REG_CTRL_MEAS, [ctrl])
Expand Down Expand Up @@ -492,6 +495,7 @@ def _set_heatr_conf(
else:
hctrl = _BME68X_DISABLE_HEATER
run_gas = _BME68X_DISABLE_GAS_MEAS
self._run_gas = ~(run_gas - 1)

ctrl_gas_data_0 = bme_set_bits(
ctrl_gas_data_0, _BME68X_HCTRL_MSK, _BME68X_HCTRL_POS, hctrl
Expand Down Expand Up @@ -598,7 +602,7 @@ def _calc_gas_wait(self, dur: int) -> int:
factor: int = 0
durval: int = 0xFF # Max duration

if dur < 0xFC0:
if dur >= 0xFC0:
return durval
while dur > 0x3F:
dur = dur / 4
Expand Down