Added persistent apps
This commit is contained in:
parent
480f856913
commit
5e4c5bc24a
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
#width
|
#width
|
||||||
ScreenX = 80
|
ScreenX = 24
|
||||||
#height
|
#height
|
||||||
ScreenY = 40
|
ScreenY = 40
|
||||||
|
|
||||||
@ -13,14 +13,14 @@ NoDataTimeout = 20
|
|||||||
LogLevel = logging.DEBUG
|
LogLevel = logging.DEBUG
|
||||||
|
|
||||||
UseGui = True
|
UseGui = True
|
||||||
GuiScaleFactor = 5
|
GuiScaleFactor = 10
|
||||||
|
|
||||||
WebHost = "localhost"
|
WebHost = "localhost"
|
||||||
WebPort = 8000
|
WebPort = 8000
|
||||||
|
|
||||||
# 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", "persistent": True},
|
||||||
{"name": "framebuffer", "cmd": ["apps/fbcp", "/dev/fb0"]},
|
{"name": "framebuffer", "cmd": ["apps/fbcp", "/dev/fb0"]},
|
||||||
{"name": "fdtd", "cmd": "apps/main"},
|
{"name": "fdtd", "cmd": "apps/main"},
|
||||||
{"name": "play_youtube", "cmd": "apps/play_youtube.sh"}
|
{"name": "play_youtube", "cmd": "apps/play_youtube.sh"}
|
||||||
|
33
main.py
33
main.py
@ -145,7 +145,7 @@ class LogReader(threading.Thread):
|
|||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
class App(threading.Thread):
|
class App(threading.Thread):
|
||||||
def __init__(self, cmd, param, listener):
|
def __init__(self, cmd, param, listener, is_persistent):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
#start app
|
#start app
|
||||||
if type(cmd) != list:
|
if type(cmd) != list:
|
||||||
@ -161,6 +161,7 @@ class App(threading.Thread):
|
|||||||
self.datasource = DataSource(b"\x00"*config.ScreenX*config.ScreenY*3)
|
self.datasource = DataSource(b"\x00"*config.ScreenX*config.ScreenY*3)
|
||||||
self.running = running
|
self.running = running
|
||||||
self.listener = listener
|
self.listener = listener
|
||||||
|
self.is_persistent = is_persistent
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while running and self.running and self.alive():
|
while running and self.running and self.alive():
|
||||||
@ -195,6 +196,9 @@ class App(threading.Thread):
|
|||||||
def getLog(self):
|
def getLog(self):
|
||||||
return self.logreader.getLog()
|
return self.logreader.getLog()
|
||||||
|
|
||||||
|
def isPersistent(self):
|
||||||
|
return self.is_persistent
|
||||||
|
|
||||||
def terminateApp(self):
|
def terminateApp(self):
|
||||||
logging.error("Terminate app!")
|
logging.error("Terminate app!")
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -214,6 +218,7 @@ class AppRunner(threading.Thread):
|
|||||||
self.datasource = DataSource(b"\x00"*config.ScreenX*config.ScreenY*3)
|
self.datasource = DataSource(b"\x00"*config.ScreenX*config.ScreenY*3)
|
||||||
self.serial = SerialWriter(self.datasource)
|
self.serial = SerialWriter(self.datasource)
|
||||||
self.serial.start()
|
self.serial.start()
|
||||||
|
self.persistent_apps = {}
|
||||||
if config.UseGui:
|
if config.UseGui:
|
||||||
self.gui = Gui(self.datasource)
|
self.gui = Gui(self.datasource)
|
||||||
self.gui.start()
|
self.gui.start()
|
||||||
@ -226,14 +231,24 @@ class AppRunner(threading.Thread):
|
|||||||
logging.info("Requesting app: "+str(app))
|
logging.info("Requesting app: "+str(app))
|
||||||
|
|
||||||
def updateApp(self):
|
def updateApp(self):
|
||||||
if self.app != None:
|
if self.app != None and not self.app.isPersistent():
|
||||||
self.app.stop()
|
self.app.stop()
|
||||||
logging.info("Starting app "+config.Apps[self.requestedApp]["name"])
|
|
||||||
cmd = config.Apps[self.requestedApp]["cmd"]
|
self.currentApp = self.requestedApp
|
||||||
logging.debug(str(cmd))
|
if self.currentApp in self.persistent_apps.keys():
|
||||||
self.app = App(cmd, self.param, self.cv)
|
self.app = self.persistent_apps[self.currentApp]
|
||||||
self.app.datasource.addListener(self.cv)
|
else:
|
||||||
self.app.start()
|
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):
|
def run(self):
|
||||||
logging.info("Starting Apprunner")
|
logging.info("Starting Apprunner")
|
||||||
@ -242,7 +257,7 @@ class AppRunner(threading.Thread):
|
|||||||
if self.app == None or not self.app.alive():
|
if self.app == None or not self.app.alive():
|
||||||
self.requestedApp = 0
|
self.requestedApp = 0
|
||||||
if self.requestedApp != None:
|
if self.requestedApp != None:
|
||||||
self.currentApp = self.requestedApp
|
|
||||||
self.updateApp()
|
self.updateApp()
|
||||||
self.requestedApp = None
|
self.requestedApp = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user