Add adjust_to_sea_pressure function

Now describe_pressure() gives meaningful insights if you set the altitude
pull/491/head
btmask 2022-08-09 23:52:51 +02:00
rodzic 82756a3fc9
commit 3cfac2787b
1 zmienionych plików z 18 dodań i 0 usunięć

Wyświetl plik

@ -22,6 +22,9 @@ TEMPERATURE_OFFSET = 3
BRIGHTNESS = 0.8
# change this to adjust pressure based on your altitude
altitude = 0
# light the LED red if the gas reading is less than 50%
GAS_ALERT = 0.5
@ -46,6 +49,18 @@ def graphic_equaliser():
led.set_rgb(0, ms, 0)
def adjust_to_sea_pressure(pressure_hpa, temperature, altitude):
"""
Adjust pressure based on your altitude.
credits to @cubapp https://gist.github.com/cubapp/23dd4e91814a995b8ff06f406679abcf
"""
# Adjusted-to-the-sea barometric pressure
adjusted_hpa = pressure_hpa + ((pressure_hpa * 9.80665 * altitude) / (287 * (273 + temperature + (altitude / 400))))
return adjusted_hpa
def describe_pressure(pressure_hpa):
"""Convert pressure into barometer-type description."""
if pressure_hpa < 970:
@ -213,6 +228,9 @@ while True:
# convert pressure into hpa
pressure_hpa = pressure / 100
# correct pressure
pressure_hpa = adjust_to_sea_pressure(pressure_hpa, corrected_temperature, altitude)
# read LTR559
ltr_reading = ltr.get_reading()
lux = ltr_reading[BreakoutLTR559.LUX]