Skip to content

Commit

Permalink
Add setting to disable standard hid braille (PR #13180)
Browse files Browse the repository at this point in the history
* add setting to disable HID Braille
  • Loading branch information
feerrenrut committed Dec 20, 2021
1 parent 029b7be commit 952d28b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 22 deletions.
57 changes: 35 additions & 22 deletions source/bdDetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
"""

import itertools
import typing
from collections import namedtuple, defaultdict, OrderedDict
import threading
from typing import Iterable

import typing
import wx
Expand Down Expand Up @@ -143,15 +141,16 @@ def getDriversForConnectedUsbDevices() -> typing.Iterator[typing.Tuple[str, Devi
if match.type==type and match.id in ids:
yield driver, match

for match in usbHidDeviceMatches:
# Check for the Braille HID protocol after any other device matching.
# This ensures that a vendor specific driver is preferred over the braille HID protocol.
# This preference may change in the future.
if _isHIDBrailleMatch(match):
yield (
_getStandardHidDriverName(),
match
)
if _isHidBrailleStandardSupported():
for match in usbHidDeviceMatches:
# Check for the Braille HID protocol after any other device matching.
# This ensures that a vendor specific driver is preferred over the braille HID protocol.
# This preference may change in the future.
if _isHIDBrailleMatch(match):
yield (
_getStandardHidDriverName(),
match
)


def _getStandardHidDriverName() -> str:
Expand All @@ -161,6 +160,12 @@ def _getStandardHidDriverName() -> str:
return brailleDisplayDrivers.hidBrailleStandard.HidBrailleDriver.name


def _isHidBrailleStandardSupported() -> bool:
"""Check if standard HID braille is supported"""
import brailleDisplayDrivers.hidBrailleStandard
return brailleDisplayDrivers.hidBrailleStandard.isSupportEnabled()


def _isHIDBrailleMatch(match: DeviceMatch) -> bool:
return match.type == KEY_HID and match.deviceInfo.get('HIDUsagePage') == HID_USAGE_PAGE_BRAILLE

Expand Down Expand Up @@ -194,15 +199,16 @@ def getDriversForPossibleBluetoothDevices() -> typing.Iterator[typing.Tuple[str,
if matchFunc(match):
yield driver, match

for match in btHidDevMatchesForHid:
# Check for the Braille HID protocol after any other device matching.
# This ensures that a vendor specific driver is preferred over the braille HID protocol.
# This preference may change in the future.
if _isHIDBrailleMatch(match):
yield (
_getStandardHidDriverName(),
match
)
if _isHidBrailleStandardSupported():
for match in btHidDevMatchesForHid:
# Check for the Braille HID protocol after any other device matching.
# This ensures that a vendor specific driver is preferred over the braille HID protocol.
# This preference may change in the future.
if _isHIDBrailleMatch(match):
yield (
_getStandardHidDriverName(),
match
)


class _DeviceInfoFetcher(AutoPropertyObject):
Expand Down Expand Up @@ -405,7 +411,10 @@ def getConnectedUsbDevicesForDriver(driver) -> typing.Iterator[DeviceMatch]:
)
for match in usbDevs:
if driver == _getStandardHidDriverName():
if _isHIDBrailleMatch(match):
if(
_isHidBrailleStandardSupported()
and _isHIDBrailleMatch(match)
):
yield match
else:
devs = _driverDevices[driver]
Expand All @@ -422,7 +431,11 @@ def getPossibleBluetoothDevicesForDriver(driver) -> typing.Iterator[DeviceMatch]
@raise LookupError: If there is no detection data for this driver.
"""
if driver == _getStandardHidDriverName():
matchFunc = _isHIDBrailleMatch
def matchFunc(checkMatch: DeviceMatch) -> bool:
return (
_isHidBrailleStandardSupported()
and _isHIDBrailleMatch(checkMatch)
)
else:
matchFunc = _driverDevices[driver][KEY_BLUETOOTH]
if not callable(matchFunc):
Expand Down
15 changes: 15 additions & 0 deletions source/brailleDisplayDrivers/hidBrailleStandard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
from bdDetect import HID_USAGE_PAGE_BRAILLE


def isSupportEnabled() -> bool:
import config
return config.conf["braille"]["enableHidBrailleSupport"] in [
1, # yes
0, # Use default/recommended value, currently "yes"
]


class BraillePageUsageID(enum.IntEnum):
UNDEFINED = 0
BRAILLE_DISPLAY = 0x1
Expand Down Expand Up @@ -78,6 +86,13 @@ class HidBrailleDriver(braille.BrailleDisplayDriver):
description = _("Standard HID Braille Display")
isThreadSafe = True

@classmethod
def check(cls):
return (
isSupportEnabled()
and super().check()
)

def __init__(self, port="auto"):
super().__init__()
self.numCells = 0
Expand Down
1 change: 1 addition & 0 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
readByParagraph = boolean(default=false)
wordWrap = boolean(default=true)
focusContextPresentation = option("changedContext", "fill", "scroll", default="changedContext")
enableHidBrailleSupport = integer(0, 2, default=0) # 0:Use default/recommended value (yes), 1:yes, 2:no
# Braille display driver settings
[[__many__]]
Expand Down
40 changes: 40 additions & 0 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2700,6 +2700,42 @@ def __init__(self, parent):
self.ariaDescCheckBox.SetValue(config.conf["annotations"]["reportAriaDescription"])
self.ariaDescCheckBox.defaultValue = self._getDefaultValue(["annotations", "reportAriaDescription"])

# Translators: This is the label for a group of advanced options in the
# Advanced settings panel
label = _("HID Braille Standard")
hidBrailleSizer = wx.StaticBoxSizer(wx.VERTICAL, self, label=label)
hidBrailleBox = hidBrailleSizer.GetStaticBox()
hidBrailleGroup = guiHelper.BoxSizerHelper(self, sizer=hidBrailleSizer)
self.bindHelpEvent("HIDBraille", hidBrailleBox)
sHelper.addItem(hidBrailleGroup)

supportHidBrailleChoices = [
# Translators: Label for option in the 'Enable support for HID braille' combobox
# in the Advanced settings panel.
_("Default (Yes)"),
# Translators: Label for option in the 'Enable support for HID braille' combobox
# in the Advanced settings panel.
_("Yes"),
# Translators: Label for option in the 'Enable support for HID braille' combobox
# in the Advanced settings panel.
_("No"),
]

# Translators: This is the label for a checkbox in the
# Advanced settings panel.
label = _("Enable support for HID braille")
self.supportHidBrailleCombo: wx.Choice = hidBrailleGroup.addLabeledControl(
labelText=label,
wxCtrlClass=wx.Choice,
choices=supportHidBrailleChoices,
)
self.supportHidBrailleCombo.SetSelection(
config.conf["braille"]["enableHidBrailleSupport"]
)
self.supportHidBrailleCombo.defaultValue = self._getDefaultValue(
["braille", "enableHidBrailleSupport"]
)

# Translators: This is the label for a group of advanced options in the
# Advanced settings panel
label = _("Terminal programs")
Expand Down Expand Up @@ -2910,6 +2946,7 @@ def haveConfigDefaultsBeenRestored(self):
and set(self.logCategoriesList.CheckedItems) == set(self.logCategoriesList.defaultCheckedItems)
and self.annotationsDetailsCheckBox.IsChecked() == self.annotationsDetailsCheckBox.defaultValue
and self.ariaDescCheckBox.IsChecked() == self.ariaDescCheckBox.defaultValue
and self.supportHidBrailleCombo.GetSelection() == self.supportHidBrailleCombo.defaultValue
and True # reduce noise in diff when the list is extended.
)

Expand All @@ -2927,6 +2964,7 @@ def restoreToDefaults(self):
self.caretMoveTimeoutSpinControl.SetValue(self.caretMoveTimeoutSpinControl.defaultValue)
self.annotationsDetailsCheckBox.SetValue(self.annotationsDetailsCheckBox.defaultValue)
self.ariaDescCheckBox.SetValue(self.ariaDescCheckBox.defaultValue)
self.supportHidBrailleCombo.SetSelection(self.supportHidBrailleCombo.defaultValue)
self.reportTransparentColorCheckBox.SetValue(self.reportTransparentColorCheckBox.defaultValue)
self.logCategoriesList.CheckedItems = self.logCategoriesList.defaultCheckedItems
self._defaultsRestored = True
Expand Down Expand Up @@ -2955,6 +2993,8 @@ def onSave(self):
)
config.conf["annotations"]["reportDetails"] = self.annotationsDetailsCheckBox.IsChecked()
config.conf["annotations"]["reportAriaDescription"] = self.ariaDescCheckBox.IsChecked()
config.conf["braille"]["enableHidBrailleSupport"] = self.supportHidBrailleCombo.GetSelection()

for index,key in enumerate(self.logCategories):
config.conf['debugLog'][key]=self.logCategoriesList.IsChecked(index)
config.conf["featureFlag"]["playErrorSound"] = self.playErrorSoundCombo.GetSelection()
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is a minor release to fix several issues in 2021.3.

== Changes ==
- The new HID Braille protocol is no longer preferred when another braille display driver can be used. (#13153)
- The new HID Braille protocol can be disabled via a setting in the advanced settings panel. (#13180)
-


Expand Down

0 comments on commit 952d28b

Please sign in to comment.