Seperate serial thread

This commit is contained in:
deckensteuerung 2018-08-22 18:04:04 +02:00
parent bd84098ff4
commit 647edcc2ed
2 changed files with 27 additions and 2 deletions

View File

@ -4,6 +4,8 @@ ScreenX = 24
#height
ScreenY = 40
Serial = "/dev/ttyACM0"
# first app is always running in IDLE
Apps = [
{"name": "pixelflut", "cmd": "apps/idle.py", "permanent": True},

27
main.py
View File

@ -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()