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