Seperate serial thread
This commit is contained in:
parent
bd84098ff4
commit
647edcc2ed
@ -4,6 +4,8 @@ ScreenX = 24
|
|||||||
#height
|
#height
|
||||||
ScreenY = 40
|
ScreenY = 40
|
||||||
|
|
||||||
|
Serial = "/dev/ttyACM0"
|
||||||
|
|
||||||
# first app is always running in IDLE
|
# first app is always running in IDLE
|
||||||
Apps = [
|
Apps = [
|
||||||
{"name": "pixelflut", "cmd": "apps/idle.py", "permanent": True},
|
{"name": "pixelflut", "cmd": "apps/idle.py", "permanent": True},
|
||||||
|
27
main.py
27
main.py
@ -5,6 +5,26 @@ import serial
|
|||||||
import threading
|
import threading
|
||||||
import json
|
import json
|
||||||
from bottle import route, run
|
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.app = None
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.param = ""
|
self.param = ""
|
||||||
|
self.serial = SerialWriter()
|
||||||
|
self.serial.start()
|
||||||
|
|
||||||
def requestApp(self, app, param=""):
|
def requestApp(self, app, param=""):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
@ -41,8 +63,9 @@ class AppRunner(threading.Thread):
|
|||||||
oshandle = d.fileno()
|
oshandle = d.fileno()
|
||||||
data = os.read(oshandle, config.ScreenX*config.ScreenY*3)
|
data = os.read(oshandle, config.ScreenX*config.ScreenY*3)
|
||||||
# data = d.raw.read(config.ScreenX*config.ScreenY*3)
|
# data = d.raw.read(config.ScreenX*config.ScreenY*3)
|
||||||
ser.write(b"\01")
|
#ser.write(b"\01")
|
||||||
ser.write(data)
|
#ser.write(data)
|
||||||
|
self.serial.setData(data)
|
||||||
|
|
||||||
|
|
||||||
runner = AppRunner()
|
runner = AppRunner()
|
||||||
|
Loading…
Reference in New Issue
Block a user