From 5243a33584fe4ceb691b6f87bc4ee4f623e4cddd Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 20 Nov 2021 13:41:18 -0600 Subject: [PATCH] Check map to display size --- locale/circuitpython.pot | 4 ++++ shared-bindings/is31fl3741/is31fl3741.c | 3 +++ shared-module/is31fl3741/is31fl3741.c | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index dbcf703b68..9f6ea16bbb 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1458,6 +1458,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 "" diff --git a/shared-bindings/is31fl3741/is31fl3741.c b/shared-bindings/is31fl3741/is31fl3741.c index 723687d227..aa98972b24 100644 --- a/shared-bindings/is31fl3741/is31fl3741.c +++ b/shared-bindings/is31fl3741/is31fl3741.c @@ -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; diff --git a/shared-module/is31fl3741/is31fl3741.c b/shared-module/is31fl3741/is31fl3741.c index 78d2d1efce..c616d3a20c 100644 --- a/shared-module/is31fl3741/is31fl3741.c +++ b/shared-module/is31fl3741/is31fl3741.c @@ -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]);