Improvements to braill driver.

This commit is contained in:
Storm Dragon 2024-12-05 15:06:47 -05:00
parent b54a226833
commit bc72765544

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors. # By Chrys, Storm Dragon, and contributors.
@ -9,9 +9,9 @@ from fenrirscreenreader.core import debug
class brailleDriver(): class brailleDriver():
def __init__(self): def __init__(self):
self._isInitialized = False self._isInitialized = False
self.deviceSize = None
self._brl = None self._brl = None
self.deviceSize = None
def initialize(self, environment): def initialize(self, environment):
"""Initialize the BRLTTY connection.""" """Initialize the BRLTTY connection."""
self.env = environment self.env = environment
@ -36,22 +36,19 @@ class brailleDriver():
if not self._isInitialized: if not self._isInitialized:
return return
try: try:
# Ensure text doesn't exceed display width
if self.deviceSize:
text = text[:self.deviceSize[0]]
self._brl.writeText(text) self._brl.writeText(text)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('ERROR: Writing braille failed:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('ERROR: Writing braille failed:' + str(e),debug.debugLevel.ERROR)
def connectDevice(self): def readKeypress(self):
"""Attempt to connect to the braille device.""" """Read a keypress from the braille display."""
if not self._isInitialized:
return None
try: try:
if self._brl: return self._brl.readKey(wait=0)
self._brl.enterTtyMode()
return True
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('ERROR: Connecting braille failed:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('ERROR: Reading key failed:' + str(e),debug.debugLevel.ERROR)
return False return None
def enterScreen(self, screen): def enterScreen(self, screen):
"""Enter a new screen context.""" """Enter a new screen context."""