Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bricknil/sensor/peripheral.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ def _convert_bytes(self, msg_bytes:bytearray, byte_count):
If multiple values, then a list of those values
Value can be either uint8, uint16, or uint32 depending on value of `byte_count`
"""
if byte_count == 1: # just a uint8
val = msg_bytes[0]
elif byte_count == 2: # uint16 little-endian
val = struct.unpack('<H', msg_bytes)[0]
elif byte_count == 4: # uint32 little-endian
val = struct.unpack('<I', msg_bytes)[0]
if byte_count == 1: # just an int8
val = struct.unpack('<b', msg_bytes)[0]
elif byte_count == 2: # int16 little-endian
val = struct.unpack('<h', msg_bytes)[0]
elif byte_count == 4: # int32 little-endian
val = struct.unpack('<i', msg_bytes)[0]
else:
self.message_error(f'Cannot convert array of {msg_bytes} length {len(msg_bytes)} to python datatype')
val = None
Expand Down