def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None for match in self._getTryPorts(port): portType, portId, port, portInfo = match self.isBulk = portType == bdDetect.KEY_CUSTOM # Try talking to the display. try: if self.isBulk: # onReceiveSize based on max packet size according to USB endpoint information. self._dev = hwIo.Bulk(port, 0, 1, self._onReceive, writeSize=0, onReceiveSize=64) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue for i in xrange(3): self._sendCellCountRequest() # Wait for an expected response. if self.isBulk: # Hims Bulk devices sometimes present themselves to the system while not yet ready. # For example, when switching the connection mode toggle on the Braille EDGE from Bluetooth to USB, # the USB device is connected but not yet ready. # Wait ten times the timeout, which is ugly, but effective. self._dev.waitForRead(self.timeout * 10) else: self._dev.waitForRead(self.timeout) if self.numCells: break if not self.numCells: log.debugWarning("No response from potential Hims display") self._dev.close() continue self._sendIdentificationRequests(match) if self._model: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._model.name, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Hims display found")
def __init__(self, port="auto"): super(BrailleDisplayDriver, self).__init__() self.numCells = 0 self._model = None if port == "auto": tryPorts = self._getAutoPorts( hwPortUtils.listComPorts(onlyAvailable=True)) else: try: btName = next( portInfo.get("bluetoothName", "") for portInfo in hwPortUtils.listComPorts() if portInfo.get("port") == port) btPrefix = next(prefix for prefix in bluetoothPrefixes if btName.startswith(prefix)) tryPorts = ((port, "bluetooth", btPrefix), ) except StopIteration: tryPorts = () for port, portType, identifier in tryPorts: self.isBulk = portType == "USB bulk" # Try talking to the display. try: if self.isBulk: # onReceiveSize based on max packet size according to USB endpoint information. self._dev = hwIo.Bulk(port, 0, 1, self._onReceive, writeSize=0, onReceiveSize=64) else: self._dev = hwIo.Serial(port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive) except EnvironmentError: log.debugWarning("", exc_info=True) continue for i in xrange(3): self._sendCellCountRequest() # Wait for an expected response. if self.isBulk: # Hims Bulk devices sometimes present themselves to the system while not yet ready. # For example, when switching the connection mode toggle on the Braille EDGE from Bluetooth to USB, # the USB device is connected but not yet ready. # Wait ten times the timeout, which is ugly, but effective. self._dev.waitForRead(self.timeout * 10) else: self._dev.waitForRead(self.timeout) if self.numCells: break if not self.numCells: log.debugWarning("No response from potential Hims display") self._dev.close() continue if portType == "USB serial": self._model = SyncBraille() elif self.isBulk: self._sendIdentificationRequests(usbId=identifier) elif portType == "bluetooth" and identifier: self._sendIdentificationRequests(bluetoothPrefix=identifier) else: self._sendIdentificationRequests() if self._model: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._model.name, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Hims display found")
def __init__(self, port="auto"): self.numCells = 0 self._ackPending = False self._pendingCells = [] self._keyBits = 0 self._extendedKeyBits = 0 self._ignoreKeyReleases = False self._model = None self._manufacturer = None self._firmwareVersion = None self.translationTable = None self.leftWizWheelActionCycle = itertools.cycle(self.wizWheelActions) action = self.leftWizWheelActionCycle.next() self.gestureMap.add("br(freedomScientific):leftWizWheelUp", *action[1]) self.gestureMap.add("br(freedomScientific):leftWizWheelDown", *action[2]) self.rightWizWheelActionCycle = itertools.cycle(self.wizWheelActions) action = self.rightWizWheelActionCycle.next() self.gestureMap.add("br(freedomScientific):rightWizWheelUp", *action[1]) self.gestureMap.add("br(freedomScientific):rightWizWheelDown", *action[2]) super(BrailleDisplayDriver, self).__init__() for portType, portId, port, portInfo in self._getTryPorts(port): self.isUsb = portType == bdDetect.KEY_CUSTOM # Try talking to the display. try: if self.isUsb: self._dev = hwIo.Bulk( port, epIn=1, epOut=0, onReceive=self._onReceive, writeSize=0, onReceiveSize=56 ) else: self._dev = hwIo.Serial( port, baudrate=BAUD_RATE, parity=PARITY, timeout=self.timeout, writeTimeout=self.timeout, onReceive=self._onReceive ) except EnvironmentError: log.debugWarning("", exc_info=True) continue # Send an identification request self._sendPacket(FS_PKT_QUERY) for _i in xrange(3): self._dev.waitForRead(self.timeout) if self.numCells and self._model: break if self.numCells and self._model: # A display responded. log.info("Found {device} connected via {type} ({port})".format( device=self._model, type=portType, port=port)) break self._dev.close() else: raise RuntimeError("No Freedom Scientific display found") self._configureDisplay() self.gestureMap.add("br(freedomScientific):topRouting1", "globalCommands", "GlobalCommands", "braille_scrollBack") self.gestureMap.add("br(freedomScientific):topRouting%d" % self.numCells, "globalCommands", "GlobalCommands", "braille_scrollForward")