Seperate serial thread
This commit is contained in:
27
main.py
27
main.py
@@ -5,6 +5,26 @@ import serial
|
||||
import threading
|
||||
import json
|
||||
from bottle import route, run
|
||||
import time
|
||||
|
||||
class SerialWriter(threading.Thread):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.lock = threading.Lock()
|
||||
self.data = b"\x00"*config.ScreenX*config.ScreenY*3
|
||||
|
||||
def setData(self, data):
|
||||
with self.lock:
|
||||
self.data = data
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
ser = serial.Serial(config.Serial)
|
||||
while True:
|
||||
ser.write(b"\01")
|
||||
ser.write(self.data)
|
||||
time.sleep(1/120)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +36,8 @@ class AppRunner(threading.Thread):
|
||||
self.app = None
|
||||
self.lock = threading.Lock()
|
||||
self.param = ""
|
||||
self.serial = SerialWriter()
|
||||
self.serial.start()
|
||||
|
||||
def requestApp(self, app, param=""):
|
||||
with self.lock:
|
||||
@@ -41,8 +63,9 @@ class AppRunner(threading.Thread):
|
||||
oshandle = d.fileno()
|
||||
data = os.read(oshandle, config.ScreenX*config.ScreenY*3)
|
||||
# data = d.raw.read(config.ScreenX*config.ScreenY*3)
|
||||
ser.write(b"\01")
|
||||
ser.write(data)
|
||||
#ser.write(b"\01")
|
||||
#ser.write(data)
|
||||
self.serial.setData(data)
|
||||
|
||||
|
||||
runner = AppRunner()
|
||||
|
Reference in New Issue
Block a user