@@ -90,7 +90,8 @@ def registerAutomaticDetection(cls, driverRegistrar: DriverRegistrar):
9090
9191 def __init__ (self , port = "auto" ):
9292 super ().__init__ ()
93- self .numCells = 0
93+ self .numRows = 1
94+ self .numCols = 0
9495
9596 for portType , portId , port , portInfo in self ._getTryPorts (port ):
9697 if portType != bdDetect .DeviceType .HID :
@@ -103,16 +104,27 @@ def __init__(self, port="auto"):
103104 continue # Couldn't connect.
104105 if self ._dev .usagePage != HID_USAGE_PAGE_BRAILLE :
105106 log .debug ("Not braille" )
107+ self ._dev .close ()
106108 continue
107109 cellValueCaps = self ._findCellValueCaps ()
108- if cellValueCaps :
110+ if len (cellValueCaps ) > 0 :
111+ if any (x .ReportCount != cellValueCaps [0 ].ReportCount for x in cellValueCaps ):
112+ log .warn ("Found multi-line display with an irregular shape, ignoring." )
113+ self ._dev .close ()
114+ continue
115+ self .numRows = len (cellValueCaps )
116+ self .numCols = cellValueCaps [0 ].ReportCount
117+ self ._maxNumberOfCells = self .numCells
109118 self ._cellValueCaps = cellValueCaps
110- self ._numberOfCellsValueCaps = self ._findNumberOfCellsValueCaps ()
111- self .numCells = self ._maxNumberOfCells = cellValueCaps .ReportCount
119+ if self .numRows == 1 :
120+ self ._numberOfCellsValueCaps = self ._findNumberOfCellsValueCaps ()
121+ elif self ._findNumberOfCellsValueCaps ():
122+ log .warn ("The number of braille cells usage is not supported on multi-line displays" )
112123 # A display responded.
113124 log .info (
114- "Found display with {cells} cells connected via {type} ({port})" .format (
115- cells = self .numCells ,
125+ "Found display with {rows}x{cells} cells connected via {type} ({port})" .format (
126+ rows = self .numRows ,
127+ cells = self .numCols ,
116128 type = portType ,
117129 port = port ,
118130 ),
@@ -126,20 +138,17 @@ def __init__(self, port="auto"):
126138 self ._keysDown = set ()
127139 self ._ignoreKeyReleases = False
128140
129- def _findCellValueCaps (self ) -> Optional [hidpi .HIDP_VALUE_CAPS ]:
130- for valueCaps in self ._dev .outputValueCaps :
131- if (
132- valueCaps .LinkUsagePage == HID_USAGE_PAGE_BRAILLE
133- and valueCaps .LinkUsage == BraillePageUsageID .BRAILLE_ROW
134- and valueCaps .u1 .NotRange .Usage
135- in (
136- BraillePageUsageID .EIGHT_DOT_BRAILLE_CELL ,
137- BraillePageUsageID .SIX_DOT_BRAILLE_CELL ,
138- )
139- and valueCaps .ReportCount > 0
140- ):
141- return valueCaps
142- return None
141+ def _findCellValueCaps (self ) -> List [hidpi .HIDP_VALUE_CAPS ]:
142+ return [valueCaps for valueCaps in self ._dev .outputValueCaps if (
143+ valueCaps .LinkUsagePage == HID_USAGE_PAGE_BRAILLE
144+ and valueCaps .LinkUsage == BraillePageUsageID .BRAILLE_ROW
145+ and valueCaps .u1 .NotRange .Usage
146+ in (
147+ BraillePageUsageID .EIGHT_DOT_BRAILLE_CELL ,
148+ BraillePageUsageID .SIX_DOT_BRAILLE_CELL ,
149+ )
150+ and valueCaps .ReportCount > 0
151+ )]
143152
144153 def _findNumberOfCellsValueCaps (self ) -> hidpi .HIDP_VALUE_CAPS | None :
145154 for valueCaps in self ._dev .inputValueCaps :
@@ -226,13 +235,20 @@ def display(self, cells: List[int]):
226235 # cells will already be padded up to numCells.
227236 padded_cells = cells + [0 ] * (self ._maxNumberOfCells - len (cells ))
228237 cellBytes = b"" .join (intToByte (cell ) for cell in padded_cells )
229- report = hwIo .hid .HidOutputReport (self ._dev , reportID = self ._cellValueCaps .ReportID )
230- report .setUsageValueArray (
231- HID_USAGE_PAGE_BRAILLE ,
232- self ._cellValueCaps .LinkCollection ,
233- self ._cellValueCaps .u1 .NotRange .Usage ,
234- cellBytes ,
235- )
238+ reportID = self ._cellValueCaps [0 ].ReportID
239+ report = hwIo .hid .HidOutputReport (self ._dev , reportID = reportID )
240+ for valueCap in self ._cellValueCaps :
241+ if valueCap .ReportID != reportID :
242+ self ._dev .write (report .data )
243+ reportID = valueCap .ReportID
244+ report = hwIo .hid .HidOutputReport (self ._dev , reportID = reportID )
245+ report .setUsageValueArray (
246+ HID_USAGE_PAGE_BRAILLE ,
247+ valueCap .LinkCollection ,
248+ valueCap .u1 .NotRange .Usage ,
249+ cellBytes [:valueCap .ReportCount ],
250+ )
251+ cellBytes = cellBytes [valueCap .ReportCount :]
236252 self ._dev .write (report .data )
237253
238254 gestureMap = inputCore .GlobalGestureMap (
0 commit comments