Merge branch 'numlock' into bleed

This commit is contained in:
chrys 2018-06-29 00:39:07 +02:00
commit 9746471dc8
5 changed files with 50 additions and 70 deletions

View File

@ -1,16 +0,0 @@
Known Bugs (Problems with the logic ):
- word echo triggers twice if there are two spaces after an word and you arrow over them
- spellcheck triggers twice if there are two spaces after an word and you arrow over them
[] Sometimes Numblock hangs and make shortcuts not detect (critical) (workaround - press numlock again until shortcuts are working again)
[] Numlock/ Capslock is sometimes out of Sync (normal)
[] lag when stopping speech for speechd speech driver
[] lag when start speaking with generic speech driver
[W] setup.py fails on raspian
Glitches (improve diff results):
currently None
wishes:
- whole status line in irssi is spoken insteed of just the changes (lilmike)
- whole status line in vim is spoken insteed of just the changes (lilmike)

View File

@ -12,7 +12,6 @@ fenrirPath = os.path.dirname(currentdir)
class inputManager(): class inputManager():
def __init__(self): def __init__(self):
self.setLedState = True
self.shortcutType = 'KEY' self.shortcutType = 'KEY'
self.executeDeviceGrab = False self.executeDeviceGrab = False
def setShortcutType(self, shortcutType = 'KEY'): def setShortcutType(self, shortcutType = 'KEY'):
@ -63,8 +62,15 @@ class inputManager():
self.grabAllDevices() self.grabAllDevices()
self.executeDeviceGrab = False self.executeDeviceGrab = False
def handleInputEvent(self, eventData): def handleInputEvent(self, eventData):
#print(eventData)
if not eventData: if not eventData:
return return
# a hang apears.. try to fix
if self.env['input']['eventBuffer'] == []:
if self.env['input']['currInput'] != []:
self.env['input']['currInput'] = []
self.env['input']['shortcutRepeat'] = 1
self.env['input']['prevInput'] = self.env['input']['currInput'].copy() self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
if eventData['EventState'] == 0: if eventData['EventState'] == 0:
if eventData['EventName'] in self.env['input']['currInput']: if eventData['EventName'] in self.env['input']['currInput']:
@ -73,7 +79,6 @@ class inputManager():
self.env['input']['currInput'] = sorted(self.env['input']['currInput']) self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
elif len(self.env['input']['currInput']) == 0: elif len(self.env['input']['currInput']) == 0:
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.setLedState = self.handleLedStates(eventData)
self.lastInputTime = time.time() self.lastInputTime = time.time()
elif eventData['EventState'] == 1: elif eventData['EventState'] == 1:
if not eventData['EventName'] in self.env['input']['currInput']: if not eventData['EventName'] in self.env['input']['currInput']:
@ -87,7 +92,7 @@ class inputManager():
self.env['input']['shortcutRepeat'] += 1 self.env['input']['shortcutRepeat'] += 1
else: else:
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.setLedState = self.handleLedStates(eventData) self.handleLedStates(eventData)
self.lastInputTime = time.time() self.lastInputTime = time.time()
elif eventData['EventState'] == 2: elif eventData['EventState'] == 2:
self.lastInputTime = time.time() self.lastInputTime = time.time()
@ -101,35 +106,18 @@ class inputManager():
self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO)
if self.noKeyPressed(): if self.noKeyPressed():
self.env['input']['prevInput'] = [] self.env['input']['prevInput'] = []
self.setLedState = True
self.handleDeviceGrab() self.handleDeviceGrab()
def handleLedStates(self, mEvent): def handleLedStates(self, mEvent):
if not self.setLedState: try:
return self.setLedState if mEvent['EventName'] == 'KEY_NUMLOCK':
if mEvent['EventName'] == 'KEY_NUMLOCK': self.env['runtime']['inputDriver'].toggleLedState()
if mEvent['EventState'] == 1 and not self.env['input']['newNumLock'] == 1: elif mEvent['EventName'] == 'KEY_CAPSLOCK':
self.env['runtime']['inputDriver'].toggleLedState() self.env['runtime']['inputDriver'].toggleLedState(1)
return False elif mEvent['EventName'] == 'KEY_SCROLLLOCK':
if mEvent['EventState'] == 0 and not self.env['input']['newNumLock'] == 0: self.env['runtime']['inputDriver'].toggleLedState(2)
self.env['runtime']['inputDriver'].toggleLedState() except:
return False pass
if mEvent['EventName'] == 'KEY_CAPSLOCK':
if mEvent['EventState'] == 1 and not self.env['input']['newCapsLock'] == 1:
self.env['runtime']['inputDriver'].toggleLedState(1)
return False
if mEvent['EventState'] == 0 and not self.env['input']['newCapsLock'] == 0:
self.env['runtime']['inputDriver'].toggleLedState(1)
return False
if mEvent['EventName'] == 'KEY_SCROLLLOCK':
if mEvent['EventState'] == 1 and not self.env['input']['newScrollLock'] == 1:
self.env['runtime']['inputDriver'].toggleLedState(2)
return False
if mEvent['EventState'] == 0 and not self.env['input']['newScrollLock'] == 0:
self.env['runtime']['inputDriver'].toggleLedState(2)
return False
return self.setLedState
def grabAllDevices(self): def grabAllDevices(self):
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
try: try:

View File

@ -57,7 +57,8 @@ class punctuationManager():
else: else:
resultText = resultText.replace(str(key),' ' +str(item) + ' ') resultText = resultText.replace(str(key),' ' +str(item) + ' ')
return resultText return resultText
def isPuctuation(self, char):
return char in self.env['punctuation']['PUNCTDICT']
def proceedPunctuation(self, text, ignorePunctuation=False): def proceedPunctuation(self, text, ignorePunctuation=False):
resultText = text resultText = text
resultText = self.useCustomDict(resultText, self.env['punctuation']['CUSTOMDICT']) resultText = self.useCustomDict(resultText, self.env['punctuation']['CUSTOMDICT'])

View File

@ -31,6 +31,9 @@ class textManager():
newText += text[lastPos:span[0]] newText += text[lastPos:span[0]]
numberOfChars = len(text[span[0]:span[1]]) numberOfChars = len(text[span[0]:span[1]])
name = text[span[0]:span[1]][:2] name = text[span[0]:span[1]][:2]
if not self.env['runtime']['punctuationManager'].isPuctuation(name[0]):
lastPos = span[1]
continue
if name[0] == name[1]: if name[0] == name[1]:
newText += ' ' + str(numberOfChars) + ' ' + self.env['runtime']['punctuationManager'].proceedPunctuation(name[0], True) + ' ' newText += ' ' + str(numberOfChars) + ' ' + self.env['runtime']['punctuationManager'].proceedPunctuation(name[0], True) + ' '
else: else:
@ -45,6 +48,9 @@ class textManager():
result += text[lastPos:span[0]] result += text[lastPos:span[0]]
numberOfChars = len(newText[span[0]:span[1]]) numberOfChars = len(newText[span[0]:span[1]])
name = newText[span[0]:span[1]][:2] name = newText[span[0]:span[1]][:2]
if not self.env['runtime']['punctuationManager'].isPuctuation(name[0]):
lastPos = span[1]
continue
if name[0] == name[1]: if name[0] == name[1]:
result += ' ' + str(numberOfChars) + ' ' + self.env['runtime']['punctuationManager'].proceedPunctuation(name[0], True) + ' ' result += ' ' + str(numberOfChars) + ' ' + self.env['runtime']['punctuationManager'].proceedPunctuation(name[0], True) + ' '
else: else:

View File

@ -84,18 +84,16 @@ class driver(inputDriver):
if validDevices: if validDevices:
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":validDevices}) eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":validDevices})
return time.time() return time.time()
def plugInputDeviceWatchdogTimer(self, active):
time.sleep(10)
return None
def inputWatchdog(self,active , eventQueue): def inputWatchdog(self,active , eventQueue):
try: try:
while active.value: while active.value:
r, w, x = select(self.iDevices, [], [], 0.7) r, w, x = select(self.iDevices, [], [], 0.8)
for fd in r: event = None
event = None foundKeyInSequence = False
foreward = False foreward = False
eventFired = False eventFired = False
for fd in r:
try: try:
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
except: except:
@ -103,24 +101,26 @@ class driver(inputDriver):
while(event): while(event):
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])
if event.type == evdev.events.EV_KEY: if event.type == evdev.events.EV_KEY:
if not foundKeyInSequence:
foundKeyInSequence = True
if event.code != 0: if event.code != 0:
currMapEvent = self.mapEvent(event) currMapEvent = self.mapEvent(event)
if not currMapEvent: if not currMapEvent:
foreward = True continue
if not isinstance(currMapEvent['EventName'], str): if not isinstance(currMapEvent['EventName'], str):
foreward = True continue
if not foreward or eventFired: if currMapEvent['EventState'] in [0,1,2]:
if currMapEvent['EventState'] in [0,1,2]: eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()})
eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()}) eventFired = True
eventFired = True
else: else:
if not event.type in [0,4]: if event.type in [2,3]:
foreward = True foreward = True
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
if foreward and not eventFired: if not foundKeyInSequence:
self.writeEventBuffer() if foreward and not eventFired:
self.clearEventBuffer() self.writeEventBuffer()
self.clearEventBuffer()
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("INPUT WATCHDOG CRASH: "+str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("INPUT WATCHDOG CRASH: "+str(e),debug.debugLevel.ERROR)
@ -262,12 +262,13 @@ class driver(inputDriver):
return False return False
ledState = self.getLedState(led) ledState = self.getLedState(led)
for i in self.iDevices: for i in self.iDevices:
# 17 LEDs if self.gDevices[i]:
if 17 in self.iDevices[i].capabilities(): # 17 LEDs
if ledState == 1: if 17 in self.iDevices[i].capabilities():
self.iDevices[i].set_led(led , 0) if ledState == 1:
else: self.iDevices[i].set_led(led , 0)
self.iDevices[i].set_led(led , 1) else:
self.iDevices[i].set_led(led , 1)
def grabAllDevices(self): def grabAllDevices(self):
if not self._initialized: if not self._initialized:
return return