Skip to content

Commit 99611c1

Browse files
authored
Merge edcfe14 into 4bab722
2 parents 4bab722 + edcfe14 commit 99611c1

20 files changed

Lines changed: 278 additions & 142 deletions

source/bdDetect.py

Lines changed: 162 additions & 65 deletions
Large diffs are not rendered by default.

source/braille.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ def _getTryPorts(
35173517
pass
35183518
else:
35193519
yield bdDetect.DeviceMatch(
3520-
bdDetect.DeviceType.SERIAL,
3520+
bdDetect.ProtocolType.SERIAL,
35213521
portInfo["bluetoothName" if "bluetoothName" in portInfo else "friendlyName"],
35223522
portInfo["port"],
35233523
portInfo,

source/brailleDisplayDrivers/albatross/driver.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import time
1313

1414
from collections import deque
15-
from bdDetect import DeviceType, DriverRegistrar
15+
from bdDetect import DriverRegistrar, ProtocolType
1616
from logHandler import log
1717
from serial.win32 import (
1818
PURGE_RXABORT,
@@ -84,11 +84,11 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):
8484

8585
@classmethod
8686
def registerAutomaticDetection(cls, driverRegistrar: DriverRegistrar):
87-
driverRegistrar.addUsbDevices(
88-
DeviceType.SERIAL,
89-
{
90-
"VID_0403&PID_6001", # Caiku Albatross 46/80
91-
},
87+
driverRegistrar.addUsbDevice(
88+
ProtocolType.SERIAL,
89+
VID_AND_PID, # Caiku Albatross 46/80
90+
# Filter for bus reported device description, which should be "Albatross Braille Display".
91+
matchFunc=lambda match: match.deviceInfo.get("busReportedDeviceDescription") == BUS_DEVICE_DESC,
9292
)
9393

9494
@classmethod
@@ -168,11 +168,6 @@ def _searchPorts(self, originalPort: str):
168168
"""
169169
for self._baudRate in BAUD_RATE:
170170
for portType, portId, port, portInfo in self._getTryPorts(originalPort):
171-
# Block port if its vid and pid are correct but bus reported
172-
# device description is not "Albatross Braille Display".
173-
if portId == VID_AND_PID and portInfo.get("busReportedDeviceDescription") != BUS_DEVICE_DESC:
174-
log.debug(f"port {port} blocked; port information: {portInfo}")
175-
continue
176171
# For reconnection
177172
self._currentPort = port
178173
self._tryToConnect = True

source/brailleDisplayDrivers/alva.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver, ScriptableObject):
158158
@classmethod
159159
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
160160
driverRegistrar.addUsbDevices(
161-
bdDetect.DeviceType.HID,
161+
bdDetect.ProtocolType.HID,
162162
{
163163
"VID_0798&PID_0640", # BC640
164164
"VID_0798&PID_0680", # BC680
@@ -216,7 +216,7 @@ def __init__(self, port="auto"):
216216
self._deviceId = None
217217

218218
for portType, portId, port, portInfo in self._getTryPorts(port):
219-
self.isHid = portType == bdDetect.DeviceType.HID
219+
self.isHid = portType == bdDetect.ProtocolType.HID
220220
# Try talking to the display.
221221
try:
222222
if self.isHid:

source/brailleDisplayDrivers/baum.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):
8484
@classmethod
8585
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
8686
driverRegistrar.addUsbDevices(
87-
bdDetect.DeviceType.HID,
87+
bdDetect.ProtocolType.HID,
8888
{
8989
"VID_0904&PID_3001", # RefreshaBraille 18
9090
"VID_0904&PID_6101", # VarioUltra 20
@@ -111,7 +111,7 @@ def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
111111
)
112112

113113
driverRegistrar.addUsbDevices(
114-
bdDetect.DeviceType.SERIAL,
114+
bdDetect.ProtocolType.SERIAL,
115115
{
116116
"VID_0403&PID_FE70", # Vario 40
117117
"VID_0403&PID_FE71", # PocketVario
@@ -164,7 +164,7 @@ def __init__(self, port="auto"):
164164
for portType, portId, port, portInfo in self._getTryPorts(port):
165165
# At this point, a port bound to this display has been found.
166166
# Try talking to the display.
167-
self.isHid = portType == bdDetect.DeviceType.HID
167+
self.isHid = portType == bdDetect.ProtocolType.HID
168168
try:
169169
if self.isHid:
170170
self._dev = hwIo.Hid(port, onReceive=self._onReceive)

source/brailleDisplayDrivers/brailleNote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):
130130
@classmethod
131131
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
132132
driverRegistrar.addUsbDevices(
133-
bdDetect.DeviceType.SERIAL,
133+
bdDetect.ProtocolType.SERIAL,
134134
{
135135
"VID_1C71&PID_C004", # Apex
136136
},

source/brailleDisplayDrivers/brailliantB.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
HR_KEYS = b"\x04"
3636
HR_BRAILLE = b"\x05"
3737
HR_POWEROFF = b"\x07"
38+
HID_USAGE_PAGE = 0x93
3839

3940
KEY_NAMES = {
4041
1: "power", # Brailliant BI 32, 40 and 80.
@@ -89,47 +90,61 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):
8990
@classmethod
9091
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
9192
driverRegistrar.addUsbDevices(
92-
bdDetect.DeviceType.HID,
93+
bdDetect.ProtocolType.HID,
9394
{
9495
"VID_1C71&PID_C111", # Mantis Q 40
9596
"VID_1C71&PID_C101", # Chameleon 20
97+
"VID_1C71&PID_C131", # Brailliant BI 40X
98+
"VID_1C71&PID_C141", # Brailliant BI 20X
99+
},
100+
matchFunc=bdDetect.HIDUsagePageMatchFuncFactory(HID_USAGE_PAGE),
101+
)
102+
driverRegistrar.addUsbDevices(
103+
bdDetect.ProtocolType.HID,
104+
{
96105
"VID_1C71&PID_C121", # Humanware BrailleOne 20 HID
97106
"VID_1C71&PID_CE01", # NLS eReader 20 HID
98107
"VID_1C71&PID_C006", # Brailliant BI 32, 40 and 80
99108
"VID_1C71&PID_C022", # Brailliant BI 14
100-
"VID_1C71&PID_C131", # Brailliant BI 40X
101-
"VID_1C71&PID_C141", # Brailliant BI 20X
102109
"VID_1C71&PID_C00A", # BrailleNote Touch
103110
"VID_1C71&PID_C00E", # BrailleNote Touch v2
104111
},
105112
)
106113
driverRegistrar.addUsbDevices(
107-
bdDetect.DeviceType.SERIAL,
114+
bdDetect.ProtocolType.SERIAL,
108115
{
109116
"VID_1C71&PID_C005", # Brailliant BI 32, 40 and 80
110117
"VID_1C71&PID_C021", # Brailliant BI 14
111118
},
112119
)
113120
driverRegistrar.addBluetoothDevices(
114121
lambda m: (
115-
m.type == bdDetect.DeviceType.SERIAL
122+
m.type == bdDetect.ProtocolType.SERIAL
116123
and (
117124
m.id.startswith("Brailliant B") or m.id == "Brailliant 80" or "BrailleNote Touch" in m.id
118125
)
119126
)
120127
or (
121-
m.type == bdDetect.DeviceType.HID
128+
m.type == bdDetect.ProtocolType.HID
122129
and m.deviceInfo.get("manufacturer") == "Humanware"
123-
and m.deviceInfo.get("product")
124-
in (
125-
"Brailliant HID",
126-
"APH Chameleon 20",
127-
"APH Mantis Q40",
128-
"Humanware BrailleOne",
129-
"NLS eReader",
130-
"NLS eReader Humanware",
131-
"Brailliant BI 40X",
132-
"Brailliant BI 20X",
130+
and (
131+
(
132+
m.deviceInfo.get("product")
133+
in (
134+
"APH Chameleon 20",
135+
"APH Mantis Q40",
136+
"Brailliant BI 40X",
137+
"Brailliant BI 20X",
138+
)
139+
and bdDetect._isHIDUsagePageMatch(m, HID_USAGE_PAGE)
140+
)
141+
or m.deviceInfo.get("product")
142+
in (
143+
"Brailliant HID",
144+
"Humanware BrailleOne",
145+
"NLS eReader",
146+
"NLS eReader Humanware",
147+
)
133148
)
134149
),
135150
)
@@ -143,10 +158,13 @@ def __init__(self, port="auto"):
143158
self.numCells = 0
144159

145160
for portType, portId, port, portInfo in self._getTryPorts(port):
146-
self.isHid = portType == bdDetect.DeviceType.HID
161+
self.isHid = portType == bdDetect.ProtocolType.HID
147162
# Try talking to the display.
148163
try:
149164
if self.isHid:
165+
if (usasePage := portInfo.get("HIDUsagePage")) != HID_USAGE_PAGE:
166+
log.debugWarning(f"Ignoring device {port!r} with usage page {usasePage!r}")
167+
continue
150168
self._dev = hwIo.Hid(port, onReceive=self._hidOnReceive)
151169
else:
152170
self._dev = hwIo.Serial(

source/brailleDisplayDrivers/eurobraille/driver.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver, ScriptableObject):
4545
@classmethod
4646
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
4747
driverRegistrar.addUsbDevices(
48-
bdDetect.DeviceType.HID,
48+
bdDetect.ProtocolType.HID,
4949
{
5050
"VID_C251&PID_1122", # Esys (version < 3.0, no SD card
5151
"VID_C251&PID_1123", # Esys (version >= 3.0, with HID keyboard, no SD card
@@ -67,7 +67,7 @@ def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
6767
},
6868
)
6969
driverRegistrar.addUsbDevices(
70-
bdDetect.DeviceType.SERIAL,
70+
bdDetect.ProtocolType.SERIAL,
7171
{
7272
"VID_28AC&PID_0012", # b.note
7373
"VID_28AC&PID_0013", # b.note 2
@@ -97,7 +97,7 @@ def __init__(self, port="Auto"):
9797
for portType, portId, port, portInfo in self._getTryPorts(port):
9898
# At this point, a port bound to this display has been found.
9999
# Try talking to the display.
100-
self.isHid = portType == bdDetect.DeviceType.HID
100+
self.isHid = portType == bdDetect.ProtocolType.HID
101101
try:
102102
if self.isHid:
103103
self._dev = hwIo.Hid(
@@ -141,7 +141,7 @@ def __init__(self, port="Auto"):
141141
port=port,
142142
),
143143
)
144-
if self.deviceType.startswith(("bnote", "bbook")):
144+
if self.deviceType.startswith(("bnote", "bbook")):
145145
# send identifier to bnote / bbook with current COM port
146146
comportNumber = f'{int(re.match(".*?([0-9]+)$", port).group(1)):02d}'
147147
identifier = f"NVDA/{comportNumber}".encode()
@@ -158,7 +158,7 @@ def __init__(self, port="Auto"):
158158

159159
def terminate(self):
160160
try:
161-
if self.deviceType.startswith(("bnote", "bbook")):
161+
if self.deviceType.startswith(("bnote", "bbook")):
162162
# reset identifier to bnote / bbook with current COM port
163163
self._sendPacket(constants.EB_SYSTEM, constants.EB_CONNECTION_NAME, b"")
164164
super().terminate()
@@ -287,7 +287,7 @@ def _handleKeyPacket(self, group: bytes, data: bytes):
287287
log.debug("Ignoring key repetition")
288288
return
289289
self.keysDown[group] |= arg
290-
isIris = self.deviceType.startswith("Iris")
290+
isIris = self.ProtocolType.startswith("Iris")
291291
if not isIris and group == constants.EB_KEY_COMMAND and arg >= self.keysDown[group]:
292292
# Started a gesture including command keys
293293
self._ignoreCommandKeyReleases = False

source/brailleDisplayDrivers/eurobraille/gestures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class InputGesture(braille.BrailleDisplayGesture, brailleInput.BrailleInputGestu
162162

163163
def __init__(self, display: "BrailleDisplayDriver"):
164164
super().__init__()
165-
self.model = display.deviceType.lower().split(" ")[0]
165+
self.model = display.ProtocolType.lower().split(" ")[0]
166166
keysDown = dict(display.keysDown)
167167

168168
self.keyNames = names = []

source/brailleDisplayDrivers/freedomScientific.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver, ScriptableObject):
199199
@classmethod
200200
def registerAutomaticDetection(cls, driverRegistrar: bdDetect.DriverRegistrar):
201201
driverRegistrar.addUsbDevices(
202-
bdDetect.DeviceType.CUSTOM,
202+
bdDetect.ProtocolType.CUSTOM,
203203
{
204204
"VID_0F4E&PID_0100", # Focus 1
205205
"VID_0F4E&PID_0111", # PAC Mate
@@ -243,7 +243,7 @@ def __init__(self, port="auto"):
243243
self.gestureMap.add("br(freedomScientific):rightWizWheelDown", *action[2])
244244
super(BrailleDisplayDriver, self).__init__()
245245
for portType, portId, port, portInfo in self._getTryPorts(port):
246-
self.isUsb = portType == bdDetect.DeviceType.CUSTOM
246+
self.isUsb = portType == bdDetect.ProtocolType.CUSTOM
247247
# Try talking to the display.
248248
try:
249249
if self.isUsb:

0 commit comments

Comments
 (0)