From 16f4e3e98126e30931717542128a497fbc30303c Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 27 Jun 2017 01:35:12 +0200 Subject: [PATCH] performance improvements --- .../onHeartBeat/2000-GetSessionInfo.py | 74 +++++++++++++++++++ src/fenrir/core/eventManager.py | 2 + src/fenrir/core/fenrirManager.py | 9 ++- src/fenrir/core/screenManager.py | 12 +-- src/fenrir/inputDriver/evdevDriver.py | 4 +- src/fenrir/screenDriver/vcsaDriver.py | 1 - 6 files changed, 90 insertions(+), 12 deletions(-) create mode 100755 src/fenrir/commands/onHeartBeat/2000-GetSessionInfo.py diff --git a/src/fenrir/commands/onHeartBeat/2000-GetSessionInfo.py b/src/fenrir/commands/onHeartBeat/2000-GetSessionInfo.py new file mode 100755 index 00000000..3b9b55b6 --- /dev/null +++ b/src/fenrir/commands/onHeartBeat/2000-GetSessionInfo.py @@ -0,0 +1,74 @@ +#!/bin/python +import time +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import time +import datetime + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.lastTime = datetime.datetime.now() + self.lastDateString = '' + self.lastTimeString = '' + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('time', 'enabled'): + return + onMinutes = self.env['runtime']['settingsManager'].getSetting('time', 'onMinutes') + delaySec = self.env['runtime']['settingsManager'].getSettingAsInt('time', 'delaySec') + # no need + if onMinutes == '' and delaySec <= 0: + return + onMinutes = onMinutes.split(',') + now = datetime.datetime.now() + # ignore onMinutes if there is a delaySec + if delaySec > 0: + if int((now-self.lastTime).total_seconds()) < delaySec: + return + else: + # shoul announce? + if not str(now.minute) in onMinutes: + return + # already announced? + if now.hour == self.lastTime.hour: + if now.minute == self.lastTime.minute: + return + dateFormat = self.env['runtime']['settingsManager'].getSetting('general', 'dateFormat') + dateString = datetime.datetime.strftime(now, dateFormat) + + presentDate = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentDate') and \ + self.lastDateString != dateString + presentTime = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentTime') + # no changed value to announce + if not (presentDate or presentTime): + return + timeFormat = self.env['runtime']['settingsManager'].getSetting('general', 'timeFormat') + timeString = datetime.datetime.strftime(now, timeFormat) + + if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'interrupt'): + self.env['runtime']['outputManager'].interruptOutput() + if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'announce'): + self.env['runtime']['outputManager'].playSoundIcon('announce') + + if presentTime: + # present the time + self.env['runtime']['outputManager'].presentText(_('Autotime: {0}').format(timeString), soundIcon='', interrupt=False) + # and date if changes + if presentDate: + self.env['runtime']['outputManager'].presentText(dateString , soundIcon='', interrupt=False) + self.lastDateString = dateString + self.lastTime = datetime.datetime.now() + self.lastTimeString = timeString + def setCallback(self, callback): + pass diff --git a/src/fenrir/core/eventManager.py b/src/fenrir/core/eventManager.py index d083135a..69a11455 100644 --- a/src/fenrir/core/eventManager.py +++ b/src/fenrir/core/eventManager.py @@ -53,9 +53,11 @@ class eventManager(): self.handleStopMainLoop() return elif event['Type'] == fenrirEventType.ScreenUpdate: + pass self.env['runtime']['fenrirManager'].handleScreenUpdate() elif event['Type'] == fenrirEventType.KeyboardInput: self.env['runtime']['fenrirManager'].handleInput() + #self.env['runtime']['fenrirManager'].handleScreenUpdate() elif event['Type'] == fenrirEventType.BrailleInput: pass elif event['Type'] == fenrirEventType.PlugInputDevice: diff --git a/src/fenrir/core/fenrirManager.py b/src/fenrir/core/fenrirManager.py index b6a1bddd..32d64fc8 100644 --- a/src/fenrir/core/fenrirManager.py +++ b/src/fenrir/core/fenrirManager.py @@ -63,8 +63,8 @@ class fenrirManager(): self.environment['runtime']['inputManager'].clearEventBuffer() if self.environment['input']['keyForeward'] > 0: self.environment['input']['keyForeward'] -=1 - #self.environment['runtime']['screenManager'].update('onInput') - #self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput') + self.environment['runtime']['screenManager'].update('onInput') + self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput') self.handleCommands() def handleScreenChange(self): self.environment['runtime']['screenManager'].update('onScreenChange') @@ -80,14 +80,15 @@ class fenrirManager(): def handleScreenUpdate(self): s = time.time() + 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') #print(time.time() -s) diff --git a/src/fenrir/core/screenManager.py b/src/fenrir/core/screenManager.py index 0472360a..74dd27b5 100644 --- a/src/fenrir/core/screenManager.py +++ b/src/fenrir/core/screenManager.py @@ -21,16 +21,18 @@ class screenManager(): self.env['runtime']['settingsManager'].shutdownDriver('screenDriver') def update(self, trigger='onUpdate'): - self.env['runtime']['screenDriver'].getCurrScreen() - self.env['runtime']['screenDriver'].getSessionInformation() + + if trigger == 'onScreenChange': + self.env['runtime']['screenDriver'].getCurrScreen() + self.env['runtime']['screenDriver'].getSessionInformation() self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] if self.isScreenChange(): self.changeBrailleScreen() if not self.isSuspendingScreen(self.env['screen']['newTTY']): self.env['runtime']['screenDriver'].update(trigger) - if trigger == 'onUpdate' or self.isScreenChange() \ - or len(self.env['screen']['newDelta']) > 6: - self.env['runtime']['screenDriver'].getCurrApplication() + #if trigger == 'onUpdate' or self.isScreenChange() \ + # or len(self.env['screen']['newDelta']) > 6: + # self.env['runtime']['screenDriver'].getCurrApplication() self.env['screen']['lastScreenUpdate'] = time.time() def isSuspendingScreen(self, screen = None): diff --git a/src/fenrir/inputDriver/evdevDriver.py b/src/fenrir/inputDriver/evdevDriver.py index 84068758..c8d0d07f 100644 --- a/src/fenrir/inputDriver/evdevDriver.py +++ b/src/fenrir/inputDriver/evdevDriver.py @@ -45,7 +45,7 @@ class driver(): 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) + time.sleep(2.5) #self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay') return time.time() def shutdown(self): @@ -58,7 +58,7 @@ class driver(): while self.watchDog.value == 0: if active.value == 0: return - time.sleep(0.01) + time.sleep(0.001) r = [] while r == []: r, w, x = select(deviceFd, [], [], 2) diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index 328d90e4..2aa835c5 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -98,7 +98,6 @@ class driver(): self.env['screen']['autoIgnoreScreens'] = [] def updateWatchdog(self,active , eventQueue): - print('init VCSA updateWatchdog') currScreen = '2' vcsa = {} for i in range(1,7):