sync select in evdev
This commit is contained in:
parent
b822d39b9a
commit
3037ad36e0
@ -16,10 +16,14 @@ except Exception as e:
|
||||
import time
|
||||
from select import select
|
||||
import multiprocessing
|
||||
from multiprocessing.sharedctypes import Value
|
||||
from ctypes import c_bool
|
||||
|
||||
from core.eventData import fenrirEventType
|
||||
from core import inputData
|
||||
from core import debug
|
||||
|
||||
|
||||
class driver():
|
||||
def __init__(self):
|
||||
self._manager = multiprocessing.Manager()
|
||||
@ -28,7 +32,7 @@ class driver():
|
||||
self.uDevices = {}
|
||||
self.iDeviceNo = 0
|
||||
self._initialized = False
|
||||
|
||||
self.watchDog = Value(c_bool, True)
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
global _evdevAvailable
|
||||
@ -38,7 +42,7 @@ class driver():
|
||||
self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR)
|
||||
return
|
||||
self.updateInputDevices()
|
||||
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, self.iDevicesFD)
|
||||
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, {'dev':self.iDevicesFD, 'syn':self.watchDog})
|
||||
def shutdown(self):
|
||||
if not self._initialized:
|
||||
return
|
||||
@ -46,12 +50,14 @@ class driver():
|
||||
deviceFd = []
|
||||
for fd in iDevicesFD:
|
||||
deviceFd.append(fd)
|
||||
print('select', deviceFd, iDevicesFD)
|
||||
while self.watchDog.value == 1:
|
||||
time.sleep(0.01)
|
||||
r, w, x = select(deviceFd, [], [], 3)
|
||||
time.sleep(0.1)
|
||||
self.watchDog.value = 0
|
||||
def getInputEvent(self):
|
||||
if not self.hasIDevices():
|
||||
time.sleep(0.008) # dont flood CPU
|
||||
self.watchDog.value = 1
|
||||
return None
|
||||
event = None
|
||||
r, w, x = select(self.iDevices, [], [], 0.0001)
|
||||
@ -61,6 +67,7 @@ class driver():
|
||||
event = self.iDevices[fd].read_one()
|
||||
except:
|
||||
self.removeDevice(fd)
|
||||
self.watchDog.value = 1
|
||||
return None
|
||||
foreward = False
|
||||
while(event):
|
||||
@ -78,6 +85,7 @@ class driver():
|
||||
continue
|
||||
if not foreward:
|
||||
if currMapEvent['EventState'] in [0,1,2]:
|
||||
self.watchDog.value = 1
|
||||
return currMapEvent
|
||||
else:
|
||||
if not event.type in [0,1,4]:
|
||||
@ -86,6 +94,7 @@ class driver():
|
||||
if foreward:
|
||||
self.writeEventBuffer()
|
||||
self.clearEventBuffer()
|
||||
self.watchDog.value = 1
|
||||
return None
|
||||
|
||||
def writeEventBuffer(self):
|
||||
|
Loading…
Reference in New Issue
Block a user