Skip to content

Commit 45beb4d

Browse files
authored
Merge pull request #29 from pimoroni/repackage
Tidyup and prep for v1.0.0
2 parents b6c2609 + a1f94cc commit 45beb4d

File tree

10 files changed

+37
-96
lines changed

10 files changed

+37
-96
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
1.0.0
22
-----
33

4-
* Repackage to pyproject.toml
4+
* Repackage to hatch/pyproject.toml
55
* Require i2cdevice>=1.0.0 (smbus2)
66

77
0.1.1

examples/all-values.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import time
44

5-
try:
6-
from smbus2 import SMBus
7-
except ImportError:
8-
from smbus import SMBus
5+
from smbus2 import SMBus
96

107
from bme280 import BME280
118

@@ -25,5 +22,5 @@
2522
temperature = bme280.get_temperature()
2623
pressure = bme280.get_pressure()
2724
humidity = bme280.get_humidity()
28-
print("{:05.2f}*C {:05.2f}hPa {:05.2f}%".format(temperature, pressure, humidity))
25+
print(f"{temperature:05.2f}°C {pressure:05.2f}hPa {humidity:05.2f}%")
2926
time.sleep(1)

examples/compensated-temperature.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import time
44
from subprocess import PIPE, Popen
55

6-
from bme280 import BME280
6+
from smbus2 import SMBus
77

8-
try:
9-
from smbus2 import SMBus
10-
except ImportError:
11-
from smbus import SMBus
8+
from bme280 import BME280
129

1310
print(
1411
"""compensated-temperature.py - Use the CPU temperature to compensate temperature
@@ -49,6 +46,6 @@ def get_cpu_temperature():
4946
raw_temp = bme280.get_temperature()
5047
comp_temp = raw_temp - ((smoothed_cpu_temp - raw_temp) / factor)
5148

52-
print("Compensated temperature: {:05.2f} *C".format(comp_temp))
49+
print(f"Raw: {raw_temp:05.2f}°C, Compensated: {comp_temp:05.2f}°C")
5350

5451
time.sleep(1.0)

examples/dump-calibration.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env python
22

3-
try:
4-
from smbus2 import SMBus
5-
except ImportError:
6-
from smbus import SMBus
3+
4+
from smbus2 import SMBus
5+
76
from bme280 import BME280
87

98
print(
@@ -21,4 +20,4 @@
2120
for key in dir(bme280.calibration):
2221
if key.startswith("dig_"):
2322
value = getattr(bme280.calibration, key)
24-
print("{} = {}".format(key, value))
23+
print(f"{key} = {value}")

examples/local_altitude.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import time
44

5-
try:
6-
from smbus2 import SMBus
7-
except ImportError:
8-
from smbus import SMBus
5+
from smbus2 import SMBus
6+
97
from bme280 import BME280
108

119
print(
@@ -22,10 +20,20 @@
2220

2321
# asks the user for their local QNH value and confirms it
2422
local_qnh = input(
25-
"""Please enter your local QNH value.
26-
You can find this by searching for a local METAR on the internet.
23+
"""Please enter your local QNH value (air pressure at the mean sea level).
24+
25+
You can find this by searching for a local METAR report,
26+
eg: "Cambridge METAR"
27+
28+
And looking for the number prefixed with a "Q",
29+
eg: Q1015
2730
>"""
2831
)
32+
33+
# remove a Q prefix if there is one
34+
if local_qnh.startswith("Q") or local_qnh.startswith("q"):
35+
local_qnh = local_qnh[1:]
36+
2937
print("You have told us the QNH is", local_qnh)
3038

3139
# converts the input into a floating point number
@@ -39,5 +47,5 @@
3947

4048
while True:
4149
altitude = bme280.get_altitude(qnh=local_qnh)
42-
print(round(altitude), "metres above sea level")
50+
print(f"{altitude:0.0f} metres above sea level")
4351
time.sleep(2)

examples/relative-altitude.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import time
44

5-
try:
6-
from smbus2 import SMBus
7-
except ImportError:
8-
from smbus import SMBus
5+
from smbus2 import SMBus
6+
97
from bme280 import BME280
108

119
print(
@@ -23,7 +21,7 @@
2321
baseline_values = []
2422
baseline_size = 100
2523

26-
print("Collecting baseline values for {:d} seconds. Do not move the sensor!\n".format(baseline_size))
24+
print(f"Collecting baseline values for {baseline_size:d} seconds. Do not move the sensor!\n")
2725

2826
# Collect some values to calculate a baseline pressure
2927
for i in range(baseline_size):
@@ -36,5 +34,5 @@
3634

3735
while True:
3836
altitude = bme280.get_altitude(qnh=baseline)
39-
print("Relative altitude: {:05.2f} metres".format(altitude))
37+
print(f"Relative altitude: {altitude:05.2f} metres")
4038
time.sleep(1)

examples/temperature-compare.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import time
44

5-
try:
6-
from smbus2 import SMBus
7-
except ImportError:
8-
from smbus import SMBus
5+
from smbus2 import SMBus
96

107
from bme280 import BME280
118

@@ -33,5 +30,5 @@
3330
while True:
3431
temperatureA = bme280A.get_temperature()
3532
temperatureB = bme280B.get_temperature()
36-
print("Forced: {:05.2f}*C Normal: {:05.2f}*C D: {:05.2f}".format(temperatureA, temperatureB, abs(temperatureA - temperatureB)))
33+
print(f"Forced: {temperatureA:05.2f}°C Normal: {temperatureB:05.2f}°C D: {abs(temperatureA - temperatureB):05.2f}°C")
3734
time.sleep(1)

examples/temperature-forced-mode.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import time
44

5-
try:
6-
from smbus2 import SMBus
7-
except ImportError:
8-
from smbus import SMBus
5+
from smbus2 import SMBus
96

107
from bme280 import BME280
118

@@ -21,5 +18,5 @@
2118

2219
while True:
2320
temperature = bme280.get_temperature()
24-
print("{:05.2f}*C".format(temperature))
21+
print(f"{temperature:05.2f}°C")
2522
time.sleep(1)

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@ ignore = [
115115
[tool.pimoroni]
116116
apt_packages = []
117117
configtxt = []
118-
commands = []
118+
commands = [
119+
"printf \"Setting up i2c...\n\"",
120+
"sudo raspi-config nonint do_i2c 0"
121+
]

setup.cfg

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)