diff --git a/src/fenrir/commands/onHeartBeat/76000-time.py b/src/fenrir/commands/onHeartBeat/76000-time.py old mode 100644 new mode 100755 diff --git a/src/fenrir/core/commandData.py b/src/fenrir/core/commandData.py index c3ea2fae..50bc072d 100644 --- a/src/fenrir/core/commandData.py +++ b/src/fenrir/core/commandData.py @@ -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':{ - }, -} diff --git a/src/fenrir/core/commandManager.py b/src/fenrir/core/commandManager.py index cb198f33..d5dde35c 100644 --- a/src/fenrir/core/commandManager.py +++ b/src/fenrir/core/commandManager.py @@ -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(): diff --git a/src/fenrir/core/environment.py b/src/fenrir/core/environment.py index 0dde4f99..b8838e15 100644 --- a/src/fenrir/core/environment.py +++ b/src/fenrir/core/environment.py @@ -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, diff --git a/src/fenrir/core/eventManager.py b/src/fenrir/core/eventManager.py index 7c8f7ce8..779d079f 100644 --- a/src/fenrir/core/eventManager.py +++ b/src/fenrir/core/eventManager.py @@ -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): diff --git a/src/fenrir/core/fenrirManager.py b/src/fenrir/core/fenrirManager.py index 2e291a55..a26bb08e 100644 --- a/src/fenrir/core/fenrirManager.py +++ b/src/fenrir/core/fenrirManager.py @@ -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): diff --git a/src/fenrir/core/generalData.py b/src/fenrir/core/generalData.py index 324099ba..261e7379 100644 --- a/src/fenrir/core/generalData.py +++ b/src/fenrir/core/generalData.py @@ -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',], } diff --git a/src/fenrir/inputDriver/evdevDriver.py b/src/fenrir/inputDriver/evdevDriver.py index de6d7b0d..84068758 100644 --- a/src/fenrir/inputDriver/evdevDriver.py +++ b/src/fenrir/inputDriver/evdevDriver.py @@ -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():