Skip to content

Commit 32c3d04

Browse files
committed
adafruit_pixelbuf: Allow the buffer to be written in _transmit
This permits modifying the brightness of TM1814 strips at runtime.
1 parent 7a2da7a commit 32c3d04

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

shared-module/adafruit_pixelbuf/PixelBuf.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ void common_hal_adafruit_pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *se
3030
self->auto_write = false;
3131

3232
size_t pixel_len = self->pixel_count * self->bytes_per_pixel;
33-
self->transmit_buffer_obj = mp_obj_new_bytes_of_zeros(header_len + pixel_len + trailer_len);
34-
mp_obj_str_t *o = MP_OBJ_TO_PTR(self->transmit_buffer_obj);
33+
self->transmit_buffer_obj = mp_obj_new_bytearray_of_zeros(header_len + pixel_len + trailer_len);
34+
mp_obj_array_t *o = MP_OBJ_TO_PTR(self->transmit_buffer_obj);
3535

36-
// Abuse the bytes object a bit by mutating it's data by dropping the const. If the user's
37-
// Python code holds onto it, they'll find out that it changes. At least this way it isn't
38-
// mutable by the code itself.
39-
uint8_t *transmit_buffer = (uint8_t *)o->data;
36+
uint8_t *transmit_buffer = o->items;
4037
memcpy(transmit_buffer, header, header_len);
4138
memcpy(transmit_buffer + header_len + pixel_len, trailer, trailer_len);
4239
self->post_brightness_buffer = transmit_buffer + header_len;

0 commit comments

Comments
 (0)