Skip to content

Commit 8e8a175

Browse files
authored
Merge pull request #9 from caternuson/iss8
Add altitude property
2 parents a627119 + a2ec35b commit 8e8a175

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

adafruit_dps310.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DPS310.git"
4646

4747
# Common imports; remove if unused or pylint will complain
48+
import math
4849
from time import sleep
4950
import adafruit_bus_device.i2c_device as i2c_device
5051
from adafruit_register.i2c_struct import UnaryStruct, ROUnaryStruct
@@ -234,6 +235,8 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
234235
1040384,
235236
2088960,
236237
)
238+
self.sea_level_pressure = 1013.25
239+
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
237240
self.initialize()
238241

239242
def initialize(self):
@@ -301,6 +304,12 @@ def pressure(self):
301304
final_pressure = pres_calc / 100
302305
return final_pressure
303306

307+
@property
308+
def altitude(self):
309+
"""The altitude based on the sea level pressure (`sea_level_pressure`) - which you must
310+
enter ahead of time)"""
311+
return 44330 * (1.0 - math.pow(self.pressure / self.sea_level_pressure, 0.1903))
312+
304313
@property
305314
def temperature(self):
306315
"""The current temperature reading in degrees C"""

0 commit comments

Comments
 (0)