# The MIT License (MIT) # # Copyright (c) 2017 Scott Shawcroft for Adafruit Industries # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import struct DESCRIPTOR_TYPE_CLASS_SPECIFIC_DEVICE = 0x21 DESCRIPTOR_TYPE_CLASS_SPECIFIC_CONFIGURATION = 0x22 DESCRIPTOR_TYPE_CLASS_SPECIFIC_STRING = 0x23 DESCRIPTOR_TYPE_CLASS_SPECIFIC_INTERFACE = 0x24 DESCRIPTOR_TYPE_CLASS_SPECIFIC_ENDPOINT = 0x25 class EndpointDescriptor: """Single endpoint configuration""" bDescriptorType = 0x5 fmt = " 1: self._bLength = value[0] if value[1] != 3: raise ValueError("Sequence not a StringDescriptor") self._bString = value[2:2+self.bLength] def notes(self): return [str(self)] def __bytes__(self): return struct.pack("BB{}s".format(len(self._bString)), self.bLength, self.bDescriptorType, self._bString) @property def bString(self): return self._bString.decode("utf-16-le") @bString.setter def bString(self, value): self._bString = value.encode("utf-16-le") self._bLength = len(self.encoded) + 2 @property def bLength(self): return self._bLength