From c2d01cd78018ce6d2a8a63ddcd9113d164fd306f Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 6 Jul 2016 01:13:28 +0200 Subject: [PATCH] try out TTY detection --- TODO | 11 ++++++----- src/fenrir.py | 28 ++++++++++++++++++++++------ src/speech/sd.py | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index ce44d65d..505abdfd 100644 --- a/TODO +++ b/TODO @@ -11,11 +11,6 @@ http://serverfault.com/questions/306854/how-to-find-out-the-currently-active-lin http://mielke.cc/brltty/doc/Manual-BrlAPI/English/BrlAPI.html https://git.gnome.org/browse/orca/tree/src/orca/braille.py -- implement speechdriver speechd -https://git.gnome.org/browse/orca/tree/src/orca/speech.py -https://git.gnome.org/browse/orca/tree/src/orca/speechdispatcherfactory.py -http://devel.freebsoft.org/doc/speechd/speech-dispatcher.html#Client-Programming - - implement speechdriver generic (say) - threading ReadContent, ReadShortcuts, executeCommands, listenNewTTYsForListen, controllThread (main) - debugging @@ -45,3 +40,9 @@ it seems we have this info in vcsa - get current cursor +- implement speechdriver speechd +https://git.gnome.org/browse/orca/tree/src/orca/speech.py +https://git.gnome.org/browse/orca/tree/src/orca/speechdispatcherfactory.py +http://devel.freebsoft.org/doc/speechd/speech-dispatcher.html#Client-Programming + + diff --git a/src/fenrir.py b/src/fenrir.py index 41d6ec7d..5a6713c7 100755 --- a/src/fenrir.py +++ b/src/fenrir.py @@ -13,7 +13,7 @@ runtime = { 'running':True, 'columns': 0, 'lines': 0, -'screenDriver': '/dev/vcsa3', +'screenDriver': '/dev/vcsa', 'delta': '', 'oldCursor':{'x':0,'y':0}, 'oldContentBytes': b'', @@ -23,15 +23,25 @@ runtime = { 'newContentBytes': b'', 'newContentText': '', 'newContentAttrib': b'', +'oldTTY':'0', +'newTTY':'0', 'speechDriverString':'sd', 'speechDriver': sd.speech() } while(runtime['running']): # read screen - vcsa = open(runtime['screenDriver'],'rb') - runtime['newContentBytes'] = vcsa.read() - vcsa.close() + currTTY = open('/sys/devices/virtual/tty/tty0/active','r') + runtime['newTTY'] = currTTY.read()[3:-1] + currTTY.close() + runtime['newTTY'] = '3' + try: + vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb') + runtime['newContentBytes'] = vcsa.read() + vcsa.close() + except: + print(runtime['screenDriver'] + runtime['newTTY']) + continue # get metadata like cursor or screensize runtime['lines'] = int( runtime['newContentBytes'][0]) @@ -43,7 +53,13 @@ while(runtime['running']): runtime['newContentText'] = str(runtime['newContentBytes'][4:][::2].decode('cp1252').encode('utf-8')) runtime['newContentAttrib'] = runtime['newContentBytes'][5:][::2] runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns'])) - + if runtime['newTTY'] != runtime['oldTTY']: + runtime['oldContentBytes'] = b'' + runtime['oldContentAttrib'] = b'' + runtime['oldContentText'] = '' + runtime['oldCursor']['x'] = 0 + runtime['oldCursor']['y'] = 0 + # changes on the screen if runtime['oldContentBytes'] != runtime['newContentBytes']: if len(runtime['delta']) < 3: @@ -62,4 +78,4 @@ while(runtime['running']): runtime['oldContentTextAttrib'] = runtime['newContentAttrib'] runtime['oldCursor']['x'] = runtime['newCursor']['x'] runtime['oldCursor']['y'] = runtime['newCursor']['y'] - + runtime['oldTTY'] = runtime['newTTY'] diff --git a/src/speech/sd.py b/src/speech/sd.py index b17532b8..4fb37796 100644 --- a/src/speech/sd.py +++ b/src/speech/sd.py @@ -63,7 +63,7 @@ class speech(): if not self.isInitialized: return False try: - self.sd..set_output_module(module) + self.sd.set_output_module(module) return True except: return False