Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-line braille displays in HidBrailleDriver #17001

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
58 changes: 39 additions & 19 deletions source/brailleDisplayDrivers/hidBrailleStandard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (C) 2021 NV Access Limited

from dataclasses import dataclass
from typing import List, Optional
from typing import List
import enum
import braille
import inputCore
Expand Down Expand Up @@ -90,7 +90,8 @@ def registerAutomaticDetection(cls, driverRegistrar: DriverRegistrar):

def __init__(self, port="auto"):
super().__init__()
self.numCells = 0
self.numRows = 1
self.numCols = 0

for portType, portId, port, portInfo in self._getTryPorts(port):
if portType != bdDetect.DeviceType.HID:
Expand All @@ -103,16 +104,27 @@ def __init__(self, port="auto"):
continue # Couldn't connect.
if self._dev.usagePage != HID_USAGE_PAGE_BRAILLE:
log.debug("Not braille")
self._dev.close()
continue
cellValueCaps = self._findCellValueCaps()
if cellValueCaps:
if len(cellValueCaps) > 0:
if any(x.ReportCount != cellValueCaps[0].ReportCount for x in cellValueCaps):
log.warn("Found multi-line display with an irregular shape, ignoring.")
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
self._dev.close()
continue
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
self.numRows = len(cellValueCaps)
self.numCols = cellValueCaps[0].ReportCount
self._maxNumberOfCells = self.numCells
self._cellValueCaps = cellValueCaps
self._numberOfCellsValueCaps = self._findNumberOfCellsValueCaps()
self.numCells = self._maxNumberOfCells = cellValueCaps.ReportCount
if self.numRows == 1:
self._numberOfCellsValueCaps = self._findNumberOfCellsValueCaps()
elif self._findNumberOfCellsValueCaps():
log.warn("The number of braille cells usage is not supported on multi-line displays")
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
# A display responded.
log.info(
"Found display with {cells} cells connected via {type} ({port})".format(
cells=self.numCells,
"Found display with {rows}x{cells} cells connected via {type} ({port})".format(
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
rows=self.numRows,
cells=self.numCols,
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
type=portType,
port=port,
),
Expand All @@ -126,8 +138,10 @@ def __init__(self, port="auto"):
self._keysDown = set()
self._ignoreKeyReleases = False

def _findCellValueCaps(self) -> Optional[hidpi.HIDP_VALUE_CAPS]:
for valueCaps in self._dev.outputValueCaps:
def _findCellValueCaps(self) -> List[hidpi.HIDP_VALUE_CAPS]:
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
return [
valueCaps
for valueCaps in self._dev.outputValueCaps
if (
valueCaps.LinkUsagePage == HID_USAGE_PAGE_BRAILLE
and valueCaps.LinkUsage == BraillePageUsageID.BRAILLE_ROW
Expand All @@ -137,9 +151,8 @@ def _findCellValueCaps(self) -> Optional[hidpi.HIDP_VALUE_CAPS]:
BraillePageUsageID.SIX_DOT_BRAILLE_CELL,
)
and valueCaps.ReportCount > 0
):
return valueCaps
return None
)
]

def _findNumberOfCellsValueCaps(self) -> hidpi.HIDP_VALUE_CAPS | None:
for valueCaps in self._dev.inputValueCaps:
Expand Down Expand Up @@ -226,13 +239,20 @@ def display(self, cells: List[int]):
# cells will already be padded up to numCells.
padded_cells = cells + [0] * (self._maxNumberOfCells - len(cells))
cellBytes = b"".join(intToByte(cell) for cell in padded_cells)
report = hwIo.hid.HidOutputReport(self._dev, reportID=self._cellValueCaps.ReportID)
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
report.setUsageValueArray(
HID_USAGE_PAGE_BRAILLE,
self._cellValueCaps.LinkCollection,
self._cellValueCaps.u1.NotRange.Usage,
cellBytes,
)
reportID = self._cellValueCaps[0].ReportID
report = hwIo.hid.HidOutputReport(self._dev, reportID=reportID)
for valueCap in self._cellValueCaps:
if valueCap.ReportID != reportID:
self._dev.write(report.data)
reportID = valueCap.ReportID
report = hwIo.hid.HidOutputReport(self._dev, reportID=reportID)
report.setUsageValueArray(
HID_USAGE_PAGE_BRAILLE,
valueCap.LinkCollection,
valueCap.u1.NotRange.Usage,
cellBytes[: valueCap.ReportCount],
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
)
cellBytes = cellBytes[valueCap.ReportCount :]
alexmoon marked this conversation as resolved.
Show resolved Hide resolved
self._dev.write(report.data)

gestureMap = inputCore.GlobalGestureMap(
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The available options are:
* The `-c`/`--config-path` and `--disable-addons` command line options are now respected when launching an update from within NVDA. (#16937)
* eSpeak NG has been updated to 1.52-dev commit `961454ff`. (#16775)
* Added new languages Faroese and Xextan.
* When using a multi-line braille display via the Standard HID braille driver, all lines of cells will be used. (#16993, @alexmoon)
alexmoon marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

Expand Down