diff --git a/config/settings/settings.cfg b/config/settings/settings.cfg index d3f5a12f..2aed62ac 100644 --- a/config/settings/settings.cfg +++ b/config/settings/settings.cfg @@ -1 +1,26 @@ +[sound] +enabled=False, +driver=sox +theme=default + +[speech] +enabled=True +driver=speechd +rate=1 +pitch=1 +module= +voice=de + +[braille] +enabled=False +layout=en + +['screen] +driver=linux + +[general] +keyboardLayout=desktop +debugLevel=0 +punctuationLevel=1 + diff --git a/src/fenrir-package/commands/onInput/10000-shut_up.py b/src/fenrir-package/commands/onInput/10000-shut_up.py new file mode 100644 index 00000000..0dde2d39 --- /dev/null +++ b/src/fenrir-package/commands/onInput/10000-shut_up.py @@ -0,0 +1,13 @@ +#!/bin/python + +class command(): + def __init__(self): + pass + def run(self, environment): + environment['runtime']['speechDriver'].cancel() + print('input changed stop') + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass diff --git a/src/fenrir-package/commands/onInput/70000-speak_incomming.py b/src/fenrir-package/commands/onInput/70000-speak_incomming.py new file mode 100644 index 00000000..39647ad7 --- /dev/null +++ b/src/fenrir-package/commands/onInput/70000-speak_incomming.py @@ -0,0 +1,15 @@ +#!/bin/python + +class command(): + def __init__(self): + pass + def run(self, environment): + if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \ + environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: + environment['runtime']['speechDriver'].speak(environment['screenData']['newDelta']) + print('input changed bla') + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass diff --git a/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py b/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py new file mode 100644 index 00000000..3f98c19f --- /dev/null +++ b/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py @@ -0,0 +1,15 @@ +#!/bin/python + +class command(): + def __init__(self): + pass + def run(self, environment): + if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \ + environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: + environment['runtime']['speechDriver'].speak(environment['screenData']['newDelta']) + print('screenchanged bla') + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index dc440a7c..d77fe02b 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -25,7 +25,10 @@ class commandManager(): except: continue return environment - + def executeTriggerCommands(self, environment, trigger): + for cmd in sorted(environment['commands'][trigger]): + environment = environment['commands'][trigger][cmd].run(environment) + return environment def executeCommand(self, environment, currCommand, section = 'commands'): if self.isCommandDefined(environment): try: diff --git a/src/fenrir-package/core/commands.py b/src/fenrir-package/core/commands.py index 6832457c..771893c2 100644 --- a/src/fenrir-package/core/commands.py +++ b/src/fenrir-package/core/commands.py @@ -8,12 +8,10 @@ commandInfo = { } commands = { -'onnInput':{ +'onInput':{ }, 'onScreenChanged':{ }, 'commands':{ -# 'curr_line': curr_line.command(), -# 'shut_up': shut_up.command() } } diff --git a/src/fenrir-package/core/screenData.py b/src/fenrir-package/core/screenData.py index 5c13736d..97317799 100644 --- a/src/fenrir-package/core/screenData.py +++ b/src/fenrir-package/core/screenData.py @@ -3,12 +3,13 @@ screenData = { 'columns': 0, 'lines': 0, -'delta': '', +'oldDelta': '', 'oldCursorReview':{'x':0,'y':0}, 'oldCursor':{'x':0,'y':0}, 'oldContentBytes': b'', 'oldContentText': '', 'oldContentAttrib': b'', +'newDelta': '', 'newCursorReview':{'x':0,'y':0}, 'newCursor':{'x':0,'y':0}, 'newContentBytes': b'', diff --git a/src/fenrir-package/core/settingsManager.py b/src/fenrir-package/core/settingsManager.py index 63f76082..8e2ec190 100644 --- a/src/fenrir-package/core/settingsManager.py +++ b/src/fenrir-package/core/settingsManager.py @@ -2,10 +2,11 @@ from configparser import ConfigParser from core.settings import settings import evdev +import importlib.util class settingsManager(): def __init__(self): - pass + self.settings = settings def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.kb'): kbConfig = open(kbConfigPath,"r") @@ -66,7 +67,43 @@ class settingsManager(): environment['settings'].read(settingConfigPath) return environment - def getSetting(self, environment, setting): - value = True # do be implemented + def getSetting(self, environment, section, setting): + value = '' + try: + value = environment['settings'].get(section, setting) + except: + value = self.settings[section][setting] return value + + def getSettingAsInt(self, environment, section, setting): + return int(getSetting(self, environment, section, setting)) + + def getSettingAsBool(self, environment, section, setting): + return bool(getSetting(self, environment, section, setting)) + + def loadSpeechDriver(self, environment, driverName): + if environment['runtime']['speechDriver'] != None: + environment['runtime']['speechDriver'].shutdown() + spec = importlib.util.spec_from_file_location(driverName, 'speech/' + driverName + '.py') + driver_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(driver_mod) + environment['runtime']['speechDriver'] = driver_mod.speech() + return environment + + def loadSoundDriver(self, environment, driverName): + if environment['runtime']['soundDriver'] != None: + environment['runtime']['soundDriver'].shutdown() + spec = importlib.util.spec_from_file_location(driverName, 'sound/' + driverName + '.py') + driver_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(driver_mod) + environment['runtime']['soundDriver'] = driver_mod.sound() + return environment + + def loadScreenDriver(self, environment, driverName): + spec = importlib.util.spec_from_file_location(driverName, 'screen/' + driverName + '.py') + driver_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(driver_mod) + environment['runtime']['screenDriver'] = driver_mod.screen() + return environment + diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 9aa76e9e..f06021bd 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -16,10 +16,6 @@ from core import commandManager from core import settingsManager from utils import debug -from speech import espeak as es -from speech import speechd as sd -from screen import linux as lx - class fenrir(): def __init__(self): self.threadUpdateScreen = None @@ -29,16 +25,21 @@ class fenrir(): self.environment['runtime']['inputManager'] = inputManager.inputManager() self.environment['runtime']['settingsManager'] = settingsManager.settingsManager() self.environment = self.environment['runtime']['settingsManager'].loadShortcuts(self.environment) + self.environment = self.environment['runtime']['settingsManager'].loadSettings(self.environment) + self.environment['runtime']['commandManager'] = commandManager.commandManager() self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'commands') self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onInput') self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onScreenChanged') self.environment['runtime']['debug'] = debug.debug() signal.signal(signal.SIGINT, self.captureSignal) - # the following hard coded, in future we have a config loader - self.environment['runtime']['speechDriver'] = sd.speech() - self.environment['runtime']['screenDriver'] = lx.screenManager() - + self.environment = self.environment['runtime']['settingsManager'].loadSpeechDriver(self.environment,\ + self.environment['runtime']['settingsManager'].getSetting(self.environment,'speech', 'driver')) + self.environment = self.environment['runtime']['settingsManager'].loadScreenDriver(self.environment,\ + self.environment['runtime']['settingsManager'].getSetting(self.environment,'screen', 'driver')) + self.environment = self.environment['runtime']['settingsManager'].loadSoundDriver(self.environment,\ + self.environment['runtime']['settingsManager'].getSetting(self.environment,'sound', 'driver')) + def proceed(self): #self.threadUpdateScreen = Thread(target=self.updateScreen, args=()) self.threadHandleInput = Thread(target=self.handleInput, args=()) @@ -53,16 +54,18 @@ class fenrir(): def handleInput(self): while(self.environment['generalInformation']['running']): self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment) + self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment) + self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') if self.environment['input']['currShortcutString'] != '': self.handleCommands() def updateScreen(self): self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment) + self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') time.sleep(0.5) def handleCommands(self): - self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) if (self.environment['commandInfo']['currCommand'] != '') and \ (time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.4): self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands') diff --git a/src/fenrir-package/screen/linux.py b/src/fenrir-package/screen/linux.py index c3358bd1..a735270a 100644 --- a/src/fenrir-package/screen/linux.py +++ b/src/fenrir-package/screen/linux.py @@ -7,17 +7,26 @@ import time import re #import fenrir.utils.debug -class screenManager(): +class screen(): def __init__(self, device='/dev/vcsa'): self.vcsaDevicePath = device self.textWrapper = textwrap.TextWrapper() self.textWrapper.drop_whitespace = False def analyzeScreen(self, environment): + # set new "old" values + environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes'] + environment['screenData']['oldContentText'] = environment['screenData']['newContentText'] + environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib'] + environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x'] + environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y'] + environment['screenData']['oldTTY'] = environment['screenData']['newTTY'] + environment['screenData']['oldDelta'] = environment['screenData']['newDelta'] + # read screen currTTY = open('/sys/devices/virtual/tty/tty0/active','r') environment['screenData']['newTTY'] = currTTY.read()[3:-1] currTTY.close() - + try: vcsa = open(self.vcsaDevicePath + environment['screenData']['newTTY'] ,'rb',0) environment['screenData']['newContentBytes'] = vcsa.read() @@ -35,10 +44,7 @@ class screenManager(): # analyze content environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('WINDOWS-1250')) - #environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('cp1252')).encode('utf-8')[2:] environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2] -# environment['screenData']['newContentText'] = '\n'.join(textwrap.wrap(environment['screenData']['newContentText'], environment['screenData']['columns']))[:-2] - #environment['screenData']['newContentText'] = re.sub("(.{"+ str(environment['screenData']['columns'])+"})", "\\1\n", str(environment['screenData']['newContentText']), 0, re.DOTALL) environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2] if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: @@ -48,20 +54,13 @@ class screenManager(): environment['screenData']['oldContentText'] = '' environment['screenData']['oldCursor']['x'] = 0 environment['screenData']['oldCursor']['y'] = 0 - environment['runtime']['speechDriver'].cancel() + environment['screenData']['oldDelta'] = '' + environment['screenData']['newDelta'] = '' + # changes on the screen if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \ (len(environment['screenData']['newContentText']) > 0): diff = difflib.ndiff(" ".join(environment['screenData']['oldContentText'].split()), " ".join(environment['screenData']['newContentText'].split())) - environment['screenData']['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ ')) - if ((len(environment['screenData']['delta']) == 1)): - environment['runtime']['speechDriver'].cancel() - environment['runtime']['speechDriver'].speak(environment['screenData']['delta']) - # set new "old" values - environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes'] - environment['screenData']['oldContentText'] = environment['screenData']['newContentText'] - environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib'] - environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x'] - environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y'] - environment['screenData']['oldTTY'] = environment['screenData']['newTTY'] + environment['screenData']['newDelta'] = ''.join(x[2:] for x in diff if x.startswith('+ ')) + return environment diff --git a/src/fenrir-package/sound/sox.py b/src/fenrir-package/sound/sox.py index 17bc0b84..db30591c 100644 --- a/src/fenrir-package/sound/sox.py +++ b/src/fenrir-package/sound/sox.py @@ -7,7 +7,7 @@ class sound(): pass def playSoundFile(self, Path): pass - def setCallback(self, callback) + def setCallback(self, callback): pass def shutdown(self): pass