kuukar-rpi/kuukar/kuukar_lcd.py

43 lines
1.6 KiB
Python

from time import sleep
from socket import gethostname, gethostbyname
import kuukar.kuukar_nextion as kuukar_nextion
class lcd:
def __init__(self) -> None:
self.nextion = kuukar_nextion.nextion()
sleep(1)
self.nextion.send_command("page home")
self.nextion.send_command("ipTXT.txt=\""+str(gethostbyname(gethostname()))+"\"")
self.nextion.external_touch_handler = self.touch_handler
def play_video(self, filename: str) -> None:
self.nextion.send_command("page video_player")
self.nextion.send_command("video.path=\"sd0/" + filename + ".video\"")
self.nextion.send_command("video.en=1")
def pause_video(self) -> None:
self.nextion.send_command("video.en=2")
def resume_video(self) -> None:
self.nextion.send_command("video.en=1")
def stop_video(self) -> None:
self.nextion.send_command("video.en=0")
self.nextion.send_command("page home")
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")
speed = 100-(y-60)/(205-60)*200
turn = (x-5)/(150-5)*200-100
print(f"Setting speed to {speed} and turn angle to {turn}")