add different code paths for events; split up mainloop;
This commit is contained in:
@@ -26,7 +26,7 @@ class eventManager():
|
||||
self.cleanEventQueue()
|
||||
def heartBeatTimer(self):
|
||||
try:
|
||||
time.sleep(8)
|
||||
time.sleep(0.5)
|
||||
except:
|
||||
pass
|
||||
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
|
||||
@@ -50,15 +50,15 @@ class eventManager():
|
||||
if event['Type'] == fenrirEventType.Ignore:
|
||||
return
|
||||
elif event['Type'] == fenrirEventType.StopMainLoop:
|
||||
self._mainLoopRunning.value = 0
|
||||
self.handleStopMainLoop()
|
||||
print('stop')
|
||||
return
|
||||
elif event['Type'] == fenrirEventType.ScreenUpdate:
|
||||
self.env['runtime']['fenrirManager'].handleProcess()
|
||||
self.env['runtime']['fenrirManager'].handleScreenUpdate()
|
||||
print(self._eventQueue.qsize())
|
||||
print('ScreenUpdate')
|
||||
elif event['Type'] == fenrirEventType.KeyboardInput:
|
||||
self.env['runtime']['fenrirManager'].handleProcess()
|
||||
self.env['runtime']['fenrirManager'].handleInput()
|
||||
print(self._eventQueue.qsize())
|
||||
print('KeyboardInput')
|
||||
elif event['Type'] == fenrirEventType.BrailleInput:
|
||||
@@ -68,11 +68,12 @@ class eventManager():
|
||||
elif event['Type'] == fenrirEventType.BrailleFlush:
|
||||
pass
|
||||
elif event['Type'] == fenrirEventType.ScreenChanged:
|
||||
self.env['runtime']['fenrirManager'].handleProcess()
|
||||
self.env['runtime']['fenrirManager'].handleScreenChange()
|
||||
print(self._eventQueue.qsize())
|
||||
print('ScreenChanged')
|
||||
elif event['Type'] == fenrirEventType.HeartBeat:
|
||||
self.env['runtime']['fenrirManager'].handleProcess()
|
||||
# run timer actions
|
||||
#self.env['runtime']['fenrirManager'].handleProcess()
|
||||
print(self._eventQueue.qsize())
|
||||
print('HeartBeat at {0} {1}'.format(event['Type'], event['Data'] ))
|
||||
|
||||
@@ -84,6 +85,9 @@ class eventManager():
|
||||
st = time.time()
|
||||
self.proceedEventLoop()
|
||||
#print('ALL loop ' + str(time.time() - st))
|
||||
def handleStopMainLoop(self):
|
||||
self._mainLoopRunning.value = 0
|
||||
time.sleep(3.5)
|
||||
def stopMainEventLoop(self, Force = False):
|
||||
if Force:
|
||||
self._mainLoopRunning.value = 0
|
||||
@@ -126,9 +130,9 @@ class eventManager():
|
||||
while self.isMainEventLoopRunning():
|
||||
try:
|
||||
if args:
|
||||
function(eventQueue, args)
|
||||
function(self._mainLoopRunning, eventQueue, args)
|
||||
else:
|
||||
function(eventQueue)
|
||||
function(self._mainLoopRunning, eventQueue)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@@ -141,7 +145,7 @@ class eventManager():
|
||||
Data = None
|
||||
try:
|
||||
if args != None:
|
||||
Data = function(args)
|
||||
Data = function(self._mainLoopRunning, args)
|
||||
else:
|
||||
Data = function()
|
||||
except Exception as e:
|
||||
|
@@ -47,15 +47,10 @@ class fenrirManager():
|
||||
if not self.initialized:
|
||||
return
|
||||
self.environment['runtime']['eventManager'].startMainEventLoop()
|
||||
|
||||
self.shutdown()
|
||||
|
||||
def handleProcess(self):
|
||||
def handleInput(self):
|
||||
eventReceived = self.environment['runtime']['inputManager'].getInputEvent()
|
||||
startTime = time.time()
|
||||
if not eventReceived:
|
||||
if not self.environment['runtime']['screenManager'].isSuspendingScreen():
|
||||
self.environment['runtime']['inputManager'].updateInputDevices()
|
||||
startTime = time.time()
|
||||
if eventReceived:
|
||||
self.prepareCommand()
|
||||
if not (self.wasCommand or self.environment['general']['tutorialMode']) or self.environment['runtime']['screenManager'].isSuspendingScreen():
|
||||
@@ -69,23 +64,39 @@ class fenrirManager():
|
||||
if self.environment['input']['keyForeward'] > 0:
|
||||
self.environment['input']['keyForeward'] -=1
|
||||
self.environment['runtime']['screenManager'].update('onInput')
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
|
||||
else:
|
||||
self.environment['runtime']['screenManager'].update('onUpdate')
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
|
||||
self.handleCommands()
|
||||
def handleScreenChange(self):
|
||||
self.environment['runtime']['screenManager'].update('onUpdate')
|
||||
|
||||
if self.environment['runtime']['applicationManager'].isApplicationChange():
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
|
||||
self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \
|
||||
self.environment['runtime']['applicationManager'].getPrevApplication(), \
|
||||
self.environment['runtime']['applicationManager'].getCurrentApplication())
|
||||
|
||||
if self.environment['runtime']['screenManager'].isScreenChange():
|
||||
if not self.environment['runtime']['screenManager'].isScreenChange():
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged')
|
||||
else:
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
|
||||
#self.environment['runtime']['outputManager'].brailleText(flush=False)
|
||||
self.handleCommands()
|
||||
#print(time.time()-startTime)
|
||||
|
||||
|
||||
def handleScreenUpdate(self):
|
||||
self.environment['runtime']['screenManager'].update('onUpdate')
|
||||
|
||||
if self.environment['runtime']['applicationManager'].isApplicationChange():
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
|
||||
self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \
|
||||
self.environment['runtime']['applicationManager'].getPrevApplication(), \
|
||||
self.environment['runtime']['applicationManager'].getCurrentApplication())
|
||||
|
||||
if not self.environment['runtime']['screenManager'].isScreenChange():
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
|
||||
def handlePlugInputDevice(self):
|
||||
if not self.environment['runtime']['screenManager'].isSuspendingScreen(): # remove if all works
|
||||
self.environment['runtime']['inputManager'].updateInputDevices()
|
||||
def handleHeartBeat(self):
|
||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat')
|
||||
self.handlePlugInputDevice()
|
||||
#self.environment['runtime']['outputManager'].brailleText(flush=False)
|
||||
|
||||
def prepareCommand(self):
|
||||
if self.environment['runtime']['screenManager'].isSuspendingScreen():
|
||||
self.wasCommand = False
|
||||
|
Reference in New Issue
Block a user