More flexible apps

This commit is contained in:
deckensteuerung 2018-08-22 21:15:32 +02:00
parent 8b7a34956b
commit b822fb9c1c
2 changed files with 23 additions and 10 deletions

View File

@ -1,3 +1,4 @@
import logging
#width
ScreenX = 24
@ -9,12 +10,14 @@ Serial = "/dev/ttyACM0"
# kills app after some seconds if it sends no data
NoDataTimeout = 20
LogLevel = logging.DEBUG
UseGui = True
GuiScaleFactor = 10
# first app is always running in IDLE
Apps = [
{"name": "pixelflut", "cmd": "apps/idle.py", "permanent": True},
{"name": "framebuffer", "cmd": "apps/framebuffercp"},
{"name": "framebuffer", "cmd": ["apps/fbcp", "/dev/fb0"]},
{"name": "play_youtube", "cmd": "apps/play_youtube.sh"}
]

28
main.py
View File

@ -21,9 +21,11 @@ if config.UseGui:
def __init__(self):
super().__init__()
self.data = b"\x00"*config.ScreenX*config.ScreenY*3
self.lock = threading.Lock()
def setData(self, data):
self.data = data
with self.lock:
self.data = data
def run(self):
global running
@ -37,14 +39,18 @@ if config.UseGui:
logging.debug("GUI quits app")
running = False
screen.fill((0, 255, 0))
for x in range(config.ScreenX):
for y in range(config.ScreenY):
i = x+y*config.ScreenX
r = (self.data[i*3+0])
g = (self.data[i*3+1])
b = (self.data[i*3+2])
with self.lock:
try:
for x in range(config.ScreenX):
for y in range(config.ScreenY):
i = x+y*config.ScreenX
r = (self.data[i*3+0])
g = (self.data[i*3+1])
b = (self.data[i*3+2])
pygame.draw.rect(screen, (r, g, b), pygame.Rect(sf*x, sf*y, sf, sf))
pygame.draw.rect(screen, (r, g, b), pygame.Rect(sf*x, sf*y, sf, sf))
except:
pass
pygame.display.flip()
logging.info("Closing GUI")
@ -155,7 +161,11 @@ class AppRunner(threading.Thread):
if self.app != None:
self.app.terminate()
self.app.stderr.close()
args = [os.getcwd()+"/"+config.Apps[self.requestedApp]["cmd"], str(config.ScreenX), str(config.ScreenY), self.param]
cmd = config.Apps[self.requestedApp]["cmd"]
logging.debug(str(cmd))
if type(cmd) != list:
cmd = [cmd,]
args = cmd+[str(config.ScreenX), str(config.ScreenY), self.param]
self.app = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
self.logreader.clear()