try to fix

This commit is contained in:
Nicolò Balzarotti 2023-01-05 15:44:41 +01:00
parent 175695d512
commit b75b306726
3 changed files with 13 additions and 2 deletions

View File

@ -30,7 +30,6 @@ class GPIOPin(Actuator):
def enable(self, enable=True):
GPIO.output(self.pin, self.onstate) if enable else self.disable()
def disable(self):
GPIO.output(self.pin, self.offstate)

View File

@ -175,7 +175,7 @@ class State():
return None
def phase_time(self, arg=None):
return (self.now() - self.envdata['current-phase-loadtime'])
return (self.now() - self.envdata.get('current-phase-loadtime', 0))
def loadphase(self, phaseidx):
phase = self.recipe.phases[phaseidx]

View File

@ -4,6 +4,9 @@ from collections import deque
import re
from os.path import exists
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# TODO client: add a way to disable live plotting? server: stop
# sending data periodically to everybody!
@ -21,6 +24,14 @@ class Sensor():
return (perf_counter(),
int((random() * (1-self.auto) + self.prevval * self.auto) * 100) / 100)
class GPIOState(Sensor):
def __init__(self, pin, transform=lambda x: 1-x):
self.pin = pin
self.transform = transform
def read(self):
return self.transform(GPIO.input(self.pin))
class Temperature1W(Sensor):
def __init__(self, address):
self.measure = 'Temperature'
@ -61,6 +72,7 @@ class Sensors():
self.available_sensors = {
'T_ext': Temperature1W('28-06214252b671'),
'T_food': Temperature1W('28-062142531e5a'),
'heater': GPIOState(22),
}
def list(self):