Skip to content

Commit aeefb83

Browse files
committed
add altitude property
1 parent a627119 commit aeefb83

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

adafruit_dps310.py

Lines changed: 10 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,13 @@ 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+
p = self.pressure # in Si units for hPascal
312+
return 44330 * (1.0 - math.pow(p / self.sea_level_pressure, 0.1903))
313+
304314
@property
305315
def temperature(self):
306316
"""The current temperature reading in degrees C"""

0 commit comments

Comments
 (0)