Refactored some classes into separate files in lib/
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2026-09-12 17:25:55 -04:00
parent 31c7f870e0
commit 2768616be4
6 changed files with 228 additions and 230 deletions
+36
View File
@@ -0,0 +1,36 @@
import time
class SHT41:
DEFAULT_ADDR = 0x44
CMD_MEASURE_HIGH_PRECISION = 0xFD
def __init__(self, i2c, addr=DEFAULT_ADDR):
self.i2c = i2c
self.addr = addr
# Soft reset
self.i2c.writeto(self.addr, b"\x94")
time.sleep(0.01)
def read_values(self):
# Trigger high precision measurement
self.i2c.writeto(self.addr, bytes([self.CMD_MEASURE_HIGH_PRECISION]))
# Conversion takes up to 8.2ms
time.sleep(0.01)
# 6 bytes: [Temp_MSB, Temp_LSB, CRC, Hum_MSB, Hum_LSB, CRC]
data = self.i2c.readfrom(self.addr, 6)
raw_t = (data[0] << 8) | data[1]
raw_h = (data[3] << 8) | data[4]
# Sensirion SHT4x conversion equations
temp = -45.0 + 175.0 * (raw_t / 65535.0)
hum = -6.0 + 125.0 * (raw_h / 65535.0)
hum = max(0.0, min(hum, 100.0))
return {
"temperature": round(temp, 2),
"humidity": round(hum, 2),
"pressure": None,
}