fix gpio read
This commit is contained in:
parent
b75b306726
commit
bd96ca95a6
10
sensors.py
10
sensors.py
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue