add first trigger
This commit is contained in:
parent
0fb493e391
commit
6f84710b6f
@ -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
|
||||||
|
|
||||||
|
13
src/fenrir-package/commands/onInput/10000-shut_up.py
Normal file
13
src/fenrir-package/commands/onInput/10000-shut_up.py
Normal file
@ -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
|
15
src/fenrir-package/commands/onInput/70000-speak_incomming.py
Normal file
15
src/fenrir-package/commands/onInput/70000-speak_incomming.py
Normal file
@ -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
|
@ -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
|
@ -25,7 +25,10 @@ class commandManager():
|
|||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
return environment
|
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'):
|
def executeCommand(self, environment, currCommand, section = 'commands'):
|
||||||
if self.isCommandDefined(environment):
|
if self.isCommandDefined(environment):
|
||||||
try:
|
try:
|
||||||
|
@ -8,12 +8,10 @@ commandInfo = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
'onnInput':{
|
'onInput':{
|
||||||
},
|
},
|
||||||
'onScreenChanged':{
|
'onScreenChanged':{
|
||||||
},
|
},
|
||||||
'commands':{
|
'commands':{
|
||||||
# 'curr_line': curr_line.command(),
|
|
||||||
# 'shut_up': shut_up.command()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
screenData = {
|
screenData = {
|
||||||
'columns': 0,
|
'columns': 0,
|
||||||
'lines': 0,
|
'lines': 0,
|
||||||
'delta': '',
|
'oldDelta': '',
|
||||||
'oldCursorReview':{'x':0,'y':0},
|
'oldCursorReview':{'x':0,'y':0},
|
||||||
'oldCursor':{'x':0,'y':0},
|
'oldCursor':{'x':0,'y':0},
|
||||||
'oldContentBytes': b'',
|
'oldContentBytes': b'',
|
||||||
'oldContentText': '',
|
'oldContentText': '',
|
||||||
'oldContentAttrib': b'',
|
'oldContentAttrib': b'',
|
||||||
|
'newDelta': '',
|
||||||
'newCursorReview':{'x':0,'y':0},
|
'newCursorReview':{'x':0,'y':0},
|
||||||
'newCursor':{'x':0,'y':0},
|
'newCursor':{'x':0,'y':0},
|
||||||
'newContentBytes': b'',
|
'newContentBytes': b'',
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from core.settings import settings
|
from core.settings import settings
|
||||||
import evdev
|
import evdev
|
||||||
|
import importlib.util
|
||||||
|
|
||||||
class settingsManager():
|
class settingsManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self.settings = settings
|
||||||
|
|
||||||
def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.kb'):
|
def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.kb'):
|
||||||
kbConfig = open(kbConfigPath,"r")
|
kbConfig = open(kbConfigPath,"r")
|
||||||
@ -66,7 +67,43 @@ class settingsManager():
|
|||||||
environment['settings'].read(settingConfigPath)
|
environment['settings'].read(settingConfigPath)
|
||||||
return environment
|
return environment
|
||||||
|
|
||||||
def getSetting(self, environment, setting):
|
def getSetting(self, environment, section, setting):
|
||||||
value = True # do be implemented
|
value = ''
|
||||||
|
try:
|
||||||
|
value = environment['settings'].get(section, setting)
|
||||||
|
except:
|
||||||
|
value = self.settings[section][setting]
|
||||||
return value
|
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
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,10 +16,6 @@ from core import commandManager
|
|||||||
from core import settingsManager
|
from core import settingsManager
|
||||||
from utils import debug
|
from utils import debug
|
||||||
|
|
||||||
from speech import espeak as es
|
|
||||||
from speech import speechd as sd
|
|
||||||
from screen import linux as lx
|
|
||||||
|
|
||||||
class fenrir():
|
class fenrir():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.threadUpdateScreen = None
|
self.threadUpdateScreen = None
|
||||||
@ -29,16 +25,21 @@ class fenrir():
|
|||||||
self.environment['runtime']['inputManager'] = inputManager.inputManager()
|
self.environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||||
self.environment['runtime']['settingsManager'] = settingsManager.settingsManager()
|
self.environment['runtime']['settingsManager'] = settingsManager.settingsManager()
|
||||||
self.environment = self.environment['runtime']['settingsManager'].loadShortcuts(self.environment)
|
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['runtime']['commandManager'] = commandManager.commandManager()
|
||||||
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'commands')
|
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,'onInput')
|
||||||
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onScreenChanged')
|
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onScreenChanged')
|
||||||
self.environment['runtime']['debug'] = debug.debug()
|
self.environment['runtime']['debug'] = debug.debug()
|
||||||
signal.signal(signal.SIGINT, self.captureSignal)
|
signal.signal(signal.SIGINT, self.captureSignal)
|
||||||
# the following hard coded, in future we have a config loader
|
self.environment = self.environment['runtime']['settingsManager'].loadSpeechDriver(self.environment,\
|
||||||
self.environment['runtime']['speechDriver'] = sd.speech()
|
self.environment['runtime']['settingsManager'].getSetting(self.environment,'speech', 'driver'))
|
||||||
self.environment['runtime']['screenDriver'] = lx.screenManager()
|
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):
|
def proceed(self):
|
||||||
#self.threadUpdateScreen = Thread(target=self.updateScreen, args=())
|
#self.threadUpdateScreen = Thread(target=self.updateScreen, args=())
|
||||||
self.threadHandleInput = Thread(target=self.handleInput, args=())
|
self.threadHandleInput = Thread(target=self.handleInput, args=())
|
||||||
@ -53,16 +54,18 @@ class fenrir():
|
|||||||
def handleInput(self):
|
def handleInput(self):
|
||||||
while(self.environment['generalInformation']['running']):
|
while(self.environment['generalInformation']['running']):
|
||||||
self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment)
|
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']['screenDriver'].analyzeScreen(self.environment)
|
||||||
|
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
|
||||||
if self.environment['input']['currShortcutString'] != '':
|
if self.environment['input']['currShortcutString'] != '':
|
||||||
self.handleCommands()
|
self.handleCommands()
|
||||||
|
|
||||||
def updateScreen(self):
|
def updateScreen(self):
|
||||||
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
|
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
|
||||||
|
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
def handleCommands(self):
|
def handleCommands(self):
|
||||||
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
|
|
||||||
if (self.environment['commandInfo']['currCommand'] != '') and \
|
if (self.environment['commandInfo']['currCommand'] != '') and \
|
||||||
(time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.4):
|
(time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.4):
|
||||||
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
|
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
|
||||||
|
@ -7,17 +7,26 @@ import time
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
#import fenrir.utils.debug
|
#import fenrir.utils.debug
|
||||||
class screenManager():
|
class screen():
|
||||||
def __init__(self, device='/dev/vcsa'):
|
def __init__(self, device='/dev/vcsa'):
|
||||||
self.vcsaDevicePath = device
|
self.vcsaDevicePath = device
|
||||||
self.textWrapper = textwrap.TextWrapper()
|
self.textWrapper = textwrap.TextWrapper()
|
||||||
self.textWrapper.drop_whitespace = False
|
self.textWrapper.drop_whitespace = False
|
||||||
def analyzeScreen(self, environment):
|
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
|
# read screen
|
||||||
currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
|
currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||||
environment['screenData']['newTTY'] = currTTY.read()[3:-1]
|
environment['screenData']['newTTY'] = currTTY.read()[3:-1]
|
||||||
currTTY.close()
|
currTTY.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vcsa = open(self.vcsaDevicePath + environment['screenData']['newTTY'] ,'rb',0)
|
vcsa = open(self.vcsaDevicePath + environment['screenData']['newTTY'] ,'rb',0)
|
||||||
environment['screenData']['newContentBytes'] = vcsa.read()
|
environment['screenData']['newContentBytes'] = vcsa.read()
|
||||||
@ -35,10 +44,7 @@ class screenManager():
|
|||||||
|
|
||||||
# analyze content
|
# analyze content
|
||||||
environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('WINDOWS-1250'))
|
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']['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]
|
environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2]
|
||||||
|
|
||||||
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
|
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
|
||||||
@ -48,20 +54,13 @@ class screenManager():
|
|||||||
environment['screenData']['oldContentText'] = ''
|
environment['screenData']['oldContentText'] = ''
|
||||||
environment['screenData']['oldCursor']['x'] = 0
|
environment['screenData']['oldCursor']['x'] = 0
|
||||||
environment['screenData']['oldCursor']['y'] = 0
|
environment['screenData']['oldCursor']['y'] = 0
|
||||||
environment['runtime']['speechDriver'].cancel()
|
environment['screenData']['oldDelta'] = ''
|
||||||
|
environment['screenData']['newDelta'] = ''
|
||||||
|
|
||||||
# changes on the screen
|
# changes on the screen
|
||||||
if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \
|
if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \
|
||||||
(len(environment['screenData']['newContentText']) > 0):
|
(len(environment['screenData']['newContentText']) > 0):
|
||||||
diff = difflib.ndiff(" ".join(environment['screenData']['oldContentText'].split()), " ".join(environment['screenData']['newContentText'].split()))
|
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('+ '))
|
environment['screenData']['newDelta'] = ''.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']
|
|
||||||
return environment
|
return environment
|
||||||
|
@ -7,7 +7,7 @@ class sound():
|
|||||||
pass
|
pass
|
||||||
def playSoundFile(self, Path):
|
def playSoundFile(self, Path):
|
||||||
pass
|
pass
|
||||||
def setCallback(self, callback)
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user