add initial udev watchdog

This commit is contained in:
chrys 2017-07-02 22:03:17 +02:00
parent e47af4d30a
commit 2f259d7bf4

View File

@ -5,7 +5,9 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
_evdevAvailable = False _evdevAvailable = False
_udevAvailable = False
_evdevAvailableError = '' _evdevAvailableError = ''
_udevAvailableError = ''
try: try:
import evdev import evdev
from evdev import InputDevice, UInput from evdev import InputDevice, UInput
@ -13,6 +15,12 @@ try:
except Exception as e: except Exception as e:
_evdevAvailableError = str(e) _evdevAvailableError = str(e)
try:
import pyudev
_udevAvailable = True
except Exception as e:
_udevAvailableError = str(e)
import time import time
from select import select from select import select
import multiprocessing import multiprocessing
@ -36,17 +44,35 @@ class driver():
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
global _evdevAvailable global _evdevAvailable
global _udevAvailable
self._initialized = _evdevAvailable self._initialized = _evdevAvailable
if not self._initialized: if not self._initialized:
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.updateInputDevices() self.updateInputDevices()
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdog) if _udevAvailable:
self.env['runtime']['eventManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev)
else:
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer)
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, {'dev':self.iDevicesFD}) self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, {'dev':self.iDevicesFD})
def plugInputDeviceWatchdog(self): def plugInputDeviceWatchdogUdev(self,active , eventQueue):
time.sleep(2.5) context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.start()
while active:
devices = monitor.poll(2)
if devices:
for device in devices:
if not active:
return
print('drin')
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":''})
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay') #self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
return time.time()
def plugInputDeviceWatchdogTimer(self):
time.sleep(2.5)
return time.time() return time.time()
def shutdown(self): def shutdown(self):
if not self._initialized: if not self._initialized: