From d475fdc1aa6e0f4e18a81c224e95bfb03391fd85 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 27 Feb 2017 17:20:16 +0100 Subject: [PATCH] Create detectDevices.py --- play zone/detectDevices.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 play zone/detectDevices.py diff --git a/play zone/detectDevices.py b/play zone/detectDevices.py new file mode 100644 index 00000000..a99e94cf --- /dev/null +++ b/play zone/detectDevices.py @@ -0,0 +1,39 @@ +#!/bin/python +iDevices = {} +def updateInputDevices(): + deviceFileList = evdev.list_devices() + mode = 'ALL' + iDevicesFiles = [] + for device in iDevices: + iDevicesFiles.append(iDevices[device].fn) + print(len(iDevicesFiles),len(deviceFileList)) + 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) + 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': + iDevices[currDevice.fd] = currDevice + print('Device added:' + iDevices[currDevice.fd].name) + elif mode == 'NOMICE': + if not ((2 in cap) or (3 in cap)): + iDevices[currDevice.fd] = currDevice + print('Device added:' + iDevices[currDevice.fd].name) + elif currDevice.name.upper() in mode.split(','): + iDevices[currDevice.fd] = currDevice + print('Device added:' + iDevices[currDevice.fd].name) + except Exception as e: + print("Skip Inputdevice : " + deviceFile +' ' + str(e))