From 5847a8658c4b0212be3dad6ede5ee53a69298f89 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 2 Aug 2017 22:35:03 +0200 Subject: [PATCH] more work on device detection still WIP --- .../onPlugInputDevice/50000-UpdateDevices.py | 3 +-- src/fenrir/core/commandManager.py | 7 ++++--- src/fenrir/core/eventManager.py | 2 +- src/fenrir/core/fenrirManager.py | 4 ++-- src/fenrir/inputDriver/evdevDriver.py | 19 +++++++++---------- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/fenrir/commands/onPlugInputDevice/50000-UpdateDevices.py b/src/fenrir/commands/onPlugInputDevice/50000-UpdateDevices.py index ffd26e6a..37a392ed 100755 --- a/src/fenrir/commands/onPlugInputDevice/50000-UpdateDevices.py +++ b/src/fenrir/commands/onPlugInputDevice/50000-UpdateDevices.py @@ -16,7 +16,6 @@ class command(): def getDescription(self): return 'No description found' def run(self): - if not self.env['runtime']['screenManager'].isSuspendingScreen(): # remove if all works - self.env['runtime']['inputManager'].updateInputDevices() + self.env['runtime']['inputManager'].updateInputDevices() def setCallback(self, callback): pass diff --git a/src/fenrir/core/commandManager.py b/src/fenrir/core/commandManager.py index 9a6060ea..10c7676e 100644 --- a/src/fenrir/core/commandManager.py +++ b/src/fenrir/core/commandManager.py @@ -163,9 +163,10 @@ class commandManager(): self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + newScript ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) - def executeDefaultTrigger(self, trigger): - if self.env['runtime']['screenManager'].isSuspendingScreen(): - return + def executeDefaultTrigger(self, trigger, force=False): + if not force: + if self.env['runtime']['screenManager'].isSuspendingScreen(): + return for command in sorted(self.env['commands'][trigger]): if self.commandExists(command, trigger): try: diff --git a/src/fenrir/core/eventManager.py b/src/fenrir/core/eventManager.py index 1861dca7..a81e1706 100644 --- a/src/fenrir/core/eventManager.py +++ b/src/fenrir/core/eventManager.py @@ -61,7 +61,7 @@ class eventManager(): elif event['Type'] == fenrirEventType.BrailleInput: pass elif event['Type'] == fenrirEventType.PlugInputDevice: - pass + self.env['runtime']['fenrirManager'].handlePlugInputDevice(event) elif event['Type'] == fenrirEventType.BrailleFlush: pass elif event['Type'] == fenrirEventType.ScreenChanged: diff --git a/src/fenrir/core/fenrirManager.py b/src/fenrir/core/fenrirManager.py index ef78c696..91695fff 100644 --- a/src/fenrir/core/fenrirManager.py +++ b/src/fenrir/core/fenrirManager.py @@ -113,10 +113,10 @@ class fenrirManager(): #print('handleScreenUpdate:',time.time() - startTime) def handlePlugInputDevice(self, event): - self.environment['runtime']['commandManager'].executeDefaultTrigger('PlugInputDevice') + self.environment['runtime']['commandManager'].executeDefaultTrigger('onPlugInputDevice', force=True) def handleHeartBeat(self, event): - self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat') + self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat',force=True) #self.environment['runtime']['outputManager'].brailleText(flush=False) def detectCommand(self): diff --git a/src/fenrir/inputDriver/evdevDriver.py b/src/fenrir/inputDriver/evdevDriver.py index 5c4a9a1d..a77e719a 100644 --- a/src/fenrir/inputDriver/evdevDriver.py +++ b/src/fenrir/inputDriver/evdevDriver.py @@ -64,9 +64,6 @@ class driver(): while active: devices = monitor.poll(2) if devices: - for device in devices: - if not active: - return print('drin') eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":''}) @@ -80,28 +77,30 @@ class driver(): return def inputWatchdog(self,active , params): deviceFd = [] - for fd in params['dev']: - deviceFd.append(fd) + print('WD:',params['dev'],self.watchDog.value == 0) while self.watchDog.value == 0: if active.value == 0: return r = [] while r == []: + deviceFd = list(params['dev']) r, w, x = select(deviceFd, [], [], 2) + print('select',r, w, x) self.watchDog.value = 0 def getInputEvent(self): if not self.hasIDevices(): self.watchDog.value = 1 return None event = None - r, w, x = select(self.iDevices, [], [], 0.0001) + r, w, x = select(self.iDevices, [], [], 0.00001) + print(self.iDevices,'read',r, w, x) if r != []: for fd in r: try: event = self.iDevices[fd].read_one() except: self.removeDevice(fd) - self.watchDog.value = 1 + self.watchDog.value = 1 return None foreward = False while(event): @@ -153,7 +152,7 @@ class driver(): if init: self.removeAllDevices() deviceFileList = evdev.list_devices() - if not force: + if not force and False: if len(deviceFileList) == self.iDeviceNo: return mode = self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper() @@ -200,15 +199,15 @@ 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.updateMPiDevicesFD() self.iDeviceNo = len(evdev.list_devices()) + self.updateMPiDevicesFD() def updateMPiDevicesFD(self): for fd in self.iDevices: if not fd in self.iDevicesFD: self.iDevicesFD.append(fd) for fd in self.iDevicesFD: if not fd in self.iDevices: - self.iDevicesFD.remove(fd) + self.iDevicesFD.remove(fd) def mapEvent(self, event): if not self._initialized: return None