Skip to content

Add altitude property #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions adafruit_dps310.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DPS310.git"

# Common imports; remove if unused or pylint will complain
import math
from time import sleep
import adafruit_bus_device.i2c_device as i2c_device
from adafruit_register.i2c_struct import UnaryStruct, ROUnaryStruct
Expand Down Expand Up @@ -234,6 +235,8 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
1040384,
2088960,
)
self.sea_level_pressure = 1013.25
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
self.initialize()

def initialize(self):
Expand Down Expand Up @@ -301,6 +304,12 @@ def pressure(self):
final_pressure = pres_calc / 100
return final_pressure

@property
def altitude(self):
"""The altitude based on the sea level pressure (`sea_level_pressure`) - which you must
enter ahead of time)"""
return 44330 * (1.0 - math.pow(self.pressure / self.sea_level_pressure, 0.1903))

@property
def temperature(self):
"""The current temperature reading in degrees C"""
Expand Down