lpcmanager

5ccb381c307c
LPCBus: Device bus init was not repeatable across stop/start.

In case init happens multiple time, explicit POSIX initialization calls has to be used instead of static initializers.
from svghmi.svghmi import SVGHMI, SVGHMILibrary, paths
import os
from LPCArch import GetLPCProduct, SVG_GOT_modules
# set default values so that COG browser is managed by SVGHMI
SVGHMI.XSD = """<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="SVGHMI">
<xsd:complexType>
<xsd:attribute name="OnStart" type="xsd:string" use="optional" default="{LPCBrowserStart}"/>
<xsd:attribute name="OnStop" type="xsd:string" use="optional" default="{LPCBrowserStop}"/>
<xsd:attribute name="Portrait" type="xsd:boolean" use="optional" default="false"/>
<xsd:attribute name="Rotate180" type="xsd:boolean" use="optional" default="false"/>
<xsd:attribute name="EnableWatchdog" type="xsd:boolean" use="optional" default="true"/>
<xsd:attribute name="OnWatchdog" type="xsd:string" use="optional" default="{LPCBrowserRestart}"/>
<xsd:attribute name="WatchdogInitial" use="optional" default="30">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="600"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="WatchdogInterval" use="optional" default="10">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="60"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Port" type="xsd:integer" use="optional" default="8008"/>
<xsd:attribute name="Interface" type="xsd:string" use="optional" default="localhost"/>
<xsd:attribute name="Path" type="xsd:string" use="optional" default="{name}"/>
<xsd:attribute name="MaxConnections" use="optional" default="4">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="16"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
"""
old_get_SVGHMI_options = SVGHMI.get_SVGHMI_options
product = GetLPCProduct()
def get_SVGHMI_options(self):
svghmi_options = old_get_SVGHMI_options(self)
if product in SVG_GOT_modules:
portrait = self.GetParamsAttributes("SVGHMI.Portrait")["value"]
rotate180 = self.GetParamsAttributes("SVGHMI.Rotate180")["value"]
eglfs_angle,touch_angle = {
(False,False): ("0","0"),
(False,True): ("90","90"),
(True,False): ("180","180"),
(True,True): ("-90","270")}[(rotate180,portrait)]
# When we were using EVDEV, this was how rotation was done:
# 'QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=rotate=' + touch_angle + \
browser_commandline = ('TSLIB_CONFFILE=/etc/ts_' + touch_angle + ".conf" +
' QT_QPA_EGLFS_ROTATION=' + eglfs_angle +
' qt_webenginewidgets_minimal' +
# JavaScript VM optimization for small memory
' --js-flags="--max_old_space_size=16 --gc_interval=100 --optimize_for_size"' +
# Flags to enable all possible GPU acceleration
' --ignore-gpu-blacklist --enable-gpu-rasterization' +
' --enable-hardware-overlays=single-fullscreen' +
' --enable-gpu-memory-buffer-video-frames' +
' --disable-gpu-sandbox --enable-native-gpu-memory-buffers' +
' --enable-oop-rasterization --enable-zero-copy' +
# Avoid security bloat since serving local HMI
' --single-process' +
' --no-sandbox "' + svghmi_options["url"] + '"')
svghmi_options.update(
{"LPCBrowserStart": "sh -c '"+browser_commandline+"'",
"LPCBrowserStartDebug": "sh -c '"+browser_commandline+" --remote-debugging-port=9988"+"'",
"LPCBrowserStop": "killall qt_webenginewidgets_minimal",
"LPCBrowserRestart": "echo 'Restarting browser'"})
else:
svghmi_options.update(
{"LPCBrowserStart": "",
"LPCBrowserStop": "",
"LPCBrowserRestart": ""})
return svghmi_options
SVGHMI.get_SVGHMI_options = get_SVGHMI_options
def getDefaultSVG(self):
ScriptDirectory = paths.AbsDir(__file__)
portrait = self.GetParamsAttributes("SVGHMI.Portrait")["value"]
return os.path.join(ScriptDirectory, "portrait.svg" if portrait else "landscape.svg")
SVGHMI.getDefaultSVG = getDefaultSVG
old_Generate_C = SVGHMILibrary.Generate_C
def Generate_C(self, *args, **kwargs):
already_found_browser_launch = False
for CTNChild in self.GetCTR().IterChildren():
if isinstance(CTNChild, SVGHMI):
# spot browser launch abuse
if CTNChild.GetParamsAttributes("SVGHMI.OnStart")["value"].find("{LPCBrowserStart}") >= 0:
if already_found_browser_launch:
self.FatalError("SVGHMI: Only one HMI can launch browser")
already_found_browser_launch = True
return old_Generate_C(self, *args, **kwargs)
SVGHMILibrary.Generate_C = Generate_C