add experimental watchdog for input driver
This commit is contained in:
parent
a476e730c4
commit
b822d39b9a
@ -20,13 +20,14 @@ class eventManager():
|
|||||||
self.cleanEventQueue()
|
self.cleanEventQueue()
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.addSimpleEventThread(fenrirEventType.HeartBeat, self.timerProcess)
|
self.addSimpleEventThread(fenrirEventType.HeartBeat, self.heartBeatTimer)
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.terminateAllProcesses()
|
self.terminateAllProcesses()
|
||||||
self.cleanEventQueue()
|
self.cleanEventQueue()
|
||||||
def timerProcess(self):
|
def heartBeatTimer(self):
|
||||||
try:
|
try:
|
||||||
time.sleep(1.3)
|
time.sleep(0.3)
|
||||||
|
print('bin auch da')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
|
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
|
||||||
@ -87,14 +88,21 @@ class eventManager():
|
|||||||
if Force:
|
if Force:
|
||||||
self._mainLoopRunning.value = 0
|
self._mainLoopRunning.value = 0
|
||||||
self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||||
def addCustomEventThread(self, function):
|
def addCustomEventThread(self, function, pargs = None, multiprocess=False):
|
||||||
self._mainLoopRunning.value = 1
|
self._mainLoopRunning.value = 1
|
||||||
t = Process(target=self.customEventWorkerThread, args=(self._eventQueue, function))
|
|
||||||
|
if multiprocess:
|
||||||
|
t = Process(target=self.customEventWorkerThread, args=(self._eventQueue, function, pargs))
|
||||||
|
else:# thread not implemented yet
|
||||||
|
t = Process(target=self.customEventWorkerThread, args=(self._eventQueue, function, pargs))
|
||||||
self._eventProcesses.append(t)
|
self._eventProcesses.append(t)
|
||||||
t.start()
|
t.start()
|
||||||
def addSimpleEventThread(self, event, function):
|
def addSimpleEventThread(self, event, function, pargs = None, multiprocess=False, runOnce = False):
|
||||||
self._mainLoopRunning.value = 1
|
self._mainLoopRunning.value = 1
|
||||||
t = Process(target=self.simpleEventWorkerThread, args=(event, function))
|
if multiprocess:
|
||||||
|
t = Process(target=self.simpleEventWorkerThread, args=(event, function, pargs))
|
||||||
|
else:# thread not implemented yet
|
||||||
|
t = Process(target=self.simpleEventWorkerThread, args=(event, function, pargs))
|
||||||
self._eventProcesses.append(t)
|
self._eventProcesses.append(t)
|
||||||
t.start()
|
t.start()
|
||||||
def cleanEventQueue(self):
|
def cleanEventQueue(self):
|
||||||
@ -110,18 +118,21 @@ class eventManager():
|
|||||||
return False
|
return False
|
||||||
self._eventQueue.put({"Type":event,"Data":data})
|
self._eventQueue.put({"Type":event,"Data":data})
|
||||||
return True
|
return True
|
||||||
def customEventWorkerThread(self, eventQueue, function):
|
def customEventWorkerThread(self, eventQueue, function, args):
|
||||||
#if not isinstance(eventQueue, Queue):
|
#if not isinstance(eventQueue, Queue):
|
||||||
# return
|
# return
|
||||||
if not callable(function):
|
if not callable(function):
|
||||||
return
|
return
|
||||||
while self.isMainEventLoopRunning():
|
while self.isMainEventLoopRunning():
|
||||||
try:
|
try:
|
||||||
function(eventQueue)
|
if args:
|
||||||
|
function(eventQueue, args)
|
||||||
|
else:
|
||||||
|
function(eventQueue)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def simpleEventWorkerThread(self, event, function, runOnce = False):
|
def simpleEventWorkerThread(self, event, function, args, runOnce = False):
|
||||||
if not isinstance(event, fenrirEventType):
|
if not isinstance(event, fenrirEventType):
|
||||||
return
|
return
|
||||||
if not callable(function):
|
if not callable(function):
|
||||||
@ -129,10 +140,14 @@ class eventManager():
|
|||||||
while self.isMainEventLoopRunning():
|
while self.isMainEventLoopRunning():
|
||||||
Data = None
|
Data = None
|
||||||
try:
|
try:
|
||||||
Data = function()
|
if args != None:
|
||||||
|
Data = function(args)
|
||||||
|
else:
|
||||||
|
Data = function()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
#print(e)
|
print(e)
|
||||||
self.putToEventQueue(event, Data)
|
self.putToEventQueue(event, Data)
|
||||||
|
print('jo')
|
||||||
if runOnce:
|
if runOnce:
|
||||||
break
|
break
|
||||||
|
@ -15,12 +15,16 @@ except Exception as e:
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
from select import select
|
from select import select
|
||||||
|
import multiprocessing
|
||||||
|
from core.eventData import fenrirEventType
|
||||||
from core import inputData
|
from core import inputData
|
||||||
from core import debug
|
from core import debug
|
||||||
|
|
||||||
class driver():
|
class driver():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self._manager = multiprocessing.Manager()
|
||||||
self.iDevices = {}
|
self.iDevices = {}
|
||||||
|
self.iDevicesFD = None
|
||||||
self.uDevices = {}
|
self.uDevices = {}
|
||||||
self.iDeviceNo = 0
|
self.iDeviceNo = 0
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
@ -33,16 +37,24 @@ class driver():
|
|||||||
global _evdevAvailableError
|
global _evdevAvailableError
|
||||||
self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR)
|
||||||
return
|
return
|
||||||
|
self.updateInputDevices()
|
||||||
|
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, self.iDevicesFD)
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
|
def inputWatchdog(self, iDevicesFD):
|
||||||
|
deviceFd = []
|
||||||
|
for fd in iDevicesFD:
|
||||||
|
deviceFd.append(fd)
|
||||||
|
print('select', deviceFd, iDevicesFD)
|
||||||
|
r, w, x = select(deviceFd, [], [], 3)
|
||||||
|
time.sleep(0.1)
|
||||||
def getInputEvent(self):
|
def getInputEvent(self):
|
||||||
if not self.hasIDevices():
|
if not self.hasIDevices():
|
||||||
time.sleep(0.008) # dont flood CPU
|
time.sleep(0.008) # dont flood CPU
|
||||||
return None
|
return None
|
||||||
event = None
|
event = None
|
||||||
r, w, x = select(self.iDevices, [], [], 0)
|
r, w, x = select(self.iDevices, [], [], 0.0001)
|
||||||
if r != []:
|
if r != []:
|
||||||
for fd in r:
|
for fd in r:
|
||||||
try:
|
try:
|
||||||
@ -145,6 +157,12 @@ class driver():
|
|||||||
self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut("Skip Inputdevice : " + deviceFile +' ' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut("Skip Inputdevice : " + deviceFile +' ' + str(e),debug.debugLevel.ERROR)
|
||||||
|
self.iDevicesFD = multiprocessing.Array('i', len(self.iDevices))
|
||||||
|
i = 0
|
||||||
|
for fd in self.iDevices:
|
||||||
|
self.iDevicesFD[i] = fd
|
||||||
|
i +=1
|
||||||
|
print(self.iDevicesFD[:])
|
||||||
self.iDeviceNo = len(evdev.list_devices())
|
self.iDeviceNo = len(evdev.list_devices())
|
||||||
|
|
||||||
def mapEvent(self, event):
|
def mapEvent(self, event):
|
||||||
|
@ -98,7 +98,7 @@ class driver():
|
|||||||
self.env['screen']['autoIgnoreScreens'] = []
|
self.env['screen']['autoIgnoreScreens'] = []
|
||||||
|
|
||||||
def updateWatchdog(self,eventQueue):
|
def updateWatchdog(self,eventQueue):
|
||||||
print('init updateWatchdog')
|
print('init VCSA updateWatchdog')
|
||||||
currScreen = '2'
|
currScreen = '2'
|
||||||
vcsa = {}
|
vcsa = {}
|
||||||
for i in range(1,7):
|
for i in range(1,7):
|
||||||
|
Loading…
Reference in New Issue
Block a user