no empty input event; make hartbeat work; plugInputDevice trigger

This commit is contained in:
chrys 2017-06-25 21:21:06 +02:00
parent 9bee489bc7
commit e8c0109267
8 changed files with 19 additions and 57 deletions

0
src/fenrir/commands/onHeartBeat/76000-time.py Normal file → Executable file
View File

View File

@ -28,35 +28,3 @@ commandInfo = {
'lastCommandExecutionTime': time.time(),
'lastCommandRequestTime': time.time(),
}
# used by the commandManager
commands = {
'onInput':{
},
'onScreenChanged':{
},
'onScreenUpdate':{
},
'onApplicationChange':{
},
'commands':{
},
'onSwitchApplicationProfile':{
},
}
# used by the commandManager
commandsIgnore = {
'onInput':{
},
'onScreenChanged':{
},
'onScreenUpdate':{
},
'onApplicationChange':{
},
'commands':{
},
'onSwitchApplicationProfile':{
},
}

View File

@ -15,6 +15,8 @@ class commandManager():
def initialize(self, environment):
self.env = environment
# commands
self.env['commands'] = {}
self.env['commandsIgnore'] = {}
for commandFolder in self.env['general']['commandFolderList']:
self.env['runtime']['commandManager'].loadCommands(commandFolder,
self.env['runtime']['settingsManager'].getSetting('general', 'commandPath'))
@ -42,7 +44,8 @@ class commandManager():
if not os.access(commandFolder, os.R_OK):
self.env['runtime']['debug'].writeDebugOut("commandFolder not readable:" + commandFolder ,debug.debugLevel.ERROR)
return
self.env['commands'][section] = {}
self.env['commandsIgnore'][section] = {}
commandList = glob.glob(commandFolder+'*')
for command in commandList:
try:
@ -62,7 +65,6 @@ class commandManager():
self.env['commands'][section][fileName.upper()].initialize(self.env)
self.env['runtime']['debug'].writeDebugOut("Load command:" + section + "." + fileName.upper() ,debug.debugLevel.INFO, onAnyLevel=True)
except Exception as e:
print(command+str(e))
self.env['runtime']['debug'].writeDebugOut("Loading command:" + command ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
continue
@ -172,8 +174,7 @@ class commandManager():
self.env['runtime']['debug'].writeDebugOut("Executing trigger.command:" + trigger + "." + command ,debug.debugLevel.INFO)
self.env['commands'][trigger][command].run()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + command ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + command + str(e) ,debug.debugLevel.ERROR)
def executeCommand(self, command, section = 'commands'):
if self.env['runtime']['screenManager'].isSuspendingScreen():

View File

@ -19,8 +19,6 @@ environment = {
'runtime': runtimeData,
'general': generalData,
'settings': settingsData,
'commands': commandData.commands,
'commandsIgnore': commandData.commandsIgnore,
'commandInfo': commandData.commandInfo,
'commandBuffer': commandData.commandBuffer,
'input': inputData,

View File

@ -44,23 +44,18 @@ class eventManager():
self.eventDispatcher(event)
#print('NET loop ' + str(time.time() - st))
def eventDispatcher(self, event):
print(event['Type'])
print(event['Type'], self._eventQueue.qsize())
if not event:
return
if event['Type'] == fenrirEventType.Ignore:
return
elif event['Type'] == fenrirEventType.StopMainLoop:
self.handleStopMainLoop()
print('stop')
return
elif event['Type'] == fenrirEventType.ScreenUpdate:
self.env['runtime']['fenrirManager'].handleScreenUpdate()
print(self._eventQueue.qsize())
print('ScreenUpdate')
elif event['Type'] == fenrirEventType.KeyboardInput:
self.env['runtime']['fenrirManager'].handleInput()
print(self._eventQueue.qsize())
print('KeyboardInput')
elif event['Type'] == fenrirEventType.BrailleInput:
pass
elif event['Type'] == fenrirEventType.PlugInputDevice:
@ -69,14 +64,9 @@ class eventManager():
pass
elif event['Type'] == fenrirEventType.ScreenChanged:
self.env['runtime']['fenrirManager'].handleScreenChange()
print(self._eventQueue.qsize())
print('ScreenChanged')
elif event['Type'] == fenrirEventType.HeartBeat:
# run timer actions
#self.env['runtime']['fenrirManager'].handleProcess()
print(self._eventQueue.qsize())
print('HeartBeat at {0} {1}'.format(event['Type'], event['Data'] ))
self.env['runtime']['fenrirManager'].handleHeartBeat()
#print('HeartBeat at {0} {1}'.format(event['Type'], event['Data'] ))
def isMainEventLoopRunning(self):
return self._mainLoopRunning.value == 1
def startMainEventLoop(self):

View File

@ -67,7 +67,7 @@ class fenrirManager():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
self.handleCommands()
def handleScreenChange(self):
self.environment['runtime']['screenManager'].update('onUpdate')
self.environment['runtime']['screenManager'].update('onScreenChange')
if self.environment['runtime']['applicationManager'].isApplicationChange():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
@ -90,11 +90,9 @@ class fenrirManager():
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()
self.environment['runtime']['commandManager'].executeDefaultTrigger('PlugInputDevice')
def handleHeartBeat(self):
self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat')
self.handlePlugInputDevice()
#self.environment['runtime']['outputManager'].brailleText(flush=False)
def prepareCommand(self):

View File

@ -13,6 +13,6 @@ generalData = {
'prevUser':'',
'managerList':['eventManager','punctuationManager','cursorManager','applicationManager','commandManager'
,'screenManager','inputManager','outputManager','debug'],
'commandFolderList':['commands','onInput','onScreenUpdate','onScreenChanged'
'commandFolderList':['commands','onInput','onScreenUpdate','onScreenChanged','onHeartBeat', 'onPlugInputDevice'
,'onApplicationChange','onSwitchApplicationProfile',],
}

View File

@ -42,7 +42,12 @@ class driver():
self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR)
return
self.updateInputDevices()
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdog)
self.env['runtime']['eventManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, {'dev':self.iDevicesFD})
def plugInputDeviceWatchdog(self):
time.sleep(2)
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
return time.time()
def shutdown(self):
if not self._initialized:
return
@ -54,7 +59,9 @@ class driver():
if active.value == 0:
return
time.sleep(0.01)
r, w, x = select(deviceFd, [], [], 2)
r = []
while r == []:
r, w, x = select(deviceFd, [], [], 2)
self.watchDog.value = 0
def getInputEvent(self):
if not self.hasIDevices():