Skip to content

Add Altitude Setter #39

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 4 commits into from
May 30, 2023
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
5 changes: 5 additions & 0 deletions adafruit_bmp280.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ def altitude(self) -> float:
p = self.pressure # in Si units for hPascal
return 44330 * (1.0 - math.pow(p / self.sea_level_pressure, 0.1903))

@altitude.setter
def altitude(self, value: float) -> None:
p = self.pressure # in Si units for hPascal
self.sea_level_pressure = p / math.pow(1.0 - value / 44330.0, 5.255)

####################### Internal helpers ################################
def _read_coefficients(self) -> None:
"""Read & save the calibration coefficients"""
Expand Down