WIP move key detection to watchdog
This commit is contained in:
parent
4c2c8b83e4
commit
35fb684627
@ -124,7 +124,7 @@ driver=vcsaDriver
|
||||
encoding=auto
|
||||
screenUpdateDelay=0.05
|
||||
suspendingScreen=
|
||||
autodetectSuspendingScreen=True
|
||||
autodetectSuspendingScreen=False
|
||||
|
||||
[keyboard]
|
||||
driver=evdevDriver
|
||||
|
0
src/fenrir/core/eventData.py
Executable file → Normal file
0
src/fenrir/core/eventData.py
Executable file → Normal file
@ -49,18 +49,21 @@ class fenrirManager():
|
||||
self.environment['runtime']['eventManager'].startMainEventLoop()
|
||||
self.shutdown()
|
||||
def handleInput(self, event):
|
||||
#startTime = time.time()
|
||||
eventReceived = self.environment['runtime']['inputManager'].getInputEvent()
|
||||
#startTime = time.time
|
||||
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():
|
||||
self.environment['runtime']['inputManager'].clearLastDeepInput()
|
||||
if eventReceived:
|
||||
|
||||
if True:
|
||||
if self.environment['runtime']['screenManager'].isSuspendingScreen():
|
||||
self.environment['runtime']['inputManager'].writeEventBuffer()
|
||||
else:
|
||||
if self.environment['runtime']['helpManager'].isTutorialMode():
|
||||
self.environment['runtime']['inputManager'].clearEventBuffer()
|
||||
|
||||
print('detect')
|
||||
self.detectCommand()
|
||||
|
||||
if self.modifierInput:
|
||||
@ -82,6 +85,7 @@ class fenrirManager():
|
||||
if event['Data'] == '':
|
||||
return
|
||||
command = event['Data']
|
||||
print('fire',command)
|
||||
if self.environment['runtime']['helpManager'].isTutorialMode():
|
||||
if self.environment['runtime']['commandManager'].commandExists( command, 'help'):
|
||||
self.environment['runtime']['commandManager'].executeCommand( command, 'help')
|
||||
@ -143,10 +147,10 @@ class fenrirManager():
|
||||
if self.environment['runtime']['inputManager'].isKeyPress():
|
||||
if self.command != '':
|
||||
self.singleKeyCommand = True
|
||||
|
||||
print(self.singleKeyCommand,self.modifierInput)
|
||||
if not (self.singleKeyCommand or self.modifierInput):
|
||||
return
|
||||
|
||||
print(self.command,1)
|
||||
# fire event
|
||||
if self.command != '':
|
||||
if self.modifierInput:
|
||||
@ -157,6 +161,7 @@ class fenrirManager():
|
||||
if self.environment['runtime']['inputManager'].noKeyPressed():
|
||||
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
|
||||
self.command = ''
|
||||
print(self.command,2)
|
||||
def shutdownRequest(self):
|
||||
try:
|
||||
self.environment['runtime']['eventManager'].stopMainEventLoop()
|
||||
|
@ -18,8 +18,11 @@ class inputDriver():
|
||||
self._isInitialized = False
|
||||
def getInputEvent(self):
|
||||
time.sleep(0.05)
|
||||
if not self._initialized:
|
||||
return None
|
||||
def handleInputEvent(self, event):
|
||||
time.sleep(0.05)
|
||||
if not self._initialized:
|
||||
return
|
||||
def writeEventBuffer(self):
|
||||
if not self._initialized:
|
||||
return
|
||||
|
@ -27,26 +27,27 @@ class inputManager():
|
||||
def shutdown(self):
|
||||
self.removeAllDevices()
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('inputDriver')
|
||||
|
||||
def getInputEvent(self):
|
||||
eventReceived = False
|
||||
mEvent = self.env['runtime']['inputDriver'].getInputEvent()
|
||||
if mEvent:
|
||||
mEvent['EventName'] = self.convertEventName(mEvent['EventName'])
|
||||
eventReceived = True
|
||||
return self.env['runtime']['inputDriver'].getInputEvent()
|
||||
def handleInputEvent(self, eventData):
|
||||
if not eventData:
|
||||
return
|
||||
print(self.env['input']['currInput'])
|
||||
print(eventData['EventState'])
|
||||
self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
|
||||
if mEvent['EventState'] == 0:
|
||||
if mEvent['EventName'] in self.env['input']['currInput']:
|
||||
self.env['input']['currInput'].remove(mEvent['EventName'])
|
||||
if eventData['EventState'] == 0:
|
||||
if eventData['EventName'] in self.env['input']['currInput']:
|
||||
self.env['input']['currInput'].remove(eventData['EventName'])
|
||||
if len(self.env['input']['currInput']) > 1:
|
||||
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
||||
elif len(self.env['input']['currInput']) == 0:
|
||||
self.env['input']['shortcutRepeat'] = 1
|
||||
self.setLedState = self.handleLedStates(mEvent)
|
||||
self.setLedState = self.handleLedStates(eventData)
|
||||
self.lastInputTime = time.time()
|
||||
elif mEvent['EventState'] == 1:
|
||||
if not mEvent['EventName'] in self.env['input']['currInput']:
|
||||
self.env['input']['currInput'].append(mEvent['EventName'])
|
||||
elif eventData['EventState'] == 1:
|
||||
if not eventData['EventName'] in self.env['input']['currInput']:
|
||||
if not eventData['EventName'] == 'KEY_RESERVED':
|
||||
self.env['input']['currInput'].append(eventData['EventName'])
|
||||
if len(self.env['input']['currInput']) > 1:
|
||||
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
||||
if len(self.lastDeepestInput) < len(self.env['input']['currInput']):
|
||||
@ -56,9 +57,9 @@ class inputManager():
|
||||
self.env['input']['shortcutRepeat'] += 1
|
||||
else:
|
||||
self.env['input']['shortcutRepeat'] = 1
|
||||
self.setLedState = self.handleLedStates(mEvent)
|
||||
self.setLedState = self.handleLedStates(eventData)
|
||||
self.lastInputTime = time.time()
|
||||
elif mEvent['EventState'] == 2:
|
||||
elif eventData['EventState'] == 2:
|
||||
self.lastInputTime = time.time()
|
||||
else:
|
||||
pass
|
||||
@ -72,7 +73,6 @@ class inputManager():
|
||||
if self.noKeyPressed():
|
||||
self.env['input']['prevInput'] = []
|
||||
self.setLedState = True
|
||||
return eventReceived
|
||||
|
||||
def handleLedStates(self, mEvent):
|
||||
if not self.setLedState:
|
||||
|
@ -11,8 +11,3 @@ from core.inputDriver import inputDriver
|
||||
class driver(inputDriver):
|
||||
def __init__(self):
|
||||
inputDriver.__init__(self)
|
||||
|
||||
def getInputEvent(self):
|
||||
time.sleep(0.1)
|
||||
if not self._initialized:
|
||||
return None
|
||||
|
@ -12,6 +12,7 @@ try:
|
||||
import evdev
|
||||
from evdev import InputDevice, UInput
|
||||
_evdevAvailable = True
|
||||
|
||||
except Exception as e:
|
||||
_evdevAvailableError = str(e)
|
||||
|
||||
@ -54,7 +55,7 @@ class driver(inputDriver):
|
||||
self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev)
|
||||
else:
|
||||
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):
|
||||
context = pyudev.Context()
|
||||
monitor = pyudev.Monitor.from_netlink(context)
|
||||
@ -65,66 +66,31 @@ class driver(inputDriver):
|
||||
if devices:
|
||||
while monitor.poll(0.5):
|
||||
time.sleep(0.08)
|
||||
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None})
|
||||
#eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None})
|
||||
return time.time()
|
||||
def plugInputDeviceWatchdogTimer(self, active):
|
||||
time.sleep(2.5)
|
||||
return time.time()
|
||||
def inputWatchdog(self,active , params):
|
||||
try:
|
||||
while self.watchDog.value == 0:
|
||||
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 != []:
|
||||
def inputWatchdog(self,active , eventQueue):
|
||||
while active.value:
|
||||
r, w, x = select(self.iDevices, [], [], 0.5)
|
||||
for fd in r:
|
||||
event = None
|
||||
try:
|
||||
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:
|
||||
self.removeDevice(fd)
|
||||
self.watchDog.value = 1
|
||||
return None
|
||||
foreward = False
|
||||
while(event):
|
||||
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])
|
||||
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()
|
||||
|
||||
def handleInputEvent(self, event):
|
||||
if not event:
|
||||
print('skip')
|
||||
return
|
||||
if foreward:
|
||||
self.writeEventBuffer()
|
||||
self.clearEventBuffer()
|
||||
self.watchDog.value = 1
|
||||
return None
|
||||
|
||||
def writeEventBuffer(self):
|
||||
if not self._initialized:
|
||||
@ -224,6 +190,7 @@ class driver(inputDriver):
|
||||
mEvent['EventSec'] = event.sec
|
||||
mEvent['EventUsec'] = event.usec
|
||||
mEvent['EventState'] = event.value
|
||||
mEvent['EventType'] = event.type
|
||||
return mEvent
|
||||
except Exception as e:
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user