-
Notifications
You must be signed in to change notification settings - Fork 2
Fix bytearray TypeError Issue For Non-Express Boards #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
456b173
50d46b8
bfe3264
6a10d24
69d4b17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,20 +82,20 @@ def __getitem__(self, x): | |
raise ValueError(('LED number must be between 0 -', self._parent._num_leds - 1)) | ||
led = ledLUT[x % 16] >> 4 | ||
mask = 1 << (ledLUT[x % 16] & 0x0f) | ||
return bool(((self._parent._led_buffer[x // 16][led * 2] | \ | ||
self._parent._led_buffer[x // 16][(led * 2) + 1] << 8) & mask) > 0) | ||
return bool(((self._parent._led_buffer[x // 16][(led * 2) + 1] | \ | ||
self._parent._led_buffer[x // 16][(led * 2) + 2] << 8) & mask) > 0) | ||
|
||
def __setitem__(self, x, value): | ||
if 0 < x >= self._parent._num_leds: | ||
raise ValueError(('LED number must be between 0 -', self._parent._num_leds - 1)) | ||
led = ledLUT[x % 16] >> 4 | ||
mask = 1 << (ledLUT[x % 16] & 0x0f) | ||
if value: | ||
self._parent._led_buffer[x // 16][led * 2] |= mask | ||
self._parent._led_buffer[x // 16][(led * 2) + 1] |= mask >> 8 | ||
self._parent._led_buffer[x // 16][(led * 2) + 1] |= mask | ||
self._parent._led_buffer[x // 16][(led * 2) + 2] |= mask >> 8 | ||
elif not value: | ||
self._parent._led_buffer[x // 16][led * 2] &= ~mask | ||
self._parent._led_buffer[x // 16][(led * 2) + 1] &= ~mask >> 8 | ||
self._parent._led_buffer[x // 16][(led * 2) + 1] &= ~mask | ||
self._parent._led_buffer[x // 16][(led * 2) + 2] &= ~mask >> 8 | ||
else: | ||
raise ValueError("LED value must be True or False") | ||
|
||
|
@@ -105,7 +105,7 @@ def __setitem__(self, x, value): | |
def fill(self, on): | ||
fill = 0xff if on else 0x00 | ||
for buff in range(len(self._parent._i2c_devices)): | ||
for i in range(16): | ||
for i in range(1, 16): | ||
self._parent._led_buffer[buff][i] = fill | ||
if self._parent._auto_show: | ||
self._parent.show() | ||
|
@@ -196,10 +196,9 @@ def brightness(self, brightness): | |
|
||
def show(self): | ||
"""Refresh the LED buffer and show the changes.""" | ||
temp_led_buffer = bytearray(self._num_leds + 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this have an extra byte? I see you shifted the indices above but I don't remember why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because the first byte when sending register info to the HT16K33 is the register location; in this case it should be |
||
pos = 0 | ||
for device in self._i2c_devices: | ||
temp_led_buffer[1:] = self._led_buffer[pos] | ||
temp_led_buffer = bytearray(self._led_buffer[pos]) | ||
with device: | ||
device.write(temp_led_buffer) | ||
pos += 1 | ||
|
@@ -224,7 +223,7 @@ def read_buttons(self): | |
lists: 1 for new button presses, 1 for button relases. | ||
""" | ||
for i in range(len(self._buttons)): | ||
self._buttons[i][0][:] = self._buttons[i][1][:] | ||
self._buttons[i][0] = bytearray(self._buttons[i][1]) | ||
self._write_cmd(_HT16K33_KEY_READ_CMD) | ||
pos = 0 | ||
for device in self._i2c_devices: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be 17 because the end is exclusive I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literally just facepalmed myself... Even though the HT16K33 didn't have a problem with it testing this way.