From 59be6810ee273dbfa8cd7283510825fd8a407beb Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Fri, 4 Nov 2022 22:34:50 +0700 Subject: [PATCH] implement screen updator --- kuukar/kuukar_lcd.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kuukar/kuukar_lcd.py b/kuukar/kuukar_lcd.py index dfb9427..bed2bd1 100644 --- a/kuukar/kuukar_lcd.py +++ b/kuukar/kuukar_lcd.py @@ -3,15 +3,20 @@ from socket import gethostname, gethostbyname import kuukar.kuukar_nextion as kuukar_nextion import kuukar.kuukar_motion as kuukar_motion import kuukar.kuukar_sensors as kuukar_sensors +from threading import Thread class lcd: def __init__(self, motion: kuukar_motion.motion, sensors: kuukar_sensors.sensors) -> None: self.nextion = kuukar_nextion.nextion() + self.motion = motion + self.sensors = sensors sleep(1) self.nextion.send_command("page home") - self.nextion.send_command("ipTXT.txt=\"" + str(gethostbyname(gethostname())) + "\"") + self.nextion.send_command( + "ipTXT.txt=\"" + str(gethostbyname(gethostname())) + "\"") self.nextion.external_touch_handler = self.touch_handler + Thread(target=self._sensor_screen_updator).start() def play_video(self, filename: str) -> None: self.nextion.send_command("page video_player") @@ -44,4 +49,13 @@ class lcd: print(f"Setting speed to {speed} and turn angle to {turn}") def _sensor_screen_updator(self): - pass + while True: + self.nextion.send_command( + f"tempTXT.txt=\"{self.sensors.get_temperature()} C\"") + self.nextion.send_command( + f"humidityTXT.txt=\"{self.sensors.get_humidity_pct()}%\"") + self.nextion.send_command( + f"brightnessTXT.txt=\"{self.sensors.get_brightness_pct()}\"") + self.nextion.send_command( + f"sonarTXT.txt=\"{int(self.sensors.sonar_get_distance(0))} / {int(self.sensors.sonar_get_distance(1))} / {int(self.sensors.sonar_get_distance(2))}\"") + sleep(1)