Merge branch 'master' into bleed

This commit is contained in:
chrys 2018-05-11 23:19:38 +02:00
commit c6c4d4b331
8 changed files with 132 additions and 68 deletions

View File

@ -14,11 +14,13 @@ This software is licensed under the LGPL v3 .
1. "evdevDriver" input driver for linux evdev 1. "evdevDriver" input driver for linux evdev
- python-evdev >=0.6.3 - python-evdev >=0.6.3
- python-pyudev - python-pyudev
- This is commonly referred to as python3-evdev by your distribution 2. This is commonly referred to as python3-evdev by your distribution
- loaded uinput kernel module - loaded uinput kernel module
- ReadWrite permission - ReadWrite permission
- /dev/input - /dev/input
- /dev/uinput - /dev/uinput
3. "ptyDriver" terminal emulation input driver
- python-pyte
# Screen Drivers: # Screen Drivers:
1. "vcsaDriver" screen driver for linux VCSA devices 1. "vcsaDriver" screen driver for linux VCSA devices
@ -28,28 +30,36 @@ This software is licensed under the LGPL v3 .
- /dev/tty[1-64] - /dev/tty[1-64]
- /dev/vcsa[1-64] - /dev/vcsa[1-64]
- read logind DBUS - read logind DBUS
2. "ptyDriver" terminal emulation driver
- python-pyte
3. "dummyDriver" just a dummy
# Speech Drivers: # Speech Drivers:
1. "EspeakDriver" speech driver for Espeak or Espeak-NG: 1. "genericDriver" (default) sound driver for sound as subprocess:
- espeak or espeak-ng
2. "espeakDriver" speech driver for Espeak or Espeak-NG:
- python-espeak - python-espeak
- "speechdDriver" speech driver for Speech-dispatcher: 3. "speechdDriver" speech driver for Speech-dispatcher:
- Speech-dispatcher - Speech-dispatcher
- python-speechd - python-speechd
2. "dummyDriver" speech driver for debugging 4. "dummyDriver" no speech
5. "debugDriver" speech driver for debugging
# Braille Drivers: # Braille Drivers:
1. "BrlttyDriver" braille driver (WIP): 1. "BrlttyDriver" braille driver (WIP):
- brltty (configured and running) - brltty (configured and running)
- python-brlapi - python-brlapi
2. "dummyDriver" Braille driver for debugging 2. "dummyDriver" (default) no braille
3. "debugDriver" Braille driver for debugging
# Sound Drivers: # Sound Drivers:
1. "genericDriver" sound driver for sound as subprocess: 1. "genericDriver" (default) sound driver for sound as subprocess:
- Sox - Sox
2. "gstreamerDriver" sound driver for gstreamer 2. "gstreamerDriver" sound driver for gstreamer
- gstreamer >=1.0 - gstreamer >=1.0
- GLib - GLib
3. "dummyDriver" sound driver for debugging 3. "dummyDriver" no sound
4. "debugDriver" sound driver for debugging
# Extras: # Extras:
1. spellchecker 1. spellchecker
@ -72,7 +82,7 @@ Settings "settings.conf" is located in the "config" directory or after installat
Take care to use drivers from the config matching your installed drivers. Take care to use drivers from the config matching your installed drivers.
By default it uses: By default it uses:
- sound driver: genericDriver (via sox, could configured in settings.conf) - sound driver: genericDriver (via sox, could configured in settings.conf)
- speech driver: speechdDriver - speech driver: genericDriver (via espeak or espeak-ng, could configured in settings.conf)
- braille driver: brlttyDriver (WIP) - braille driver: brlttyDriver (WIP)
- input driver: evdevDriver - input driver: evdevDriver

View File

@ -110,7 +110,10 @@ class inputManager():
def grabAllDevices(self): def grabAllDevices(self):
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
self.env['runtime']['inputDriver'].grabAllDevices() self.env['runtime']['inputDriver'].grabAllDevices()
def ungrabAllDevices(self):
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
self.env['runtime']['inputDriver'].ungrabAllDevices()
def updateInputDevices(self): def updateInputDevices(self):
try: try:
self.env['runtime']['inputDriver'].updateInputDevices() self.env['runtime']['inputDriver'].updateInputDevices()

View File

@ -228,8 +228,11 @@ class outputManager():
offsetText = offsetText[offsetStart: offsetEnd] offsetText = offsetText[offsetStart: offsetEnd]
return offsetText return offsetText
def interruptOutput(self): def interruptOutput(self):
self.env['runtime']['speechDriver'].cancel() try:
self.env['runtime']['debug'].writeDebugOut("Interrupt speech",debug.debugLevel.INFO) self.env['runtime']['speechDriver'].cancel()
self.env['runtime']['debug'].writeDebugOut("Interrupt speech",debug.debugLevel.INFO)
except:
pass
def clearFlushTime(self): def clearFlushTime(self):
self.setFlushTime(0.0) self.setFlushTime(0.0)

View File

@ -71,7 +71,7 @@ class processManager():
else: else:
function(self.running, eventQueue) function(self.running, eventQueue)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('processManager:customEventWorkerThread:function():' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('processManager:customEventWorkerThread:function('+str(function)+'):' + str(e),debug.debugLevel.ERROR)
if runOnce: if runOnce:
break break
@ -88,7 +88,7 @@ class processManager():
else: else:
Data = function(self.running) Data = function(self.running)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('processManager:simpleEventWorkerThread:function():' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('processManager:simpleEventWorkerThread:function('+str(function)+'):' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['eventManager'].putToEventQueue(event, Data) self.env['runtime']['eventManager'].putToEventQueue(event, Data)
if runOnce: if runOnce:
break break

View File

@ -10,35 +10,59 @@ import time, os, re, difflib
class screenManager(): class screenManager():
def __init__(self): def __init__(self):
pass self.currScreenIgnored = False
self.prevScreenIgnored = False
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\ self.env['runtime']['settingsManager'].loadDriver(\
self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver') self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver')
self.env['runtime']['screenDriver'].getCurrScreen() self.getCurrScreen()
self.env['runtime']['screenDriver'].getCurrScreen() self.getCurrScreen()
self.env['runtime']['screenDriver'].getSessionInformation() self.getSessionInformation()
def getCurrScreen(self):
try:
self.env['runtime']['screenDriver'].getCurrScreen()
except:
pass
def getSessionInformation(self):
try:
self.env['runtime']['screenDriver'].getSessionInformation()
except:
pass
def shutdown(self): def shutdown(self):
self.env['runtime']['settingsManager'].shutdownDriver('screenDriver') self.env['runtime']['settingsManager'].shutdownDriver('screenDriver')
def hanldeScreenChange(self, eventData): def hanldeScreenChange(self, eventData):
self.env['runtime']['screenDriver'].getCurrScreen() self.getCurrScreen()
self.env['runtime']['screenDriver'].getSessionInformation() self.getSessionInformation()
if self.isScreenChange(): if self.isScreenChange():
self.changeBrailleScreen() self.changeBrailleScreen()
if not self.isSuspendingScreen(self.env['screen']['newTTY']): if not self.isSuspendingScreen(self.env['screen']['newTTY']):
self.update(eventData, 'onScreenChange') self.update(eventData, 'onScreenChange')
self.env['screen']['lastScreenUpdate'] = time.time() self.env['screen']['lastScreenUpdate'] = time.time()
def handleScreenUpdate(self, eventData): def handleScreenUpdate(self, eventData):
self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] self.env['screen']['oldApplication'] = self.env['screen']['newApplication']
if not self.isSuspendingScreen(self.env['screen']['newTTY']): self.updateScreenIgnored()
if self.getCurrScreenIgnored() != self.getPrevScreenIgnored():
if self.getCurrScreenIgnored():
self.env['runtime']['inputManager'].ungrabAllDevices()
self.env['runtime']['outputManager'].interruptOutput()
else:
self.env['runtime']['inputManager'].grabAllDevices()
if not self.getCurrScreenIgnored():
self.update(eventData, 'onScreenUpdate') self.update(eventData, 'onScreenUpdate')
#if trigger == 'onUpdate' or self.isScreenChange() \ #if trigger == 'onUpdate' or self.isScreenChange() \
# or len(self.env['screen']['newDelta']) > 6: # or len(self.env['screen']['newDelta']) > 6:
# self.env['runtime']['screenDriver'].getCurrApplication() # self.env['runtime']['screenDriver'].getCurrApplication()
self.env['screen']['lastScreenUpdate'] = time.time() self.env['screen']['lastScreenUpdate'] = time.time()
def getCurrScreenIgnored(self):
return self.currScreenIgnored
def getPrevScreenIgnored(self):
return self.prevScreenIgnored
def updateScreenIgnored(self):
self.prevScreenIgnored = self.currScreenIgnored
self.currScreenIgnored = self.isSuspendingScreen(self.env['screen']['newTTY'])
def update(self, eventData, trigger='onUpdate'): def update(self, eventData, trigger='onUpdate'):
# set new "old" values # set new "old" values
self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes'] self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes']
self.env['screen']['oldContentText'] = self.env['screen']['newContentText'] self.env['screen']['oldContentText'] = self.env['screen']['newContentText']
@ -50,6 +74,7 @@ class screenManager():
self.env['screen']['oldAttribDelta'] = self.env['screen']['newAttribDelta'] self.env['screen']['oldAttribDelta'] = self.env['screen']['newAttribDelta']
self.env['screen']['oldNegativeDelta'] = self.env['screen']['newNegativeDelta'] self.env['screen']['oldNegativeDelta'] = self.env['screen']['newNegativeDelta']
self.env['screen']['newContentBytes'] = eventData['bytes'] self.env['screen']['newContentBytes'] = eventData['bytes']
# get metadata like cursor or screensize # get metadata like cursor or screensize
self.env['screen']['lines'] = int( eventData['lines']) self.env['screen']['lines'] = int( eventData['lines'])
self.env['screen']['columns'] = int( eventData['columns']) self.env['screen']['columns'] = int( eventData['columns'])
@ -125,7 +150,7 @@ class screenManager():
if self.env['screen']['oldContentAttrib'] != self.env['screen']['newContentAttrib']: if self.env['screen']['oldContentAttrib'] != self.env['screen']['newContentAttrib']:
if self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'): if self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'):
self.env['screen']['newAttribDelta'], self.env['screen']['newCursorAttrib'] = screen_utils.trackHighlights(self.env['screen']['oldContentAttrib'], self.env['screen']['newContentAttrib'], self.env['screen']['newContentText'], self.env['screen']['columns']) self.env['screen']['newAttribDelta'], self.env['screen']['newCursorAttrib'] = screen_utils.trackHighlights(self.env['screen']['oldContentAttrib'], self.env['screen']['newContentAttrib'], self.env['screen']['newContentText'], self.env['screen']['columns'])
def formatAttributes(self, attribute, attributeFormatString = None): def formatAttributes(self, attribute, attributeFormatString = None):
if not attributeFormatString: if not attributeFormatString:
attributeFormatString = self.env['runtime']['settingsManager'].getSetting('general', 'attributeFormatString') attributeFormatString = self.env['runtime']['settingsManager'].getSetting('general', 'attributeFormatString')

View File

@ -40,6 +40,7 @@ class driver(inputDriver):
self.iDevices = {} self.iDevices = {}
self.iDevicesFD = self._manager.list() self.iDevicesFD = self._manager.list()
self.uDevices = {} self.uDevices = {}
self.gDevices = {}
self.iDeviceNo = 0 self.iDeviceNo = 0
self.watchDog = Value(c_bool, True) self.watchDog = Value(c_bool, True)
def initialize(self, environment): def initialize(self, environment):
@ -75,46 +76,53 @@ class driver(inputDriver):
return time.time() return time.time()
def inputWatchdog(self,active , eventQueue): def inputWatchdog(self,active , eventQueue):
while active.value: try:
r, w, x = select(self.iDevices, [], [], 0.5) while active.value:
for fd in r: r, w, x = select(self.iDevices, [], [], 0.5)
event = None for fd in r:
foreward = False event = None
eventFired = False foreward = False
try: eventFired = False
event = self.iDevices[fd].read_one() try:
except: event = self.iDevices[fd].read_one()
self.removeDevice(fd) except:
while(event): self.removeDevice(fd)
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) while(event):
if event.type == evdev.events.EV_KEY: self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])
if event.code != 0: if event.type == evdev.events.EV_KEY:
currMapEvent = self.mapEvent(event) if event.code != 0:
if not currMapEvent: currMapEvent = self.mapEvent(event)
foreward = True if not currMapEvent:
if not isinstance(currMapEvent['EventName'], str): foreward = True
foreward = True if not isinstance(currMapEvent['EventName'], str):
if not foreward or eventFired: foreward = True
if currMapEvent['EventState'] in [0,1,2]: if not foreward or eventFired:
eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()}) if currMapEvent['EventState'] in [0,1,2]:
eventFired = True eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()})
else: eventFired = True
if not event.type in [0,4]: else:
foreward = True if not event.type in [0,4]:
foreward = True
event = self.iDevices[fd].read_one()
if foreward and not eventFired: event = self.iDevices[fd].read_one()
self.writeEventBuffer() if foreward and not eventFired:
self.clearEventBuffer() self.writeEventBuffer()
self.clearEventBuffer()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("INPUT WATCHDOG CRASH: "+str(e),debug.debugLevel.ERROR)
def handleInputEvent(self, event): def handleInputEvent(self, event):
return return
def writeEventBuffer(self): def writeEventBuffer(self):
if not self._initialized: if not self._initialized:
return return
for iDevice, uDevice, event in self.env['input']['eventBuffer']: for iDevice, uDevice, event in self.env['input']['eventBuffer']:
self.writeUInput(uDevice, event) try:
if self.gDevices[iDevice.fd]:
self.writeUInput(uDevice, event)
except Exception as e:
pass
def clearEventBuffer(self): def clearEventBuffer(self):
if not self._initialized: if not self._initialized:
@ -184,7 +192,6 @@ class driver(inputDriver):
self.grabDevice(currDevice.fd) self.grabDevice(currDevice.fd)
self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO)
except Exception as e: except Exception as e:
print(e)
self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO)
self.iDeviceNo = len(evdev.list_devices()) self.iDeviceNo = len(evdev.list_devices())
self.updateMPiDevicesFD() self.updateMPiDevicesFD()
@ -238,14 +245,18 @@ class driver(inputDriver):
if not self._initialized: if not self._initialized:
return return
for fd in self.iDevices: for fd in self.iDevices:
self.grabDevice(fd) self.grabDevice(fd)
def ungrabAllDevices(self):
if not self._initialized:
return
for fd in self.iDevices:
self.ungrabDevices(fd)
def grabDevice(self, fd): def grabDevice(self, fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
self.uDevices[fd] = None self.uDevices[fd] = None
return return
try: try:
self.uDevices[fd] = UInput.from_device(self.iDevices[fd].fn) self.uDevices[fd] = UInput.from_device(self.iDevices[fd])
except Exception as e: except Exception as e:
try: try:
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: compat fallback: ' + str(e),debug.debugLevel.WARNING) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: compat fallback: ' + str(e),debug.debugLevel.WARNING)
@ -261,13 +272,21 @@ class driver(inputDriver):
return return
try: try:
self.iDevices[fd].grab() self.iDevices[fd].grab()
self.gDevices[fd] = True
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR)
def ungrabDevices(self,fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
return
try:
self.iDevices[fd].ungrab()
self.gDevices[fd] = False
except:
pass
def removeDevice(self,fd): def removeDevice(self,fd):
self.clearEventBuffer() self.clearEventBuffer()
try: try:
self.iDevices[fd].ungrab() self.ungrabDevices(fd)
except: except:
pass pass
try: try:
@ -286,7 +305,11 @@ class driver(inputDriver):
del(self.uDevices[fd]) del(self.uDevices[fd])
except: except:
pass pass
self.updateMPiDevicesFD() try:
del(self.gDevices[fd])
except:
pass
self.MPiDevicesFD()
def hasIDevices(self): def hasIDevices(self):
if not self._initialized: if not self._initialized:

View File

@ -37,7 +37,7 @@ class driver(soundDriver):
word = word.replace('fenrirFreqDuration', str(duration)) word = word.replace('fenrirFreqDuration', str(duration))
word = word.replace('fenrirFrequence', str(frequence)) word = word.replace('fenrirFrequence', str(frequence))
popenFrequenceCommand[idx] = word popenFrequenceCommand[idx] = word
self.proc = subprocess.Popen(popenFrequenceCommand, shell=False) self.proc = subprocess.Popen(popenFrequenceCommand, stdin=None, stdout=None, stderr=None, shell=False)
self.soundType = 'frequence' self.soundType = 'frequence'
def playSoundFile(self, filePath, interrupt = True): def playSoundFile(self, filePath, interrupt = True):
if not self._initialized: if not self._initialized:

View File

@ -180,7 +180,7 @@ class driver(speechDriver):
try: try:
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + ' '.join(popenSpeechCommand),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + ' '.join(popenSpeechCommand),debug.debugLevel.INFO)
self.lock.acquire(True) self.lock.acquire(True)
self.proc = Popen(popenSpeechCommand, shell=False) self.proc = Popen(popenSpeechCommand, stdin=None, stdout=None, stderr=None, shell=False)
self.lock.release() self.lock.release()
self.proc.wait() self.proc.wait()
except Exception as e: except Exception as e: