implement screen updator

This commit is contained in:
Siwat Sirichai 2022-11-04 22:34:50 +07:00
parent cca77561b2
commit 59be6810ee
1 changed files with 16 additions and 2 deletions

View File

@ -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)