Compare commits
3 Commits
f69ae9eed2
...
b4003246a8
Author | SHA1 | Date |
---|---|---|
|
b4003246a8 | |
|
4ba46b8331 | |
|
4bbf387f4f |
|
@ -18,6 +18,7 @@ try:
|
|||
except KeyError:
|
||||
is_mock = False
|
||||
|
||||
print("controller start")
|
||||
process = None
|
||||
def start_process():
|
||||
global process
|
||||
|
@ -136,10 +137,11 @@ class Humidifier:
|
|||
|
||||
# the wiring's a little different so the thresholds for detecting on/off are inverted but hopefully a lot more reliable than the original
|
||||
class HumidifierV2:
|
||||
def __init__(self):
|
||||
def __init__(self, toggle_cmd=b"i"):
|
||||
self.on_threshold = 1.5
|
||||
self.off_threshold = 2.5
|
||||
self.toggle_cooldown = 7
|
||||
self.toggle_command = toggle_cmd
|
||||
|
||||
self._on = False
|
||||
self.history = np.zeros(10)
|
||||
|
@ -179,7 +181,7 @@ class HumidifierV2:
|
|||
|
||||
def toggle(self, s):
|
||||
if time.time() > self.switch_timeout:
|
||||
s.write(b"i")
|
||||
s.write(self.toggle_command)
|
||||
s.flush()
|
||||
self.switch_timeout = time.time() + self.toggle_cooldown
|
||||
|
||||
|
@ -189,6 +191,7 @@ class Controller:
|
|||
self.target_lower = 85
|
||||
self.target_upper = 90
|
||||
self.feedforward_coeff = 50
|
||||
self.last_toggle = 0
|
||||
|
||||
self._manual_mode = False
|
||||
self.manual_on = False
|
||||
|
@ -207,6 +210,11 @@ class Controller:
|
|||
self._manual_mode = on
|
||||
send_update({"status": {"manual_mode": on}})
|
||||
|
||||
def toggle_checked(self, humidifier, s):
|
||||
if time.time() - self.last_toggle > 0.8:
|
||||
humidifier.toggle(s)
|
||||
self.last_toggle = time.time()
|
||||
|
||||
def update(self, humidifier, humidifier2, humidity):
|
||||
if self.first_sample:
|
||||
self.humidifier_history[:] = humidity
|
||||
|
@ -223,24 +231,29 @@ class Controller:
|
|||
if self.manual_mode and time.time() > self.manual_timeout:
|
||||
self.manual_mode = False
|
||||
|
||||
# TODO add in support for manual control of second humidifier
|
||||
if self.manual_mode:
|
||||
if humidifier.off and self.manual_on:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
elif humidifier.on and not self.manual_on:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
if humidifier2.off and self.manual_on:
|
||||
self.toggle_checked(humidifier2, s)
|
||||
elif humidifier2.on and not self.manual_on:
|
||||
self.toggle_checked(humidifier2, s)
|
||||
else:
|
||||
if comp_humidity < self.target_lower:
|
||||
if humidifier.off:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
if humidifier2.off:
|
||||
humidifier2.toggle(s)
|
||||
self.toggle_checked(humidifier2, s)
|
||||
elif comp_humidity > self.target_upper:
|
||||
if humidifier.on:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
if humidifier2.on:
|
||||
humidifier2.toggle(s)
|
||||
self.toggle_checked(humidifier2, s)
|
||||
|
||||
humidifier = Humidifier()
|
||||
humidifier = HumidifierV2(b"n")
|
||||
humidifier2 = HumidifierV2()
|
||||
controller = Controller()
|
||||
|
||||
|
|
Loading…
Reference in New Issue