add experimental watchdog for input driver

This commit is contained in:
chrys 2017-06-23 02:15:59 +02:00
parent a476e730c4
commit b822d39b9a
3 changed files with 49 additions and 16 deletions

View File

@ -20,13 +20,14 @@ class eventManager():
self.cleanEventQueue()
def initialize(self, environment):
self.env = environment
self.addSimpleEventThread(fenrirEventType.HeartBeat, self.timerProcess)
self.addSimpleEventThread(fenrirEventType.HeartBeat, self.heartBeatTimer)
def shutdown(self):
self.terminateAllProcesses()
self.cleanEventQueue()
def timerProcess(self):
def heartBeatTimer(self):
try:
time.sleep(1.3)
time.sleep(0.3)
print('bin auch da')
except:
pass
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
@ -87,14 +88,21 @@ class eventManager():
if Force:
self._mainLoopRunning.value = 0
self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
def addCustomEventThread(self, function):
def addCustomEventThread(self, function, pargs = None, multiprocess=False):
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)
t.start()
def addSimpleEventThread(self, event, function):
def addSimpleEventThread(self, event, function, pargs = None, multiprocess=False, runOnce = False):
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)
t.start()
def cleanEventQueue(self):
@ -110,18 +118,21 @@ class eventManager():
return False
self._eventQueue.put({"Type":event,"Data":data})
return True
def customEventWorkerThread(self, eventQueue, function):
def customEventWorkerThread(self, eventQueue, function, args):
#if not isinstance(eventQueue, Queue):
# return
if not callable(function):
return
while self.isMainEventLoopRunning():
try:
function(eventQueue)
if args:
function(eventQueue, args)
else:
function(eventQueue)
except Exception as e:
print(e)
def simpleEventWorkerThread(self, event, function, runOnce = False):
def simpleEventWorkerThread(self, event, function, args, runOnce = False):
if not isinstance(event, fenrirEventType):
return
if not callable(function):
@ -129,10 +140,14 @@ class eventManager():
while self.isMainEventLoopRunning():
Data = None
try:
Data = function()
if args != None:
Data = function(args)
else:
Data = function()
except Exception as e:
pass
#print(e)
print(e)
self.putToEventQueue(event, Data)
print('jo')
if runOnce:
break

View File

@ -15,12 +15,16 @@ except Exception as e:
import time
from select import select
import multiprocessing
from core.eventData import fenrirEventType
from core import inputData
from core import debug
class driver():
def __init__(self):
self._manager = multiprocessing.Manager()
self.iDevices = {}
self.iDevicesFD = None
self.uDevices = {}
self.iDeviceNo = 0
self._initialized = False
@ -33,16 +37,24 @@ class driver():
global _evdevAvailableError
self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR)
return
self.updateInputDevices()
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, self.iDevicesFD)
def shutdown(self):
if not self._initialized:
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):
if not self.hasIDevices():
time.sleep(0.008) # dont flood CPU
return None
event = None
r, w, x = select(self.iDevices, [], [], 0)
r, w, x = select(self.iDevices, [], [], 0.0001)
if r != []:
for fd in r:
try:
@ -145,6 +157,12 @@ class driver():
self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
except Exception as e:
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())
def mapEvent(self, event):

View File

@ -98,7 +98,7 @@ class driver():
self.env['screen']['autoIgnoreScreens'] = []
def updateWatchdog(self,eventQueue):
print('init updateWatchdog')
print('init VCSA updateWatchdog')
currScreen = '2'
vcsa = {}
for i in range(1,7):