diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..306f58e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/kuukar/kuukar_config.py b/kuukar/kuukar_config.py index 9ee47be..258ae1d 100644 --- a/kuukar/kuukar_config.py +++ b/kuukar/kuukar_config.py @@ -36,4 +36,4 @@ LIGHT_ANALOG_PIN = 0 DHT22_PIN = 5 -SERIAL_LCD = "/dev/serial/by-id/..." +SERIAL_LCD = "COM9" diff --git a/kuukar/kuukar_environment.py b/kuukar/kuukar_environment.py index 683f44e..0e80edc 100644 --- a/kuukar/kuukar_environment.py +++ b/kuukar/kuukar_environment.py @@ -34,4 +34,4 @@ class environment: self.leds.set_headlights(True) else: self.leds.set_headlights(False) - sleep(1) \ No newline at end of file + sleep(1) \ No newline at end of file diff --git a/kuukar/kuukar_lcd.py b/kuukar/kuukar_lcd.py index 21afecd..1c4dae2 100644 --- a/kuukar/kuukar_lcd.py +++ b/kuukar/kuukar_lcd.py @@ -1,7 +1,9 @@ +from time import sleep 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") def play_video(self,filename: str) -> None: diff --git a/kuukar/kuukar_nextion.py b/kuukar/kuukar_nextion.py index 58c4876..8b97379 100644 --- a/kuukar/kuukar_nextion.py +++ b/kuukar/kuukar_nextion.py @@ -2,7 +2,7 @@ import binascii from time import sleep import serial import threading -from kuukar_config import SERIAL_LCD +from kuukar.kuukar_config import SERIAL_LCD DATATYPE_NUMBER = '71' DATATYPE_STRING = '70' @@ -15,9 +15,11 @@ EVENT_TOUCH = '65' class nextion: __commands_output_buffer__ = [] + allow_serial_read = True def __init__(self) -> None: - self.device = serial.Serial(SERIAL_LCD, baudrate=19200, timeout=5) + self.device = serial.Serial(SERIAL_LCD, baudrate=9600, timeout=15) + print(self.device.is_open) self.__send_stop_bit() self.reset_device() threading.Thread(target=self.__serial_reader).start() @@ -28,9 +30,11 @@ class nextion: self.__commands_output_buffer__.append(command) def __serial_writer__(self): - if len(self.__commands_output_buffer__) > 0: - self.device.write(self.__commands_output_buffer__.pop(0)) - self.__send_stop_bit() + while True: + if len(self.__commands_output_buffer__) > 0: + self.device.write(self.__commands_output_buffer__.pop(0)) + self.__send_stop_bit() + sleep(0.05) def reset_device(self): self.send_command("rest") @@ -55,9 +59,10 @@ class nextion: def read_serial(self) -> list: ser = self.device - data = ser.read_until(self.get_stop_bit()) + data = ser.read_until(self.__get_stop_bit()) data = data[0:len(data)-3] data: list = data.hex('/').split('/') + print(data) return data def handle_serial(self, data: list): @@ -69,9 +74,13 @@ class nextion: page = int(data.pop(0), 16) component_id = int(data.pop(0), 16) press_type = data.pop(0) + self.external_touch_handler(page,component_id,press_type) print("Got a touch event at page "+str(page)+" in component "+str(component_id) + " with type "+str(press_type)) + def external_touch_handler(self, page, component_id, press_type): + # To be overridden + pass def get_attribute(self, attribute: str): self.allow_serial_read = False self.send_command("get "+str(attribute)) diff --git a/lcd_test.py b/lcd_test.py new file mode 100644 index 0000000..5bd6177 --- /dev/null +++ b/lcd_test.py @@ -0,0 +1,4 @@ +import kuukar.kuukar_lcd as kuukar_lcd +from time import sleep +lcd = kuukar_lcd.lcd() +lcd.play_video("keke_hurt") \ No newline at end of file