basic device detection
This commit is contained in:
parent
6f9106d4a8
commit
bdaf8e61fc
@ -22,7 +22,6 @@ class inputManager():
|
|||||||
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
|
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
|
||||||
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
|
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
|
||||||
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
|
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
|
||||||
self.grabDevices()
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.env['runtime']['inputManager'].releaseDevices()
|
self.env['runtime']['inputManager'].releaseDevices()
|
||||||
|
@ -22,6 +22,7 @@ class driver():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.iDevices = {}
|
self.iDevices = {}
|
||||||
self.uDevices = {}
|
self.uDevices = {}
|
||||||
|
self.iDeviceNo = 0
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
|
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
@ -32,17 +33,16 @@ 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.getInputDevices()
|
self.updateInputDevices()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
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
|
||||||
|
self.updateInputDevices()
|
||||||
event = None
|
event = None
|
||||||
r, w, x = select(self.iDevices, [], [], self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay'))
|
r, w, x = select(self.iDevices, [], [], self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay'))
|
||||||
if r != []:
|
if r != []:
|
||||||
@ -95,31 +95,55 @@ class driver():
|
|||||||
return
|
return
|
||||||
uDevice.write_event(event)
|
uDevice.write_event(event)
|
||||||
uDevice.syn()
|
uDevice.syn()
|
||||||
def getInputDevices(self):
|
|
||||||
if not self._initialized:
|
|
||||||
return
|
|
||||||
if self.iDevices != {}:
|
|
||||||
self.releaseDevices()
|
|
||||||
deviceList = evdev.list_devices()
|
|
||||||
readableDevices = []
|
|
||||||
for dev in deviceList:
|
|
||||||
try:
|
|
||||||
open(dev)
|
|
||||||
readableDevices.append(dev)
|
|
||||||
except Exception as e:
|
|
||||||
self.env['runtime']['debug'].writeDebugOut("Skip Inputdevice : " + dev +' ' + str(e),debug.debugLevel.ERROR)
|
|
||||||
self.iDevices = map(evdev.InputDevice, (readableDevices))
|
|
||||||
|
|
||||||
# 3 pos absolute
|
def updateInputDevices(self, force = False, init = False):
|
||||||
# 2 pos relative
|
if init:
|
||||||
# 1 Keys
|
self.iDevices = {}
|
||||||
# we try to filter out mices and other stuff here
|
self.iDeviceNo = 0
|
||||||
if self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper() == 'ALL':
|
deviceFileList = evdev.list_devices()
|
||||||
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
|
if not force:
|
||||||
elif self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper() == 'NOMICE':
|
if len(deviceFileList) == self.iDeviceNo:
|
||||||
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities() and not 3 in dev.capabilities() and not 2 in dev.capabilities()}
|
return
|
||||||
else:
|
self.iDeviceNo = len(deviceFileList)
|
||||||
self.iDevices = {dev.fd: dev for dev in self.iDevices if dev.name.upper() in self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper().split(',')}
|
mode = self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper()
|
||||||
|
iDevicesFiles = []
|
||||||
|
for device in self.iDevices:
|
||||||
|
iDevicesFiles.append(self.iDevices[device].fn)
|
||||||
|
if len(iDevicesFiles) == len(deviceFileList):
|
||||||
|
return
|
||||||
|
for deviceFile in deviceFileList:
|
||||||
|
try:
|
||||||
|
if deviceFile in iDevicesFiles:
|
||||||
|
print('skip')
|
||||||
|
continue
|
||||||
|
open(deviceFile)
|
||||||
|
# 3 pos absolute
|
||||||
|
# 2 pos relative
|
||||||
|
# 1 Keys
|
||||||
|
currDevice = evdev.InputDevice(deviceFile)
|
||||||
|
if currDevice.name.upper() in ['SPEAKUP','PY-EVDEV-UINPUT']:
|
||||||
|
continue
|
||||||
|
cap = currDevice.capabilities()
|
||||||
|
if mode in ['ALL','NOMICE']:
|
||||||
|
if 1 in cap:
|
||||||
|
if 116 in cap[1] and len(cap[1]) < 5:
|
||||||
|
print('power')
|
||||||
|
continue
|
||||||
|
if mode == 'ALL':
|
||||||
|
self.iDevices[currDevice.fd] = currDevice
|
||||||
|
self.grabDevice(currDevice.fd)
|
||||||
|
print('Device added (ALL):' + self.iDevices[currDevice.fd].name)
|
||||||
|
elif mode == 'NOMICE':
|
||||||
|
if not ((2 in cap) or (3 in cap)):
|
||||||
|
self.iDevices[currDevice.fd] = currDevice
|
||||||
|
self.grabDevice(currDevice.fd)
|
||||||
|
print('Device added (NOMICE):' + self.iDevices[currDevice.fd].name)
|
||||||
|
elif currDevice.name.upper() in mode.split(','):
|
||||||
|
self.iDevices[currDevice.fd] = currDevice
|
||||||
|
self.grabDevice(currDevice.fd)
|
||||||
|
print('Device added (Name):' + self.iDevices[currDevice.fd].name)
|
||||||
|
except Exception as e:
|
||||||
|
print("Skip Inputdevice : " + deviceFile +' ' + str(e))
|
||||||
|
|
||||||
def mapEvent(self, event):
|
def mapEvent(self, event):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
@ -162,25 +186,27 @@ class driver():
|
|||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
for fd in self.iDevices:
|
for fd in self.iDevices:
|
||||||
try:
|
self.grabDevice()
|
||||||
self.uDevices[fd] = UInput.from_device(self.iDevices[fd].fn)
|
def grabDevice(self, fd):
|
||||||
except Exception as e:
|
try:
|
||||||
try:
|
self.uDevices[fd] = UInput.from_device(self.iDevices[fd].fn)
|
||||||
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: compat fallback: ' + str(e),debug.debugLevel.ERROR)
|
except Exception as e:
|
||||||
dev = self.iDevices[fd]
|
|
||||||
cap = dev.capabilities()
|
|
||||||
del cap[0]
|
|
||||||
self.uDevices[fd] = UInput(
|
|
||||||
cap,
|
|
||||||
dev.name,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR)
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
self.iDevices[fd].grab()
|
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: compat fallback: ' + str(e),debug.debugLevel.ERROR)
|
||||||
|
dev = self.iDevices[fd]
|
||||||
|
cap = dev.capabilities()
|
||||||
|
del cap[0]
|
||||||
|
self.uDevices[fd] = UInput(
|
||||||
|
cap,
|
||||||
|
dev.name,
|
||||||
|
)
|
||||||
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: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.iDevices[fd].grab()
|
||||||
|
except Exception as e:
|
||||||
|
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR)
|
||||||
# leve the old code until the new one is better tested
|
# leve the old code until the new one is better tested
|
||||||
# for fd in self.iDevices:
|
# for fd in self.iDevices:
|
||||||
# dev = self.iDevices[fd]
|
# dev = self.iDevices[fd]
|
||||||
@ -195,8 +221,9 @@ class driver():
|
|||||||
# #dev.info.bustype,
|
# #dev.info.bustype,
|
||||||
# #'/dev/uinput'
|
# #'/dev/uinput'
|
||||||
# )
|
# )
|
||||||
# dev.grab()
|
# dev.grab()
|
||||||
def removeDevice(self,fd):
|
def removeDevice(self,fd):
|
||||||
|
self.clearEventBuffer()
|
||||||
try:
|
try:
|
||||||
self.iDevices[fd].ungrab()
|
self.iDevices[fd].ungrab()
|
||||||
except:
|
except:
|
||||||
|
Loading…
Reference in New Issue
Block a user