1
0
mirror of https://github.com/cmur2/python-bme680.git synced 2025-07-06 11:11:26 +02:00

Test suites and code QA fixes

This commit is contained in:
Phil Howard
2018-09-02 11:26:04 +01:00
parent c97791d720
commit 6374bc4241
15 changed files with 384 additions and 180 deletions

View File

@ -1,23 +1,28 @@
#!/usr/bin/env python
import bme680
import time
print("""Display Temperature, Pressure, Humidity and Gas
Press Ctrl+C to exit
""")
sensor = bme680.BME680()
# These calibration data can safely be commented
# out, if desired.
print("Calibration data:")
print('Calibration data:')
for name in dir(sensor.calibration_data):
if not name.startswith('_'):
value = getattr(sensor.calibration_data, name)
if isinstance(value, int):
print("{}: {}".format(name, value))
print('{}: {}'.format(name, value))
# These oversampling settings can be tweaked to
# These oversampling settings can be tweaked to
# change the balance between accuracy and noise in
# the data.
@ -27,12 +32,12 @@ sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
print("\n\nInitial reading:")
print('\n\nInitial reading:')
for name in dir(sensor.data):
value = getattr(sensor.data, name)
if not name.startswith('_'):
print("{}: {}".format(name, value))
print('{}: {}'.format(name, value))
sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
@ -43,14 +48,19 @@ sensor.select_gas_heater_profile(0)
# sensor.set_gas_heater_profile(200, 150, nb_profile=1)
# sensor.select_gas_heater_profile(1)
print("\n\nPolling:")
print('\n\nPolling:')
try:
while True:
if sensor.get_sensor_data():
output = "{0:.2f} C,{1:.2f} hPa,{2:.2f} %RH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
output = '{0:.2f} C,{1:.2f} hPa,{2:.2f} %RH'.format(
sensor.data.temperature,
sensor.data.pressure,
sensor.data.humidity)
if sensor.data.heat_stable:
print("{0},{1} Ohms".format(output, sensor.data.gas_resistance))
print('{0},{1} Ohms'.format(
output,
sensor.data.gas_resistance))
else:
print(output)