fix gpio read

This commit is contained in:
Nicolò Balzarotti 2023-01-05 15:47:31 +01:00
parent b75b306726
commit bd96ca95a6
1 changed files with 9 additions and 1 deletions

View File

@ -28,9 +28,17 @@ class GPIOState(Sensor):
def __init__(self, pin, transform=lambda x: 1-x): def __init__(self, pin, transform=lambda x: 1-x):
self.pin = pin self.pin = pin
self.transform = transform self.transform = transform
self.value = GPIO.input(self.pin)
self.update_time()
def update_time(self):
self.time = perf_counter()
def read(self): def read(self):
return self.transform(GPIO.input(self.pin)) self.value = GPIO.input(self.pin)
return (self.time, self.transform(self.value))
class Temperature1W(Sensor): class Temperature1W(Sensor):
def __init__(self, address): def __init__(self, address):