WIP move key detection to watchdog

This commit is contained in:
chrys 2018-03-06 22:14:05 +00:00
parent 4c2c8b83e4
commit 35fb684627
7 changed files with 79 additions and 109 deletions

View File

@ -124,7 +124,7 @@ driver=vcsaDriver
encoding=auto encoding=auto
screenUpdateDelay=0.05 screenUpdateDelay=0.05
suspendingScreen= suspendingScreen=
autodetectSuspendingScreen=True autodetectSuspendingScreen=False
[keyboard] [keyboard]
driver=evdevDriver driver=evdevDriver

0
src/fenrir/core/eventData.py Executable file → Normal file
View File

View File

@ -49,18 +49,21 @@ class fenrirManager():
self.environment['runtime']['eventManager'].startMainEventLoop() self.environment['runtime']['eventManager'].startMainEventLoop()
self.shutdown() self.shutdown()
def handleInput(self, event): def handleInput(self, event):
#startTime = time.time() #startTime = time.time
eventReceived = self.environment['runtime']['inputManager'].getInputEvent() if not event['Data']:
event['Data'] = self.environment['runtime']['inputManager'].getInputEvent()
if event['Data']:
event['Data']['EventName'] = self.environment['runtime']['inputManager'].convertEventName(event['Data']['EventName'])
self.environment['runtime']['inputManager'].handleInputEvent(event['Data'])
if self.environment['runtime']['inputManager'].noKeyPressed(): if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['inputManager'].clearLastDeepInput() self.environment['runtime']['inputManager'].clearLastDeepInput()
if eventReceived: if True:
if self.environment['runtime']['screenManager'].isSuspendingScreen(): if self.environment['runtime']['screenManager'].isSuspendingScreen():
self.environment['runtime']['inputManager'].writeEventBuffer() self.environment['runtime']['inputManager'].writeEventBuffer()
else: else:
if self.environment['runtime']['helpManager'].isTutorialMode(): if self.environment['runtime']['helpManager'].isTutorialMode():
self.environment['runtime']['inputManager'].clearEventBuffer() self.environment['runtime']['inputManager'].clearEventBuffer()
print('detect')
self.detectCommand() self.detectCommand()
if self.modifierInput: if self.modifierInput:
@ -82,6 +85,7 @@ class fenrirManager():
if event['Data'] == '': if event['Data'] == '':
return return
command = event['Data'] command = event['Data']
print('fire',command)
if self.environment['runtime']['helpManager'].isTutorialMode(): if self.environment['runtime']['helpManager'].isTutorialMode():
if self.environment['runtime']['commandManager'].commandExists( command, 'help'): if self.environment['runtime']['commandManager'].commandExists( command, 'help'):
self.environment['runtime']['commandManager'].executeCommand( command, 'help') self.environment['runtime']['commandManager'].executeCommand( command, 'help')
@ -143,10 +147,10 @@ class fenrirManager():
if self.environment['runtime']['inputManager'].isKeyPress(): if self.environment['runtime']['inputManager'].isKeyPress():
if self.command != '': if self.command != '':
self.singleKeyCommand = True self.singleKeyCommand = True
print(self.singleKeyCommand,self.modifierInput)
if not (self.singleKeyCommand or self.modifierInput): if not (self.singleKeyCommand or self.modifierInput):
return return
print(self.command,1)
# fire event # fire event
if self.command != '': if self.command != '':
if self.modifierInput: if self.modifierInput:
@ -157,6 +161,7 @@ class fenrirManager():
if self.environment['runtime']['inputManager'].noKeyPressed(): if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
self.command = '' self.command = ''
print(self.command,2)
def shutdownRequest(self): def shutdownRequest(self):
try: try:
self.environment['runtime']['eventManager'].stopMainEventLoop() self.environment['runtime']['eventManager'].stopMainEventLoop()

View File

@ -18,8 +18,11 @@ class inputDriver():
self._isInitialized = False self._isInitialized = False
def getInputEvent(self): def getInputEvent(self):
time.sleep(0.05) time.sleep(0.05)
if not self._initialized:
return None return None
def handleInputEvent(self, event):
time.sleep(0.05)
if not self._initialized:
return
def writeEventBuffer(self): def writeEventBuffer(self):
if not self._initialized: if not self._initialized:
return return

View File

@ -27,26 +27,27 @@ class inputManager():
def shutdown(self): def shutdown(self):
self.removeAllDevices() self.removeAllDevices()
self.env['runtime']['settingsManager'].shutdownDriver('inputDriver') self.env['runtime']['settingsManager'].shutdownDriver('inputDriver')
def getInputEvent(self): def getInputEvent(self):
eventReceived = False return self.env['runtime']['inputDriver'].getInputEvent()
mEvent = self.env['runtime']['inputDriver'].getInputEvent() def handleInputEvent(self, eventData):
if mEvent: if not eventData:
mEvent['EventName'] = self.convertEventName(mEvent['EventName']) return
eventReceived = True print(self.env['input']['currInput'])
print(eventData['EventState'])
self.env['input']['prevInput'] = self.env['input']['currInput'].copy() self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
if mEvent['EventState'] == 0: if eventData['EventState'] == 0:
if mEvent['EventName'] in self.env['input']['currInput']: if eventData['EventName'] in self.env['input']['currInput']:
self.env['input']['currInput'].remove(mEvent['EventName']) self.env['input']['currInput'].remove(eventData['EventName'])
if len(self.env['input']['currInput']) > 1: if len(self.env['input']['currInput']) > 1:
self.env['input']['currInput'] = sorted(self.env['input']['currInput']) self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
elif len(self.env['input']['currInput']) == 0: elif len(self.env['input']['currInput']) == 0:
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.setLedState = self.handleLedStates(mEvent) self.setLedState = self.handleLedStates(eventData)
self.lastInputTime = time.time() self.lastInputTime = time.time()
elif mEvent['EventState'] == 1: elif eventData['EventState'] == 1:
if not mEvent['EventName'] in self.env['input']['currInput']: if not eventData['EventName'] in self.env['input']['currInput']:
self.env['input']['currInput'].append(mEvent['EventName']) if not eventData['EventName'] == 'KEY_RESERVED':
self.env['input']['currInput'].append(eventData['EventName'])
if len(self.env['input']['currInput']) > 1: if len(self.env['input']['currInput']) > 1:
self.env['input']['currInput'] = sorted(self.env['input']['currInput']) self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
if len(self.lastDeepestInput) < len(self.env['input']['currInput']): if len(self.lastDeepestInput) < len(self.env['input']['currInput']):
@ -56,9 +57,9 @@ class inputManager():
self.env['input']['shortcutRepeat'] += 1 self.env['input']['shortcutRepeat'] += 1
else: else:
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.setLedState = self.handleLedStates(mEvent) self.setLedState = self.handleLedStates(eventData)
self.lastInputTime = time.time() self.lastInputTime = time.time()
elif mEvent['EventState'] == 2: elif eventData['EventState'] == 2:
self.lastInputTime = time.time() self.lastInputTime = time.time()
else: else:
pass pass
@ -72,7 +73,6 @@ class inputManager():
if self.noKeyPressed(): if self.noKeyPressed():
self.env['input']['prevInput'] = [] self.env['input']['prevInput'] = []
self.setLedState = True self.setLedState = True
return eventReceived
def handleLedStates(self, mEvent): def handleLedStates(self, mEvent):
if not self.setLedState: if not self.setLedState:

View File

@ -11,8 +11,3 @@ from core.inputDriver import inputDriver
class driver(inputDriver): class driver(inputDriver):
def __init__(self): def __init__(self):
inputDriver.__init__(self) inputDriver.__init__(self)
def getInputEvent(self):
time.sleep(0.1)
if not self._initialized:
return None

View File

@ -12,6 +12,7 @@ try:
import evdev import evdev
from evdev import InputDevice, UInput from evdev import InputDevice, UInput
_evdevAvailable = True _evdevAvailable = True
except Exception as e: except Exception as e:
_evdevAvailableError = str(e) _evdevAvailableError = str(e)
@ -54,7 +55,7 @@ class driver(inputDriver):
self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev) self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev)
else: else:
self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer) self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer)
self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, {'dev':self.iDevicesFD}) self.env['runtime']['processManager'].addCustomEventThread(self.inputWatchdog)
def plugInputDeviceWatchdogUdev(self,active , eventQueue): def plugInputDeviceWatchdogUdev(self,active , eventQueue):
context = pyudev.Context() context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context) monitor = pyudev.Monitor.from_netlink(context)
@ -65,66 +66,31 @@ class driver(inputDriver):
if devices: if devices:
while monitor.poll(0.5): while monitor.poll(0.5):
time.sleep(0.08) time.sleep(0.08)
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None}) #eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None})
return time.time() return time.time()
def plugInputDeviceWatchdogTimer(self, active): def plugInputDeviceWatchdogTimer(self, active):
time.sleep(2.5) time.sleep(2.5)
return time.time() return time.time()
def inputWatchdog(self,active , params): def inputWatchdog(self,active , eventQueue):
try: while active.value:
while self.watchDog.value == 0: r, w, x = select(self.iDevices, [], [], 0.5)
if active.value == 0:
return
time.sleep(0.01)
r = []
while r == []:
if active.value == 0:
return
r, w, x = select(list(params['dev']), [], [], 0.5)
self.watchDog.value = 0
except:
pass
def getInputEvent(self):
if not self.hasIDevices():
self.watchDog.value = 1
return None
event = None
r, w, x = select(self.iDevices, [], [], 0.00001)
if r != []:
for fd in r: for fd in r:
event = None
try: try:
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
currMapEvent = self.mapEvent(event)
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])
eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent})
except: except:
self.removeDevice(fd) self.removeDevice(fd)
self.watchDog.value = 1
return None def handleInputEvent(self, event):
foreward = False if not event:
while(event): print('skip')
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) return
if event.type == evdev.events.EV_KEY:
if event.code != 0:
currMapEvent = self.mapEvent(event)
if not currMapEvent:
foreward = True
event = self.iDevices[fd].read_one()
continue
if not isinstance(currMapEvent['EventName'], str):
foreward = True
event = self.iDevices[fd].read_one()
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]:
foreward = True
event = self.iDevices[fd].read_one()
if foreward: if foreward:
self.writeEventBuffer() self.writeEventBuffer()
self.clearEventBuffer() self.clearEventBuffer()
self.watchDog.value = 1
return None
def writeEventBuffer(self): def writeEventBuffer(self):
if not self._initialized: if not self._initialized:
@ -224,6 +190,7 @@ class driver(inputDriver):
mEvent['EventSec'] = event.sec mEvent['EventSec'] = event.sec
mEvent['EventUsec'] = event.usec mEvent['EventUsec'] = event.usec
mEvent['EventState'] = event.value mEvent['EventState'] = event.value
mEvent['EventType'] = event.type
return mEvent return mEvent
except Exception as e: except Exception as e:
return None return None