Commit graph

30 commits

Author SHA1 Message Date
dherrada
6fb01e73c4 Ran black, updated to pylint 2.x 2020-03-16 15:16:30 -04:00
Barbudor
8975faee83 fix #19 with proper struct unpack
tested with simulation:
# 0xE1 / 0xE2         dig_H2 [7:0]  / [15:8]    signed short
# 0xE3                dig_H3 [7:0]              unsigned char
# 0xE4 / 0xE5[3:0]    dig_H4 [11:4] / [3:0]     signed short
# 0xE5[7:4] / 0xE6    dig_H5 [3:0]  / [11:4]    signed short
# 0xE7                dig_H6                    signed char

>>> coeff = [ 0x12, 0xFF, 0xAA, 0xEE, 0x46, 0xCC, 0x88 ]
>>> coeff = list(struct.unpack('<hBbBbb', bytes(coeff)))
>>> float(coeff[0])                                 # 0xFF12 -> -238.0
-238.0
>>> float(coeff[1])                                 # 0xAA -> 170.0
170.0
>>> float((coeff[2] << 4) |  (coeff[3] & 0xF))      # 0xEE6 -> -282.0
-282.0
>>> float((coeff[4] << 4) | (coeff[3] >> 4))        # 0xCC4 -> -828.0
-828.0
>>> float(coeff[5])                                 # 0x88 -> -120.0
-120.0
>>>
2019-06-01 15:55:02 +02:00
Barbudor
a2d13f1ada refactor pressure property to handle ZeroDivision case
Recap: in the `pressure` property there is a test `if var1 == 0:` in order to avoid a division-by-zero exception. Current code return a pressure of 0 in that case.
It was suggested that my PR makes this a little more pythonic by usage of exception raise.

Analysis of the root cause: because last calculation is
```var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0]```
the only reason for `var1` to be 0 is `self._pressure_calib[0]` is 0. Calibration values are read at init time from registers in the chip. So the root cause probably relates to a register read problem.

Analysis of other similar codes
Bosch bme280.c (Github): if var1 == 0, return minimum valid pressure (300hPa).
Adafruit CiPy BMP280 driver:
  => initially, no tests were performed
  => In Feb, jraber implemeted return 0 in a commit named "Adopt changes from the BME280 library"
  => In Mar, jraber implemeted return minimum value in a commit named "Remove unnecessary 'if' and 'else' in the pressure property"
Adafruit CiPy BMP680 driver: not tested => ZeroDivisionError

I feel that returning silently the minimun valid pressure is not correct to draw attention on a possible hardware reliability problem. Returning 0 could make sense only if we were sure that the user was testing the return value against 0.
Alternatively, letting the ZeroDivisionError occur will not provide proper clue to the user as to the root cause of the problem and will probably lead to this issue to be raised again as a bug in GitHub.

Proposed solution:
Test against 0 and raise a ArithmeticError with message "Invalid calculation possibly related to error while reading the calibration registers"
2019-06-01 13:25:35 +02:00
Barbudor
cf74245929 fix issue#25 (removed frozenset()) + refactor pressure property
Removed `frozenset()` on `_BME280_IIR_FILTERS`, `_BME280_MODES`, `_BME280_STANDBY_TCS`. Kept as tuples.

Removed useless `if/else` in property `pressure` (was pointed by pylint)
2019-05-31 23:51:07 +02:00
Jeff Raber
0a10d868a6 Don't enable SPI 3-wire interface 2019-03-13 00:34:33 -05:00
Jeff Raber
9c37a711e2 Always write the new mode to the sensor
In FORCE mode, the sensor changes back to SLEEP after completeing a single
measurement, but we are not updating the mode internally.  It's better to
always write the mode to the sensor, and trust the caller not to change it
needlessly.
2019-03-12 23:42:40 -05:00
Jeff Raber
f40fb2c9d4 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
2019-03-07 03:17:02 -06:00
Jeff Raber
79d4e8556e Do not return None when temp, pressure, or humidity value = 0x80000
0x800000 is the *default* value and is a valid value
2019-03-07 02:04:27 -06:00
Jeff Raber
ef0eef6145 Refactor to remove dependency on the enum class
Removed references to the enum class, while keeping the same
functionality

Updated the 'normal mode' example
2019-03-01 08:13:40 -06:00
Jeff Raber
3b37d55d0e Add disable=too-many-instance-attributes to keep pylint happy 2019-02-28 07:52:20 -06:00
Jeff Raber
3284ed4fc0 Fix __write_config, docstring comes first 2019-02-27 08:58:32 -06:00
Jeff Raber
e9d7320639 Fix typo: standy -> standby 2019-02-27 08:50:04 -06:00
Jeff Raber
29af22eabc Default normal_flag to False to avoid UnboundLocalError in _write_config 2019-02-27 08:35:14 -06:00
Jeff Raber
032d38c749 Increase underline length to make sphinx happy 2019-02-27 01:38:19 -06:00
Jeff Raber
dc89e0becd Fix-up overscan_tempearure as it was returning the wrong value 2019-02-27 01:36:06 -06:00
Jeff Raber
3ebd5c3075 Add class attributes to allow more control over the sensor
Add attributes for IIR filter, standby period, operation mode,
 and overscan for temperature, pressure and humidity.

Add Enum classes for the overscan, standby, and iir filter values
2019-02-27 00:37:49 -06:00
hh
e947bde6bb adafruit_bme280.py: Fix the value of dig_H5
The calculation of dig_H5 from the calibration data did not match the
definition of the data sheet and the Bosch sample code. As a result,
the compensated relative humidity data could have been calculated wrong.
2018-11-17 08:51:21 +01:00
Kattni
6a9d4e7bf1
Revert "Added dew point, updated example" 2018-08-14 16:34:51 -04:00
Kattni Rembor
cdd59a110b Linting. 2018-08-13 12:20:18 -04:00
Kattni Rembor
12a7d6e558 Added dew point, updated example 2018-08-13 11:37:52 -04:00
ladyada
2f0c5aeda9 fix for context-member pylint bug 2018-06-29 22:15:10 -04:00
sommersoft
c9fd02b4a3 pylint fix 2018-02-22 23:50:28 -06:00
sommersoft
3d1b9141ad expanded title on main docstring; also forgot to turn on Travis...hehe 2018-02-22 23:48:16 -06:00
sommersoft
fb5aa30d54 added double backticks to doc string 2018-02-22 23:44:29 -06:00
jerryneedell
3bec108e32
fix typo for chip_id - line 78
The "id" variable was changed to "chip_id" but this one was missed.
2017-12-08 20:18:54 -05:00
Scott Shawcroft
1af59b660e Update auto build, turn on lint and make lint pass.
This changes the attribute seaLevelhPa to sea_level_pressure to
match python naming standards.
2017-12-05 17:18:36 -08:00
mrmcwethy
2d9c93a7b1 changed read_into to readinto 2017-11-08 13:55:26 -08:00
Scott Shawcroft
f8897dcf80 Fix up the docs. 2017-10-31 10:41:40 -07:00
ladyada
51ffff97ff example in RST 2017-10-27 20:37:55 -04:00
ladyada
1deea3c96c init 2017-10-27 19:24:45 -04:00