Use c_ubyte for byte array casts

This prevents having to do the explicit & 0xff, and avoids generating an
error when calling .read() (which didn't have the bitmask)
pull/159/head
Chris Thornton 2020-04-07 02:17:21 -07:00 committed by Olivier Martin
parent 80d26d702d
commit efc656ca52
2 changed files with 3 additions and 3 deletions

View File

@ -140,12 +140,12 @@ class Device:
# for i in range(data_len):
# value[i] = data[i]
pointer_type = POINTER(c_byte * data_len)
pointer_type = POINTER(c_ubyte * data_len)
c_bytearray = cast(data, pointer_type)
value = bytearray(data_len)
for i in range(data_len):
value[i] = c_bytearray.contents[i] & 0xFF
value[i] = c_bytearray.contents[i]
# Call GATT characteristic Notification callback
characteristic_callback['callback'](value, characteristic_callback['user_data'])

View File

@ -74,7 +74,7 @@ class GattCharacteristic():
ret = gattlib_read_char_by_uuid(self.connection, self._gattlib_characteristic.uuid, byref(_buffer), byref(_buffer_len))
pointer_type = POINTER(c_byte * _buffer_len.value)
pointer_type = POINTER(c_ubyte * _buffer_len.value)
c_bytearray = cast(_buffer, pointer_type)
value = bytearray(_buffer_len.value)