Skip to content

Commit c8b6d56

Browse files
authored
Merge df3ce9d into 23e3c9c
2 parents 23e3c9c + df3ce9d commit c8b6d56

3 files changed

Lines changed: 67 additions & 29 deletions

File tree

source/bdDetect.py

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,50 +114,80 @@ def getDriversForConnectedUsbDevices():
114114
@return: Pairs of drivers and device information.
115115
@rtype: generator of (str, L{DeviceMatch}) tuples
116116
"""
117-
usbDevs = itertools.chain(
118-
(DeviceMatch(KEY_CUSTOM, port["usbID"], port["devicePath"], port)
119-
for port in deviceInfoFetcher.usbDevices),
120-
(DeviceMatch(KEY_HID, port["usbID"], port["devicePath"], port)
121-
for port in deviceInfoFetcher.hidDevices if port["provider"]=="usb"),
122-
(DeviceMatch(KEY_SERIAL, port["usbID"], port["port"], port)
123-
for port in deviceInfoFetcher.comPorts if "usbID" in port)
117+
usbCustomDeviceMatches = (
118+
DeviceMatch(KEY_CUSTOM, port["usbID"], port["devicePath"], port)
119+
for port in deviceInfoFetcher.usbDevices
124120
)
125-
for match in usbDevs:
121+
usbComDeviceMatches = (
122+
DeviceMatch(KEY_SERIAL, port["usbID"], port["port"], port)
123+
for port in deviceInfoFetcher.comPorts
124+
if "usbID" in port
125+
)
126+
usbHidDeviceMatches, usbHidDeviceMatchesForCustom = itertools.tee((
127+
DeviceMatch(KEY_HID, port["usbID"], port["devicePath"], port)
128+
for port in deviceInfoFetcher.hidDevices
129+
if port["provider"] == "usb"
130+
))
131+
for match in itertools.chain(usbCustomDeviceMatches, usbHidDeviceMatchesForCustom, usbComDeviceMatches):
126132
for driver, devs in _driverDevices.items():
127133
for type, ids in devs.items():
128134
if match.type==type and match.id in ids:
129135
yield driver, match
136+
137+
for match in usbHidDeviceMatches:
130138
# Check for the Braille HID protocol after any other device matching.
131139
# This ensures that a vendor specific driver is preferred over the braille HID protocol.
132140
# This preference may change in the future.
133-
if match.type == KEY_HID and match.deviceInfo.get('HIDUsagePage') == HID_USAGE_PAGE_BRAILLE:
134-
yield ("hid", match)
141+
if _isHIDBrailleMatch(match):
142+
yield (
143+
_getStandardHidDriverName(),
144+
match
145+
)
146+
147+
148+
def _getStandardHidDriverName() -> str:
149+
"""Return the name of the standard HID Braille device driver
150+
"""
151+
import brailleDisplayDrivers.hidBrailleStandard
152+
return brailleDisplayDrivers.hidBrailleStandard.HidBrailleDriver.name
153+
154+
155+
def _isHIDBrailleMatch(match: DeviceMatch) -> bool:
156+
return match.type == KEY_HID and match.deviceInfo.get('HIDUsagePage') == HID_USAGE_PAGE_BRAILLE
135157

136158

137159
def getDriversForPossibleBluetoothDevices():
138160
"""Get any matching drivers for possible Bluetooth devices.
139161
@return: Pairs of drivers and port information.
140162
@rtype: generator of (str, L{DeviceMatch}) tuples
141163
"""
142-
btDevs = itertools.chain(
143-
(DeviceMatch(KEY_SERIAL, port["bluetoothName"], port["port"], port)
144-
for port in deviceInfoFetcher.comPorts
145-
if "bluetoothName" in port),
146-
(DeviceMatch(KEY_HID, port["hardwareID"], port["devicePath"], port)
147-
for port in deviceInfoFetcher.hidDevices if port["provider"]=="bluetooth"),
164+
btSerialMatchesForCustom = (
165+
DeviceMatch(KEY_SERIAL, port["bluetoothName"], port["port"], port)
166+
for port in deviceInfoFetcher.comPorts
167+
if "bluetoothName" in port
148168
)
149-
for match in btDevs:
169+
btHidDevMatchesForHid, btHidDevMatchesForCustom = itertools.tee((
170+
DeviceMatch(KEY_HID, port["hardwareID"], port["devicePath"], port)
171+
for port in deviceInfoFetcher.hidDevices
172+
if port["provider"] == "bluetooth"
173+
))
174+
for match in itertools.chain(btSerialMatchesForCustom, btHidDevMatchesForCustom):
150175
for driver, devs in _driverDevices.items():
151176
matchFunc = devs[KEY_BLUETOOTH]
152177
if not callable(matchFunc):
153178
continue
154179
if matchFunc(match):
155180
yield driver, match
181+
182+
for match in btHidDevMatchesForHid:
156183
# Check for the Braille HID protocol after any other device matching.
157184
# This ensures that a vendor specific driver is preferred over the braille HID protocol.
158185
# This preference may change in the future.
159-
if match.type == KEY_HID and match.deviceInfo.get('HIDUsagePage') == HID_USAGE_PAGE_BRAILLE:
160-
yield ("hid", match)
186+
if _isHIDBrailleMatch(match):
187+
yield (
188+
_getStandardHidDriverName(),
189+
match
190+
)
161191

162192

163193
class _DeviceInfoFetcher(AutoPropertyObject):
@@ -349,8 +379,8 @@ def getConnectedUsbDevicesForDriver(driver) -> Iterable[DeviceMatch]:
349379
for port in deviceInfoFetcher.comPorts if "usbID" in port)
350380
)
351381
for match in usbDevs:
352-
if driver == "hid":
353-
if match.type == KEY_HID and match.deviceInfo.get('HIDUsagePage') == HID_USAGE_PAGE_BRAILLE:
382+
if driver == _getStandardHidDriverName():
383+
if _isHIDBrailleMatch(match):
354384
yield match
355385
else:
356386
devs = _driverDevices[driver]
@@ -365,9 +395,9 @@ def getPossibleBluetoothDevicesForDriver(driver) -> Iterable[DeviceMatch]:
365395
@return: Port information for each port.
366396
@raise LookupError: If there is no detection data for this driver.
367397
"""
368-
if driver == "hid":
398+
if driver == _getStandardHidDriverName():
369399
def matchFunc(match):
370-
return match.type == KEY_HID and match.deviceInfo.get('HIDUsagePage') == HID_USAGE_PAGE_BRAILLE
400+
return _isHIDBrailleMatch(match)
371401
else:
372402
matchFunc = _driverDevices[driver][KEY_BLUETOOTH]
373403
if not callable(matchFunc):

source/braille.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,10 +2258,15 @@ def func(cls):
22582258
if cls.exit:
22592259
break
22602260

2261-
#: Maps old braille display driver names to new drivers that supersede old drivers.
2261+
2262+
# Maps old braille display driver names to new drivers that supersede old drivers.
2263+
# Ensure that if a user has set a preferred driver which has changed name, the new
2264+
# user preference is retained.
22622265
RENAMED_DRIVERS = {
2263-
"syncBraille":"hims",
2264-
"alvaBC6":"alva"
2266+
# "oldDriverName": "newDriverName"
2267+
"syncBraille": "hims",
2268+
"alvaBC6": "alva",
2269+
"hid": "hidBrailleStandard",
22652270
}
22662271

22672272
handler: BrailleHandler

source/brailleDisplayDrivers/hid.py renamed to source/brailleDisplayDrivers/hidBrailleStandard.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class ButtonCapsInfo:
7171
relativeIndexInCollection: int = 0
7272

7373

74-
class BrailleDisplayDriver(braille.BrailleDisplayDriver):
74+
class HidBrailleDriver(braille.BrailleDisplayDriver):
7575
_dev: hwIo.hid.Hid
76-
name = "hid"
76+
name = "hidBrailleStandard"
7777
# Translators: The name of a series of braille displays.
7878
description = _("Standard HID Braille Display")
7979
isThreadSafe = True
@@ -235,7 +235,7 @@ def display(self, cells: List[int]):
235235

236236
class InputGesture(braille.BrailleDisplayGesture, brailleInput.BrailleInputGesture):
237237

238-
source = BrailleDisplayDriver.name
238+
source = HidBrailleDriver.name
239239

240240
def __init__(self, driver, dataIndices):
241241
super().__init__()
@@ -307,3 +307,6 @@ def _usageIDToGestureName(self, usagePage: int, usageID: int):
307307
# Join the words together as camelcase.
308308
name = "".join(wordList)
309309
return name
310+
311+
312+
BrailleDisplayDriver = HidBrailleDriver

0 commit comments

Comments
 (0)