make virtual devices work

This commit is contained in:
Chrys 2019-08-21 23:26:49 +02:00
parent c517ed0a6d
commit 2da58e73ad
2 changed files with 42 additions and 41 deletions

View File

@ -1,5 +1,6 @@
1. PTY screen driver (leaves experimental state, stable now) 1. PTY screen driver (leaves experimental state, stable now)
- lot higher accuracy - lot higher accuracy
- works with "dialog" now
- a lot of performance speedup - a lot of performance speedup
- shortcuts are now recognieced more accurate - shortcuts are now recognieced more accurate
2. VCSA screen driver got support for UTF32 using /dev/vcsu (needs Linux >=4.19) 2. VCSA screen driver got support for UTF32 using /dev/vcsu (needs Linux >=4.19)

View File

@ -58,7 +58,7 @@ class driver(inputDriver):
self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev) self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev)
self.env['runtime']['processManager'].addCustomEventThread(self.inputWatchdog) self.env['runtime']['processManager'].addCustomEventThread(self.inputWatchdog)
self._initialized = True self._initialized = True
def plugInputDeviceWatchdogUdev(self,active , eventQueue): def plugInputDeviceWatchdogUdev(self,active , eventQueue):
context = pyudev.Context() context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context) monitor = pyudev.Monitor.from_netlink(context)
@ -70,24 +70,24 @@ class driver(inputDriver):
while device: while device:
self.env['runtime']['debug'].writeDebugOut('plugInputDeviceWatchdogUdev:' + str(device), debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('plugInputDeviceWatchdogUdev:' + str(device), debug.debugLevel.INFO)
try: try:
if not '/sys/devices/virtual/input/' in device.sys_path: #if not '/sys/devices/virtual/input/' in device.sys_path:
if device.device_node: if device.device_node:
validDevices.append(str(device.device_node)) validDevices.append(str(device.device_node))
except: except:
pass pass
try: try:
device = monitor.poll(0.1) device = monitor.poll(0.1)
except: except:
device = None device = None
if validDevices: if validDevices:
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":validDevices}) eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":validDevices})
return time.time() return time.time()
def inputWatchdog(self,active , eventQueue): def inputWatchdog(self,active , eventQueue):
try: try:
while active.value: while active.value:
r, w, x = select(self.iDevices, [], [], 0.8) r, w, x = select(self.iDevices, [], [], 0.8)
event = None event = None
foundKeyInSequence = False foundKeyInSequence = False
foreward = False foreward = False
eventFired = False eventFired = False
@ -134,7 +134,7 @@ class driver(inputDriver):
if self.gDevices[iDevice.fd]: if self.gDevices[iDevice.fd]:
self.writeUInput(uDevice, event) self.writeUInput(uDevice, event)
except Exception as e: except Exception as e:
pass pass
def writeUInput(self, uDevice, event): def writeUInput(self, uDevice, event):
if not self._initialized: if not self._initialized:
@ -186,9 +186,9 @@ class driver(inputDriver):
continue continue
try: try:
if currDevice.name.upper() in ['','SPEAKUP','FENRIR-UINPUT']: if currDevice.name.upper() in ['','SPEAKUP','FENRIR-UINPUT']:
continue continue
if currDevice.phys.upper() in ['','SPEAKUP']: if currDevice.phys.upper() in ['','SPEAKUP']:
continue continue
if 'BRLTTY' in currDevice.name.upper(): if 'BRLTTY' in currDevice.name.upper():
continue continue
except: except:
@ -197,25 +197,25 @@ class driver(inputDriver):
if mode in ['ALL','NOMICE']: if mode in ['ALL','NOMICE']:
if eventType.EV_KEY in cap: if eventType.EV_KEY in cap:
if 116 in cap[eventType.EV_KEY] and len(cap[eventType.EV_KEY]) < 10: if 116 in cap[eventType.EV_KEY] and len(cap[eventType.EV_KEY]) < 10:
self.env['runtime']['debug'].writeDebugOut('Device Skipped (has 116):' + currDevice.name,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device Skipped (has 116):' + currDevice.name,debug.debugLevel.INFO)
continue continue
if len(cap[eventType.EV_KEY]) < 60: if len(cap[eventType.EV_KEY]) < 60:
self.env['runtime']['debug'].writeDebugOut('Device Skipped (< 60 keys):' + currDevice.name,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device Skipped (< 60 keys):' + currDevice.name,debug.debugLevel.INFO)
continue continue
if mode == 'ALL': if mode == 'ALL':
self.addDevice(currDevice) self.addDevice(currDevice)
self.env['runtime']['debug'].writeDebugOut('Device added (ALL):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device added (ALL):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO)
elif mode == 'NOMICE': elif mode == 'NOMICE':
if not ((eventType.EV_REL in cap) or (eventType.EV_ABS in cap)): if not ((eventType.EV_REL in cap) or (eventType.EV_ABS in cap)):
self.addDevice(currDevice) self.addDevice(currDevice)
self.env['runtime']['debug'].writeDebugOut('Device added (NOMICE):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device added (NOMICE):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
else: else:
self.env['runtime']['debug'].writeDebugOut('Device Skipped (NOMICE):' + currDevice.name,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device Skipped (NOMICE):' + currDevice.name,debug.debugLevel.INFO)
else: else:
self.env['runtime']['debug'].writeDebugOut('Device Skipped (no EV_KEY):' + currDevice.name,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device Skipped (no EV_KEY):' + currDevice.name,debug.debugLevel.INFO)
elif currDevice.name.upper() in mode.split(','): elif currDevice.name.upper() in mode.split(','):
self.addDevice(currDevice) self.addDevice(currDevice)
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("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO)
self.iDeviceNo = len(evdev.list_devices()) self.iDeviceNo = len(evdev.list_devices())
@ -233,7 +233,7 @@ class driver(inputDriver):
pass pass
def mapEvent(self, event): def mapEvent(self, event):
if not self._initialized: if not self._initialized:
return None return None
if not event: if not event:
return None return None
mEvent = inputData.inputEvent mEvent = inputData.inputEvent
@ -248,31 +248,31 @@ class driver(inputDriver):
mEvent['EventName'] = mEvent['EventName'][0] mEvent['EventName'] = mEvent['EventName'][0]
mEvent['EventValue'] = event.code mEvent['EventValue'] = event.code
mEvent['EventSec'] = event.sec mEvent['EventSec'] = event.sec
mEvent['EventUsec'] = event.usec mEvent['EventUsec'] = event.usec
mEvent['EventState'] = event.value mEvent['EventState'] = event.value
mEvent['EventType'] = event.type mEvent['EventType'] = event.type
return mEvent return mEvent
except Exception as e: except Exception as e:
return None return None
def getLedState(self, led = 0): def getLedState(self, led = 0):
if not self.hasIDevices(): if not self.hasIDevices():
return False return False
# 0 = Numlock # 0 = Numlock
# 1 = Capslock # 1 = Capslock
# 2 = Rollen # 2 = Rollen
for fd, dev in self.iDevices.items(): for fd, dev in self.iDevices.items():
if led in dev.leds(): if led in dev.leds():
return True return True
return False return False
def toggleLedState(self, led = 0): def toggleLedState(self, led = 0):
if not self.hasIDevices(): if not self.hasIDevices():
return False return False
ledState = self.getLedState(led) ledState = self.getLedState(led)
for i in self.iDevices: for i in self.iDevices:
if self.gDevices[i]: if self.gDevices[i]:
# 17 LEDs # 17 LEDs
if 17 in self.iDevices[i].capabilities(): if 17 in self.iDevices[i].capabilities():
if ledState == 1: if ledState == 1:
self.iDevices[i].set_led(led , 0) self.iDevices[i].set_led(led , 0)
else: else:
@ -281,7 +281,7 @@ class driver(inputDriver):
if not self._initialized: if not self._initialized:
return return
for fd in self.iDevices: for fd in self.iDevices:
self.grabDevice(fd) self.grabDevice(fd)
def ungrabAllDevices(self): def ungrabAllDevices(self):
if not self._initialized: if not self._initialized:
@ -300,11 +300,11 @@ class driver(inputDriver):
self.uDevices[fd] = None self.uDevices[fd] = None
if self.uDevices[fd] != None: if self.uDevices[fd] != None:
return return
try: try:
self.uDevices[fd] = UInput.from_device(self.iDevices[fd], name='fenrir-uinput') self.uDevices[fd] = UInput.from_device(self.iDevices[fd], name='fenrir-uinput')
except Exception as e: except Exception as e:
try: try:
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: compat fallback: ' + str(e),debug.debugLevel.WARNING) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: compat fallback: ' + str(e),debug.debugLevel.WARNING)
dev = self.iDevices[fd] dev = self.iDevices[fd]
cap = dev.capabilities() cap = dev.capabilities()
del cap[0] del cap[0]
@ -313,12 +313,12 @@ class driver(inputDriver):
dev.name, dev.name,
) )
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR)
return return
def addDevice(self, newDevice): def addDevice(self, newDevice):
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: device added: ' + str(newDevice.fd) + ' ' +str(newDevice),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: device added: ' + str(newDevice.fd) + ' ' +str(newDevice),debug.debugLevel.INFO)
self.iDevices[newDevice.fd] = newDevice self.iDevices[newDevice.fd] = newDevice
self.gDevices[newDevice.fd] = False self.gDevices[newDevice.fd] = False
self.createUInputDev(newDevice.fd) self.createUInputDev(newDevice.fd)
def grabDevice(self, fd): def grabDevice(self, fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
@ -326,11 +326,11 @@ class driver(inputDriver):
try: try:
self.iDevices[fd].grab() self.iDevices[fd].grab()
self.gDevices[fd] = True self.gDevices[fd] = True
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO)
except IOError: except IOError:
self.gDevices[fd] = True self.gDevices[fd] = True
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR)
def ungrabDevice(self,fd): def ungrabDevice(self,fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
return return
@ -339,9 +339,9 @@ class driver(inputDriver):
self.iDevices[fd].ungrab() self.iDevices[fd].ungrab()
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: ungrab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: ungrab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO)
except: except:
pass pass
def removeDevice(self,fd): def removeDevice(self,fd):
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: device removed: ' + str(fd) + ' ' +str(self.iDevices[fd]),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: device removed: ' + str(fd) + ' ' +str(self.iDevices[fd]),debug.debugLevel.INFO)
self.clearEventBuffer() self.clearEventBuffer()
try: try:
self.ungrabDevice(fd) self.ungrabDevice(fd)