예제 #1
0
 def _set_hidKeyboardInput(self, state):
     rawState = not state
     if self.isHid:
         # Make sure the device settings are up to date.
         keySettings: int = self._dev.getFeature(
             ALVA_KEY_SETTINGS_REPORT)[ALVA_KEY_SETTINGS_POS]
         # Try to update the state
         if rawState:
             newKeySettings = intToByte(keySettings
                                        | ALVA_KEY_RAW_INPUT_MASK)
         elif keySettings & ALVA_KEY_RAW_INPUT_MASK:
             newKeySettings = intToByte(keySettings
                                        ^ ALVA_KEY_RAW_INPUT_MASK)
         else:
             newKeySettings = intToByte(keySettings)
         self._dev.setFeature(ALVA_KEY_SETTINGS_REPORT + newKeySettings)
         # Check whether the state has been changed successfully.
         # If not, this device does not support this feature.
         keySettings: int = self._dev.getFeature(
             ALVA_KEY_SETTINGS_REPORT)[ALVA_KEY_SETTINGS_POS]
         # Save the new state
         self._rawKeyboardInput = bool(keySettings
                                       & ALVA_KEY_RAW_INPUT_MASK)
     else:
         self._ser6SendMessage(cmd=b"r", value=boolToByte(rawState))
         self._ser6SendMessage(b"r", b"?")
         for i in range(3):
             self._dev.waitForRead(self.timeout)
             if rawState is self._rawKeyboardInput:
                 break
예제 #2
0
    def _sendRequest(self, command: bytes, arg: Union[bytes, bool, int] = b""):
        """
		:type command: bytes
		:type arg: bytes | bool | int
		"""
        typeErrorString = "Expected param '{}' to be of type '{}', got '{}'"
        if not isinstance(arg, bytes):
            if isinstance(arg, bool):
                arg = boolToByte(arg)
            elif isinstance(arg, int):
                arg = intToByte(arg)
            else:
                raise TypeError(
                    typeErrorString.format("arg", "bytes, bool, or int",
                                           type(arg).__name__))

        if not isinstance(command, bytes):
            raise TypeError(
                typeErrorString.format("command", "bytes",
                                       type(command).__name__))

        if self.isHid:
            self._dev.write(command + arg)
        else:
            arg = arg.replace(ESCAPE, ESCAPE * 2)
            data = b"".join([ESCAPE, command, arg])
            self._dev.write(data)
	def _set_atc(self, state):
		if self._atc is state:
			return
		if isinstance(self._model,AtcMixin):
			self.sendExtendedPacket(HT_EXTPKT_SET_ATC_MODE, boolToByte(state))
		else:
			log.debugWarning("Changing ATC setting for unsupported device %s"%self._model.name)
		# Regardless whether this setting is supported or not, we want to safe its state.
		self._atc = state
예제 #4
0
 def terminate(self):
     try:
         super(BrailleDisplayDriver, self).terminate()
         try:
             self._sendRequest(BAUM_PROTOCOL_ONOFF, boolToByte(False))
         except EnvironmentError:
             # Some displays don't support BAUM_PROTOCOL_ONOFF.
             pass
     finally:
         # Make sure the device gets closed.
         # If it doesn't, we may not be able to re-open it later.
         self._dev.close()
예제 #5
0
 def _serSendMessage(self,
                     msgId: bytes,
                     payload: Union[bytes, int, bool] = b""):
     if not isinstance(payload, bytes):
         if isinstance(payload, int):
             payload: bytes = intToByte(payload)
         elif isinstance(payload, bool):
             payload: bytes = boolToByte(payload)
         else:
             raise TypeError(
                 "Expected arg 'payload' to be of type 'bytes, int, or bool'"
             )
     data = b''.join([HEADER, msgId, intToByte(len(payload)), payload])
     self._dev.write(data)