kuukar-rpi/kuukar/kuukar_environment.py

37 lines
1.1 KiB
Python
Raw Normal View History

2022-10-25 15:01:26 +00:00
import threading
from time import sleep
2022-10-30 08:57:00 +00:00
from kuukar.kuukar_lcd import lcd
from kuukar.kuukar_leds import leds
from kuukar.kuukar_sensors import sensors
2022-10-25 15:01:26 +00:00
class environment:
t_alerted = False
h_alerted = False
def __init__(self, lcd: lcd, leds: leds, sensors: sensors) -> None:
self.lcd = lcd
self.leds = leds
self.sensors = sensors
2022-10-28 07:14:00 +00:00
threading.Thread(target=self.__checker).start()
2022-10-25 15:01:26 +00:00
2022-10-28 07:14:00 +00:00
def __checker(self):
2022-10-25 15:01:26 +00:00
while True:
if self.sensors.get_temperature() > 38.0:
if not self.t_alerted:
2022-10-26 08:10:08 +00:00
lcd.play_video("keke_died")
2022-10-25 15:01:26 +00:00
self.t_alerted = True
else:
self.t_alerted = False
if self.sensors.get_humidity_pct() > 60.0:
if not self.h_alerted:
2022-10-26 08:10:08 +00:00
lcd.play_video("keke_cute_noise")
2022-10-25 15:01:26 +00:00
self.h_alerted = True
else:
self.h_alerted = False
2022-10-28 07:14:00 +00:00
if self.sensors.get_brightness_pct() < 50:
self.leds.set_headlights(True)
else:
self.leds.set_headlights(False)
sleep(1)