Skip to content

Commit

Permalink
Check map to display size
Browse files Browse the repository at this point in the history
  • Loading branch information
gamblor21 committed Nov 20, 2021
1 parent 29594c4 commit ac3d99d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,10 @@ msgstr ""
msgid "Key must be 16, 24, or 32 bytes long"
msgstr ""

#: shared-module/is31fl3741/is31fl3741.c
msgid "LED mappings must match display size"
msgstr ""

#: py/compile.c
msgid "LHS of keyword arg must be an id"
msgstr ""
Expand Down
3 changes: 3 additions & 0 deletions shared-bindings/is31fl3741/is31fl3741.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ STATIC mp_obj_t is31fl3741_is31fl3741_make_new(const mp_obj_type_t *type, size_t

self->scale_width = args[ARG_width].u_int / 3;
self->scale_height = args[ARG_height].u_int / 3;
} else {
self->scale_width = args[ARG_width].u_int;
self->scale_height = args[ARG_height].u_int;
}

self->auto_gamma = args[ARG_gamma].u_bool;
Expand Down
5 changes: 4 additions & 1 deletion shared-module/is31fl3741/is31fl3741.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ void common_hal_is31fl3741_is31fl3741_construct(is31fl3741_is31fl3741_obj_t *sel
// of the heap as well.
gc_never_free(self->i2c);

// TODO mapping should be equal to height * width * 3
mp_obj_t *items;
size_t len;
mp_obj_list_get(mapping, &len, &items);

if (len != (size_t)(self->scale_width * self->scale_height * 3)) {
mp_raise_ValueError(translate("LED mappings must match display size"));
}

self->mapping = common_hal_is31fl3741_allocator_impl(sizeof(uint16_t) * len);
for (size_t i = 0; i < len; i++) {
mp_int_t value = mp_obj_get_int(items[i]);
Expand Down

0 comments on commit ac3d99d

Please sign in to comment.