kuukar-rpi/kuukar/kuukar_lcd.py

48 lines
1.9 KiB
Python
Raw Normal View History

2022-11-03 08:53:27 +00:00
from time import sleep
2022-11-03 16:49:34 +00:00
from socket import gethostname, gethostbyname
2022-10-30 08:57:00 +00:00
import kuukar.kuukar_nextion as kuukar_nextion
2022-11-04 04:58:20 +00:00
import kuukar.kuukar_motion as kuukar_motion
import kuukar.kuukar_sensors as kuukar_sensors
2022-11-03 16:49:34 +00:00
2022-10-23 06:49:59 +00:00
class lcd:
2022-11-04 04:58:20 +00:00
def __init__(self, motion: kuukar_motion.motion, sensors: kuukar_sensors.sensors) -> None:
self.nextion = kuukar_nextion.nextion()
2022-11-03 08:53:27 +00:00
sleep(1)
2022-10-26 05:44:58 +00:00
self.nextion.send_command("page home")
2022-11-04 04:58:20 +00:00
self.nextion.send_command("ipTXT.txt=\"" + str(gethostbyname(gethostname())) + "\"")
2022-11-03 16:49:34 +00:00
self.nextion.external_touch_handler = self.touch_handler
2022-10-23 06:49:59 +00:00
2022-11-03 16:49:34 +00:00
def play_video(self, filename: str) -> None:
2022-10-26 05:44:58 +00:00
self.nextion.send_command("page video_player")
2022-11-03 16:49:34 +00:00
self.nextion.send_command("video.path=\"sd0/" + filename + ".video\"")
2022-10-26 05:44:58 +00:00
self.nextion.send_command("video.en=1")
2022-10-23 06:49:59 +00:00
def pause_video(self) -> None:
2022-10-26 05:44:58 +00:00
self.nextion.send_command("video.en=2")
2022-10-23 06:49:59 +00:00
def resume_video(self) -> None:
2022-10-26 05:44:58 +00:00
self.nextion.send_command("video.en=1")
2022-10-23 06:49:59 +00:00
def stop_video(self) -> None:
2022-10-26 05:44:58 +00:00
self.nextion.send_command("video.en=0")
self.nextion.send_command("page home")
2022-11-03 16:49:34 +00:00
def touch_handler(self, page, component_id, press_type):
print(f'page:{page} cid:{component_id} pt:{press_type}')
if page == 1 and component_id == 2 and press_type == '01':
if self.nextion.get_attribute("aiTG.val"):
print("AI Drive Activated")
else:
print("AI Drive Deactivated")
elif page == 3:
if component_id == 2 and press_type == '00':
x = self.nextion.get_attribute("joystick.x")
y = self.nextion.get_attribute("joystick.y")
2022-11-04 04:58:20 +00:00
speed = 100 - (y - 60) / (205 - 60) * 200
turn = (x - 5) / (150 - 5) * 200 - 100
2022-11-03 16:49:34 +00:00
print(f"Setting speed to {speed} and turn angle to {turn}")
2022-11-04 04:58:20 +00:00
def _sensor_screen_updator(self):
pass