lcd working test
This commit is contained in:
parent
2e2316e471
commit
ee8cf1037d
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -36,4 +36,4 @@ LIGHT_ANALOG_PIN = 0
|
||||||
|
|
||||||
DHT22_PIN = 5
|
DHT22_PIN = 5
|
||||||
|
|
||||||
SERIAL_LCD = "/dev/serial/by-id/..."
|
SERIAL_LCD = "COM9"
|
||||||
|
|
|
@ -34,4 +34,4 @@ class environment:
|
||||||
self.leds.set_headlights(True)
|
self.leds.set_headlights(True)
|
||||||
else:
|
else:
|
||||||
self.leds.set_headlights(False)
|
self.leds.set_headlights(False)
|
||||||
sleep(1)
|
sleep(1)
|
|
@ -1,7 +1,9 @@
|
||||||
|
from time import sleep
|
||||||
import kuukar.kuukar_nextion as kuukar_nextion
|
import kuukar.kuukar_nextion as kuukar_nextion
|
||||||
class lcd:
|
class lcd:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.nextion = kuukar_nextion.nextion()
|
self.nextion = kuukar_nextion.nextion()
|
||||||
|
sleep(1)
|
||||||
self.nextion.send_command("page home")
|
self.nextion.send_command("page home")
|
||||||
|
|
||||||
def play_video(self,filename: str) -> None:
|
def play_video(self,filename: str) -> None:
|
||||||
|
|
|
@ -2,7 +2,7 @@ import binascii
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import serial
|
import serial
|
||||||
import threading
|
import threading
|
||||||
from kuukar_config import SERIAL_LCD
|
from kuukar.kuukar_config import SERIAL_LCD
|
||||||
|
|
||||||
DATATYPE_NUMBER = '71'
|
DATATYPE_NUMBER = '71'
|
||||||
DATATYPE_STRING = '70'
|
DATATYPE_STRING = '70'
|
||||||
|
@ -15,9 +15,11 @@ EVENT_TOUCH = '65'
|
||||||
class nextion:
|
class nextion:
|
||||||
|
|
||||||
__commands_output_buffer__ = []
|
__commands_output_buffer__ = []
|
||||||
|
allow_serial_read = True
|
||||||
|
|
||||||
def __init__(self) -> None:
|
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.__send_stop_bit()
|
||||||
self.reset_device()
|
self.reset_device()
|
||||||
threading.Thread(target=self.__serial_reader).start()
|
threading.Thread(target=self.__serial_reader).start()
|
||||||
|
@ -28,9 +30,11 @@ class nextion:
|
||||||
self.__commands_output_buffer__.append(command)
|
self.__commands_output_buffer__.append(command)
|
||||||
|
|
||||||
def __serial_writer__(self):
|
def __serial_writer__(self):
|
||||||
if len(self.__commands_output_buffer__) > 0:
|
while True:
|
||||||
self.device.write(self.__commands_output_buffer__.pop(0))
|
if len(self.__commands_output_buffer__) > 0:
|
||||||
self.__send_stop_bit()
|
self.device.write(self.__commands_output_buffer__.pop(0))
|
||||||
|
self.__send_stop_bit()
|
||||||
|
sleep(0.05)
|
||||||
|
|
||||||
def reset_device(self):
|
def reset_device(self):
|
||||||
self.send_command("rest")
|
self.send_command("rest")
|
||||||
|
@ -55,9 +59,10 @@ class nextion:
|
||||||
|
|
||||||
def read_serial(self) -> list:
|
def read_serial(self) -> list:
|
||||||
ser = self.device
|
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 = data[0:len(data)-3]
|
||||||
data: list = data.hex('/').split('/')
|
data: list = data.hex('/').split('/')
|
||||||
|
print(data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def handle_serial(self, data: list):
|
def handle_serial(self, data: list):
|
||||||
|
@ -69,9 +74,13 @@ class nextion:
|
||||||
page = int(data.pop(0), 16)
|
page = int(data.pop(0), 16)
|
||||||
component_id = int(data.pop(0), 16)
|
component_id = int(data.pop(0), 16)
|
||||||
press_type = data.pop(0)
|
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)
|
print("Got a touch event at page "+str(page)+" in component "+str(component_id)
|
||||||
+ " with type "+str(press_type))
|
+ " 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):
|
def get_attribute(self, attribute: str):
|
||||||
self.allow_serial_read = False
|
self.allow_serial_read = False
|
||||||
self.send_command("get "+str(attribute))
|
self.send_command("get "+str(attribute))
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
import kuukar.kuukar_lcd as kuukar_lcd
|
||||||
|
from time import sleep
|
||||||
|
lcd = kuukar_lcd.lcd()
|
||||||
|
lcd.play_video("keke_hurt")
|
Loading…
Reference in New Issue