Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4672b1d
fix malformed newline character
feerrenrut Jun 6, 2019
112f0ff
Python3: Convert braille driver framework.
feerrenrut Jun 12, 2019
d877c3a
Python3: Convert alva driver
feerrenrut Jun 12, 2019
688057b
Python3: Convert baum driver
feerrenrut Jun 12, 2019
fb39141
Python3: Convert BrailleNote driver
feerrenrut Jun 12, 2019
536fa09
Python3: Convert BrailliantB driver
feerrenrut Jun 12, 2019
ed55954
Python3: Convert ecoBraille driver
feerrenrut Jun 12, 2019
c654225
Python3: Convert eurobraille driver
feerrenrut Jun 12, 2019
b904901
Python3: Convert seika driver
feerrenrut Jun 13, 2019
08304c4
Python3: Convert superBrl driver
feerrenrut Jun 13, 2019
dc68c42
Python3: Convert freedomScientific driver
feerrenrut Jun 13, 2019
185b064
Python3: Convert handyTech driver
feerrenrut Jun 13, 2019
731c1d5
Python3: Convert hedoMobilLine driver
feerrenrut Jun 14, 2019
7d4e980
Convert hedoProfiLine driver
feerrenrut Jun 14, 2019
e52f144
Convert hims driver
feerrenrut Jun 14, 2019
9562796
Convert lilli driver
feerrenrut Jun 14, 2019
07d6718
Convert papenmeier driver
feerrenrut Jun 17, 2019
bdea5d3
Move Input gesture functions in papenmeier driver
feerrenrut Jun 17, 2019
e582be0
Convert papenmeier serial driver
feerrenrut Jun 17, 2019
27536ec
Review actions
feerrenrut Jun 21, 2019
e9a81c9
Fixes/improvements to hwIo and fixes to handy tech driver
Jun 24, 2019
cec75ad
Merge remote-tracking branch 'origin/threshold_py3_staging' into pyth…
Jun 26, 2019
f3c1913
Create a buffer manually for writes to HID devices
feerrenrut Jun 26, 2019
96ebd6e
Merge branch 'driverFixes' of https://github.com/BabbageCom/nvda into…
feerrenrut Jun 27, 2019
f9b5215
Further review actions:
feerrenrut Jun 27, 2019
8bced00
Baum: Change if to elif, add more debug info
Jun 27, 2019
128bc1e
add type hints to brailleInput.py
feerrenrut Jun 28, 2019
48a3e1f
Merge remote-tracking branch 'origin/threshold_py3_staging' into pyth…
feerrenrut Jun 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/bdDetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def addUsbDevices(driver, type, ids):
@type ids: set of str
@raise ValueError: When one of the provided IDs is malformed.
"""
malformedIds = [id for id in ids if not isinstance(id, basestring) or not USB_ID_REGEX.match(id)]
malformedIds = [id for id in ids if not isinstance(id, str) or not USB_ID_REGEX.match(id)]
if malformedIds:
raise ValueError("Invalid IDs provided for driver %s, type %s: %s"
% (driver, type, ", ".join(wrongIds)))
% (driver, type, u", ".join(malformedIds)))
devs = _getDriver(driver)
driverUsb = devs[type]
driverUsb.update(ids)
Expand Down
3 changes: 1 addition & 2 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#See the file COPYING for more details.
#Copyright (C) 2008-2018 NV Access Limited, Joseph Lee, Babbage B.V., Davy Kager, Bram Duvigneau

import sys
import itertools
import os
import driverHandler
Expand Down Expand Up @@ -1553,7 +1552,7 @@ class BrailleHandler(baseObject.AutoPropertyObject):

def __init__(self):
louisHelper.initialize()
self.display = None
self.display = None # BrailleDisplayDriver
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
self.displaySize = 0
self.mainBuffer = BrailleBuffer(self)
self.messageBuffer = BrailleBuffer(self)
Expand Down
162 changes: 100 additions & 62 deletions source/brailleDisplayDrivers/alva.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2009-2018 NV Access Limited, Davy Kager, Leonard de Ruijter, Optelec B.V.
import sys
from typing import List

import serial
import bdDetect
import braille
from logHandler import log
import inputCore
import brailleInput
import hwIo
from collections import OrderedDict
from hwIo import intToByte, boolToByte, getByte
from globalCommands import SCRCAT_BRAILLE
import ui
from baseObject import ScriptableObject
Expand Down Expand Up @@ -204,35 +205,48 @@ def terminate(self):
# We must sleep after closing the COM port, as it takes some time for the device to disconnect.
time.sleep(self.timeout)

def _ser6SendMessage(self, cmd, value=""):
if isinstance(value, (int, bool)):
value = chr(value)
self._dev.write(b"\x1b{cmd}{value}".format(cmd=cmd, value=value,))
def _ser6SendMessage(self, cmd: bytes, value: bytes = b"") -> None:
if not isinstance(value, bytes):
raise TypeError("Expected param 'value' to have type 'bytes'")
self._dev.write(b"".join(["\x1b", cmd, value]))

def _ser6OnReceive(self, data):
if data != b"\x1b": # Escape
def _ser6OnReceive(self, data: bytes):
"""
@type data: bytes
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
"""
if data != b"\x1b": # Escape
return
cmd = self._dev.read(1)
value = self._dev.read(ALVA_SER_CMD_LENGTHS[cmd])

if cmd == b"K": # Input
self._handleInput(ord(value[0]), ord(value[1]))
elif cmd == b"E": # Braille cell count
self.numCells = ord(value)
elif cmd == b"?": # Device ID
self._deviceId = ord(value)
elif cmd == b"r": # Raw keyboard messages enable/disable
self._rawKeyboardInput = bool(ord(value))
elif cmd == b"H": # Time
value: bytes = self._dev.read(ALVA_SER_CMD_LENGTHS[cmd])

if cmd == b"K": # Input
self._handleInput(group=value[0], number=value[1])
elif cmd == b"E": # Braille cell count
self.numCells = ord(value) # this command only gets one byte
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
elif cmd == b"?": # Device ID
self._deviceId = ord(value) # this command only gets one byte
elif cmd == b"r": # Raw keyboard messages enable/disable
self._rawKeyboardInput = bool(ord(value)) # this command only gets one byte
elif cmd == b"H": # Time
# Handling time for serial displays does not block initialization if it fails.
self._handleTime(value)

def _hidOnReceive(self, data):
def _hidOnReceive(self, data: bytes):
"""
@type data: bytes
"""
reportID = data[0]
if reportID == ALVA_KEY_REPORT:
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
self._handleInput(ord(data[ALVA_KEY_REPORT_KEY_GROUP_POS]), ord(data[ALVA_KEY_REPORT_KEY_POS]))
self._handleInput(
data[ALVA_KEY_REPORT_KEY_GROUP_POS],
data[ALVA_KEY_REPORT_KEY_POS]
)

def _handleInput(self, group, number):
def _handleInput(self, group: int, number: int) -> None:
"""
@type group: int
@type number: int
"""
if group == ALVA_SPECIAL_KEYS_GROUP:
# ALVA displays communicate setting changes as input messages.
if number == ALVA_SPECIAL_SETTINGS_CHANGED:
Expand All @@ -258,44 +272,59 @@ def _handleInput(self, group, number):
# This begins a new key combination.
self._ignoreKeyReleases = False

def _hidDisplay(self, cells):
for offset in range(0, len(cells), ALVA_BRAILLE_OUTPUT_MAX_SIZE):
cellsToWrite = cells[offset:offset+ALVA_BRAILLE_OUTPUT_MAX_SIZE]
self._dev.write("{id}{offset}{count}{cells}".format(
id=ALVA_BRAILLE_OUTPUT_REPORT,
offset=chr(offset),
count=chr(len(cellsToWrite)),
cells=cellsToWrite
))

def _ser6Display(self, cells):
self._ser6SendMessage(b"B", chr(0)+chr(len(cells))+cells)

def display(self, cells):
def _hidDisplay(self, cellBytes: bytes) -> None:
for offset in range(0, len(cellBytes), ALVA_BRAILLE_OUTPUT_MAX_SIZE):
cellsToWrite = cellBytes[offset:offset+ALVA_BRAILLE_OUTPUT_MAX_SIZE]
data = b"".join([
ALVA_BRAILLE_OUTPUT_REPORT,
intToByte(offset),
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
intToByte(len(cellsToWrite)),
cellsToWrite
])
self._dev.write(data)

def _ser6Display(self, cellBytes: bytes) -> None:
if not isinstance(cellBytes, bytes):
raise TypeError("Expected param 'cells' to be of type 'bytes'")
value = b"".join([
b"\x00",
intToByte(len(cellBytes)),
cellBytes
])
self._ser6SendMessage(b"B", value)

def display(self, cells: List[int]):
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
"""
@type cells: [int, ...]
"""
# cells will already be padded up to numCells.
cells = b"".join(map(chr, cells))
cellBytes = b"".join(
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
intToByte(cell) for cell in cells
)
if self.isHid:
self._hidDisplay(cells)
self._hidDisplay(cellBytes)
else:
self._ser6Display(cells)
self._ser6Display(cellBytes)

def _handleTime(self, timeStr):
ords = map(ord, timeStr)
year=ords[0] | ords[1] << 8
def _handleTime(self, time: bytes):
"""
@type time: bytes
"""
year = time[0] | time[1] << 8
if not ALVA_RTC_MIN_YEAR <= year <= ALVA_RTC_MAX_YEAR:
log.debug("This ALVA display doesn't reveal clock information")
return
try:
displayDateTime = datetime.datetime(
year=year,
month=ords[2],
day=ords[3],
hour=ords[4],
minute=ords[5],
second=ords[6]
month=time[2],
day=time[3],
hour=time[4],
minute=time[5],
second=time[6]
)
except ValueError:
log.debugWarning("Invalid time/date of ALVA display: %r"%timeStr)
log.debugWarning("Invalid time/date of ALVA display: %r" % time)
return
localDateTime = datetime.datetime.today()
if abs((displayDateTime - localDateTime).total_seconds()) >= ALVA_RTC_MAX_DRIFT:
Expand All @@ -304,14 +333,17 @@ def _handleTime(self, timeStr):
else:
log.debug("Time not synchronized. Display time %s"%displayDateTime.isoformat())

def _syncTime(self, dt):
def _syncTime(self, dt: datetime.datetime):
log.debug("Synchronizing braille display date and time...")
timeList = [
Comment thread
feerrenrut marked this conversation as resolved.
Resolved
dt.year & 0xFF, dt.year >> 8,
dt.month, dt.day,
dt.hour, dt.minute, dt.second
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second
]
timeStr = b"".join(map(chr, timeList))
timeStr = b"".join(intToByte(i) for i in timeList)
if self.isHid:
self._dev.setFeature(ALVA_RTC_REPORT + timeStr)
else:
Expand All @@ -324,22 +356,29 @@ def _set_hidKeyboardInput(self, state):
rawState = not state
if self.isHid:
# Make sure the device settings are up to date.
keySettings = self._dev.getFeature(ALVA_KEY_SETTINGS_REPORT)[ALVA_KEY_SETTINGS_POS]
keySettings: int = self._dev.getFeature(
ALVA_KEY_SETTINGS_REPORT
)[ALVA_KEY_SETTINGS_POS]
# Try to update the state
if rawState:
newKeySettings = chr(ord(keySettings) | ALVA_KEY_RAW_INPUT_MASK)
elif ord(keySettings) & ALVA_KEY_RAW_INPUT_MASK:
newKeySettings = chr(ord(keySettings) ^ ALVA_KEY_RAW_INPUT_MASK)
newKeySettings = intToByte(keySettings | ALVA_KEY_RAW_INPUT_MASK)
elif keySettings & ALVA_KEY_RAW_INPUT_MASK:
newKeySettings = intToByte(keySettings ^ ALVA_KEY_RAW_INPUT_MASK)
else:
newKeySettings = keySettings
newKeySettings = intToByte(keySettings)
self._dev.setFeature(ALVA_KEY_SETTINGS_REPORT + newKeySettings)
# Check whether the state has been changed successfully.
# If not, this device does not support this feature.
keySettings = self._dev.getFeature(ALVA_KEY_SETTINGS_REPORT)[ALVA_KEY_SETTINGS_POS]
keySettings: int = self._dev.getFeature(
ALVA_KEY_SETTINGS_REPORT
)[ALVA_KEY_SETTINGS_POS]
# Save the new state
self._rawKeyboardInput = bool(ord(keySettings) & ALVA_KEY_RAW_INPUT_MASK)
self._rawKeyboardInput = bool(keySettings & ALVA_KEY_RAW_INPUT_MASK)
else:
self._ser6SendMessage(b"r", rawState)
self._ser6SendMessage(
cmd=b"r",
value=boolToByte(rawState)
)
self._ser6SendMessage(b"r", b"?")
for i in range(3):
self._dev.waitForRead(self.timeout)
Expand Down Expand Up @@ -416,8 +455,7 @@ def __init__(self, model, keys, brailleInput=False):
assert(self.model.isalnum())
self.keyCodes = set(keys)
self.keyNames = names = []
if isNoBC640:
secondaryNames = []
secondaryNames = []
dots = 0
space = False
for group, number in self.keyCodes:
Expand Down
Loading