bme280*.py: Clamp the humidity results in the range 0-100 %.

The sensor may deliver values slightly out of range.

Signed-off-by: robert-hh <robert@hammelrath.com>
master
robert-hh 2024-02-07 14:15:23 +01:00
rodzic f1e555b2cd
commit 6c0b723039
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 32EC5F755D5A3A93
2 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -201,7 +201,10 @@ class BME280:
(self.dig_H2 / 65536.0 * (1.0 + self.dig_H6 / 67108864.0 * h *
(1.0 + self.dig_H3 / 67108864.0 * h))))
humidity = h * (1.0 - self.dig_H1 * h / 524288.0)
# humidity = max(0, min(100, humidity))
if (humidity < 0):
humidity = 0
if (humidity > 100):
humidity = 100.0
if result:
result[0] = temp

Wyświetl plik

@ -207,6 +207,10 @@ class BME280:
h = 0 if h < 0 else h
h = 419430400 if h > 419430400 else h
humidity = h >> 12
if humidity < 0:
humidity = 0
if humidity > 100 * 1024:
humidity = 100 * 1024
if result:
result[0] = temp