kopia lustrzana https://github.com/robert-hh/BME280
bme280_xxx.py: Make the code a little bit more PEP8 compliant
rodzic
92773a9c95
commit
0223507e1e
|
@ -1,3 +1,10 @@
|
|||
# Updated 2018
|
||||
# This module is based on the below cited resources, which are all
|
||||
# based on the documentation as provided in the Bosch Data Sheet and
|
||||
# the sample implementation provided therein.
|
||||
#
|
||||
# Final Document: BST-BME280-DS002-15
|
||||
#
|
||||
# Authors: Paul Cunnane 2016, Peter Dahlebrg 2016
|
||||
#
|
||||
# This module borrows from the Adafruit BME280 Python library. Original
|
||||
|
@ -31,6 +38,7 @@
|
|||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
import time
|
||||
from ustruct import unpack, unpack_from
|
||||
|
@ -140,8 +148,8 @@ class BME280:
|
|||
this to read out the sensor without allocating heap memory
|
||||
|
||||
Returns:
|
||||
array with temperature, pressure, humidity. Will be the one from
|
||||
the result parameter if not None
|
||||
array with temperature, pressure, humidity. Will be the one
|
||||
from the result parameter if not None
|
||||
"""
|
||||
self.read_raw_data(self._l3_resultarray)
|
||||
raw_temp, raw_press, raw_hum = self._l3_resultarray
|
||||
|
@ -200,8 +208,8 @@ class BME280:
|
|||
'''
|
||||
from math import pow
|
||||
try:
|
||||
p = 44330 * (1.0 - pow(self.read_compensated_data()[1]
|
||||
/ self.__sealevel, 0.1903))
|
||||
p = 44330 * (1.0 - pow(self.read_compensated_data()[1] /
|
||||
self.__sealevel, 0.1903))
|
||||
except:
|
||||
p = 0.0
|
||||
return p
|
||||
|
@ -225,4 +233,3 @@ class BME280:
|
|||
|
||||
return ("{:.2f}C".format(t), "{:.2f}hPa".format(p/100),
|
||||
"{:.2f}%".format(h))
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
# Updated 2018
|
||||
# This module is based on the below cited resources, which are all
|
||||
# based on the documentation as provided in the Bosch Data Sheet and
|
||||
# the sample implementation provided therein.
|
||||
#
|
||||
# Final Document: BST-BME280-DS002-15
|
||||
#
|
||||
# Authors: Paul Cunnane 2016, Peter Dahlebrg 2016
|
||||
#
|
||||
# This module borrows from the Adafruit BME280 Python library. Original
|
||||
|
@ -31,6 +38,11 @@
|
|||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
# Based on the documentation as provided in the Bosch Data Sheet and
|
||||
# the sample implementation provided therein.
|
||||
# Document BST-BME280-DS002-15
|
||||
#
|
||||
|
||||
import time
|
||||
from ustruct import unpack, unpack_from
|
||||
|
@ -139,8 +151,8 @@ class BME280:
|
|||
this to read out the sensor without allocating heap memory
|
||||
|
||||
Returns:
|
||||
array with temperature, pressure, humidity. Will be the one from
|
||||
the result parameter if not None
|
||||
array with temperature, pressure, humidity. Will be the one
|
||||
from the result parameter if not None
|
||||
"""
|
||||
self.read_raw_data(self._l3_resultarray)
|
||||
raw_temp, raw_press, raw_hum = self._l3_resultarray
|
||||
|
@ -170,10 +182,10 @@ class BME280:
|
|||
# humidity
|
||||
h = self.t_fine - 76800
|
||||
h = (((((raw_hum << 14) - (self.dig_H4 << 20) -
|
||||
(self.dig_H5 * h)) + 16384)
|
||||
>> 15) * (((((((h * self.dig_H6) >> 10) *
|
||||
(((h * self.dig_H3) >> 11) + 32768)) >> 10) +
|
||||
2097152) * self.dig_H2 + 8192) >> 14))
|
||||
(self.dig_H5 * h)) + 16384) >> 15) *
|
||||
(((((((h * self.dig_H6) >> 10) *
|
||||
(((h * self.dig_H3) >> 11) + 32768)) >> 10) + 2097152) *
|
||||
self.dig_H2 + 8192) >> 14))
|
||||
h = h - (((((h >> 15) * (h >> 15)) >> 7) * self.dig_H1) >> 4)
|
||||
h = 0 if h < 0 else h
|
||||
h = 419430400 if h > 419430400 else h
|
||||
|
@ -203,8 +215,8 @@ class BME280:
|
|||
'''
|
||||
from math import pow
|
||||
try:
|
||||
p = 44330 * (1.0 - pow((self.read_compensated_data()[1] / 256)
|
||||
/ self.__sealevel, 0.1903))
|
||||
p = 44330 * (1.0 - pow((self.read_compensated_data()[1] / 256) /
|
||||
self.__sealevel, 0.1903))
|
||||
except:
|
||||
p = 0.0
|
||||
return p
|
||||
|
@ -233,4 +245,3 @@ class BME280:
|
|||
h = h / 1024
|
||||
return ("{}C".format(t / 100), "{:.02f}hPa".format(p/100),
|
||||
"{:.02f}%".format(h))
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue