Added persistent apps

This commit is contained in:
a_voel02 2018-08-26 20:31:48 +02:00
parent 480f856913
commit 5e4c5bc24a
2 changed files with 27 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import logging
#width
ScreenX = 80
ScreenX = 24
#height
ScreenY = 40
@ -13,14 +13,14 @@ NoDataTimeout = 20
LogLevel = logging.DEBUG
UseGui = True
GuiScaleFactor = 5
GuiScaleFactor = 10
WebHost = "localhost"
WebPort = 8000
# first app is always running in IDLE
Apps = [
{"name": "pixelflut", "cmd": "apps/idle.py", "permanent": True},
{"name": "pixelflut", "cmd": "apps/idle.py", "persistent": True},
{"name": "framebuffer", "cmd": ["apps/fbcp", "/dev/fb0"]},
{"name": "fdtd", "cmd": "apps/main"},
{"name": "play_youtube", "cmd": "apps/play_youtube.sh"}

33
main.py
View File

@ -145,7 +145,7 @@ class LogReader(threading.Thread):
self.running = False
class App(threading.Thread):
def __init__(self, cmd, param, listener):
def __init__(self, cmd, param, listener, is_persistent):
super().__init__()
#start app
if type(cmd) != list:
@ -161,6 +161,7 @@ class App(threading.Thread):
self.datasource = DataSource(b"\x00"*config.ScreenX*config.ScreenY*3)
self.running = running
self.listener = listener
self.is_persistent = is_persistent
def run(self):
while running and self.running and self.alive():
@ -195,6 +196,9 @@ class App(threading.Thread):
def getLog(self):
return self.logreader.getLog()
def isPersistent(self):
return self.is_persistent
def terminateApp(self):
logging.error("Terminate app!")
self.stop()
@ -214,6 +218,7 @@ class AppRunner(threading.Thread):
self.datasource = DataSource(b"\x00"*config.ScreenX*config.ScreenY*3)
self.serial = SerialWriter(self.datasource)
self.serial.start()
self.persistent_apps = {}
if config.UseGui:
self.gui = Gui(self.datasource)
self.gui.start()
@ -226,14 +231,24 @@ class AppRunner(threading.Thread):
logging.info("Requesting app: "+str(app))
def updateApp(self):
if self.app != None:
if self.app != None and not self.app.isPersistent():
self.app.stop()
logging.info("Starting app "+config.Apps[self.requestedApp]["name"])
cmd = config.Apps[self.requestedApp]["cmd"]
logging.debug(str(cmd))
self.app = App(cmd, self.param, self.cv)
self.app.datasource.addListener(self.cv)
self.app.start()
self.currentApp = self.requestedApp
if self.currentApp in self.persistent_apps.keys():
self.app = self.persistent_apps[self.currentApp]
else:
persistent = ("persistent" in config.Apps[self.requestedApp].keys() and
config.Apps[self.requestedApp]["persistent"])
logging.info("Starting app "+config.Apps[self.requestedApp]["name"])
cmd = config.Apps[self.requestedApp]["cmd"]
logging.debug(str(cmd))
self.app = App(cmd, self.param, self.cv, is_persistent=persistent)
self.app.datasource.addListener(self.cv)
self.app.start()
if persistent:
self.persistent_apps[self.currentApp] = self.app
def run(self):
logging.info("Starting Apprunner")
@ -242,7 +257,7 @@ class AppRunner(threading.Thread):
if self.app == None or not self.app.alive():
self.requestedApp = 0
if self.requestedApp != None:
self.currentApp = self.requestedApp
self.updateApp()
self.requestedApp = None