From e23bad3a3af2c334573d6233508cf2fd3b111b66 Mon Sep 17 00:00:00 2001 From: Joshua Coats Date: Sat, 23 Mar 2019 10:49:43 -0700 Subject: shared-bindings/socket: add socket_recv_into --- shared-bindings/socket/__init__.c | 53 +++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index 29d47de56..c59724efc 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -240,6 +240,52 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); + +// helper function for socket_recv and socket_recv_into to handle common operations of both +STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_int_t len) { + int _errno; + mp_int_t ret = sock->nic_type->recv(sock, buf, len, &_errno); + if (ret == -1) { + mp_raise_OSError(_errno); + } + return len; +} + + +//| .. method:: recv_into(buffer[, bufsize]) +//| +//| Reads some bytes from the connected remote address, writing +//| into the provided buffer. If bufsize <= len(buffer) is given, +//| a maximum of bufsize bytes will be read into the buffer. If no +//| valid value is given for bufsize, the default is the length of +//| the given buffer. +//| +//| Suits sockets of type SOCK_STREAM +//| Returns an int of number of bytes read. +//| +//| :param bytearray buffer: buffer to receive into +//| :param int bufsize: optionally, a maximum number of bytes to read. + +STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) { + mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); + if (self->nic == MP_OBJ_NULL) { + // not connected + mp_raise_OSError(MP_ENOTCONN); + } + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); + mp_int_t len; + if (n_args == 3) { + len = mp_obj_get_int(args[2]); + } + if (n_args == 2 || (size_t) len > bufinfo.len) { + len = bufinfo.len; + } + mp_int_t ret = _socket_recv_into(self, (byte*)bufinfo.buf, len); + return mp_obj_new_int_from_uint(ret); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_into_obj, 2, 3, socket_recv_into); + //| .. method:: recv(bufsize) //| //| Reads some bytes from the connected remote address. @@ -257,11 +303,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { mp_int_t len = mp_obj_get_int(len_in); vstr_t vstr; vstr_init_len(&vstr, len); - int _errno; - mp_int_t ret = self->nic_type->recv(self, (byte*)vstr.buf, len, &_errno); - if (ret == -1) { - mp_raise_OSError(_errno); - } + mp_int_t ret = _socket_recv_into(self, (byte*)vstr.buf, len); if (ret == 0) { return mp_const_empty_bytes; } @@ -436,6 +478,7 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&socket_recv_obj) }, { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socket_sendto_obj) }, { MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&socket_recvfrom_obj) }, + { MP_ROM_QSTR(MP_QSTR_recv_into), MP_ROM_PTR(&socket_recv_into_obj) }, { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socket_setsockopt_obj) }, { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&socket_settimeout_obj) }, { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) }, -- cgit v1.2.3 From cc6fb4595ede6e27ae03edc8af782496e87698bb Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Mon, 25 Mar 2019 01:41:52 +0100 Subject: Reuse existing error message in busio.i2c Remove a period from the error message, so that the same message as in SPI and other places in I2C can be re-used. --- shared-bindings/busio/I2C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index e792d2575..e17a72b48 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -114,7 +114,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i static void check_lock(busio_i2c_obj_t *self) { asm(""); if (!common_hal_busio_i2c_has_lock(self)) { - mp_raise_RuntimeError(translate("Function requires lock.")); + mp_raise_RuntimeError(translate("Function requires lock")); } } -- cgit v1.2.3 From 81fe8060d76d54a20701e6944dd29cdfab9fed4f Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 20 Mar 2019 19:29:20 +0100 Subject: Properly calculate BPP for displayio.Bitmap Fix #1669 --- locale/ID.po | 12 ++++++------ locale/circuitpython.pot | 12 ++++++------ locale/de_DE.po | 16 ++++++++++------ locale/en_US.po | 12 ++++++------ locale/en_x_pirate.po | 12 ++++++------ locale/es.po | 15 +++++++++------ locale/fil.po | 15 +++++++++------ locale/fr.po | 15 +++++++++------ locale/it_IT.po | 12 ++++++------ locale/pt_BR.po | 12 ++++++------ shared-bindings/displayio/Bitmap.c | 16 ++++++++++++---- 11 files changed, 85 insertions(+), 64 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 694b2964f..1df86a7d2 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -762,14 +762,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 tidak mendukung pull up" @@ -2838,6 +2834,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() gagal" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 735459a47..645b2e4ad 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -737,14 +737,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "" @@ -2789,6 +2785,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 21fe860eb..87e965914 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -742,14 +742,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 unterstützt pull up nicht" @@ -2851,6 +2847,10 @@ msgstr "nicht unterstützter Typ für Operator" msgid "unsupported types for %q: '%s', '%s'" msgstr "nicht unterstützte Typen für %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() fehlgeschlagen" @@ -2889,5 +2889,9 @@ msgstr "" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Kann den Attributwert nicht lesen. Status: 0x%04x" +#~ msgid "Function requires lock." +#~ msgstr "" +#~ "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Nur unkomprimiertes Windows-Format (BMP) unterstützt %d" diff --git a/locale/en_US.po b/locale/en_US.po index 2f29498b9..da189c661 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -737,14 +737,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "" @@ -2789,6 +2785,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 0bcef8066..f9bb0f0ff 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -741,14 +741,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "" @@ -2793,6 +2789,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "" diff --git a/locale/es.po b/locale/es.po index efae8c368..9f71ac160 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -767,14 +767,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La función requiere lock" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "La función requiere lock" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 no soporta pull up." @@ -2874,6 +2870,10 @@ msgstr "tipo de operador no soportado" msgid "unsupported types for %q: '%s', '%s'" msgstr "tipos no soportados para %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() ha fallado" @@ -2916,6 +2916,9 @@ msgstr "paso cero" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "No se puede leer el valor del atributo. status 0x%02x" +#~ msgid "Function requires lock." +#~ msgstr "La función requiere lock" + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Solo formato Windows, BMP sin comprimir soportado %d" diff --git a/locale/fil.po b/locale/fil.po index 42a1c9e26..230a09597 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -765,14 +765,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Function nangangailangan ng lock" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "Kailangan ng lock ang function." - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "Walang pull down support ang GPI016." @@ -2880,6 +2876,10 @@ msgstr "hindi sinusuportahang type para sa operator" msgid "unsupported types for %q: '%s', '%s'" msgstr "hindi sinusuportahang type para sa %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "nabigo ang wifi_set_ip_info()" @@ -2922,6 +2922,9 @@ msgstr "zero step" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Hindi mabasa ang value ng attribute, status: 0x%08lX" +#~ msgid "Function requires lock." +#~ msgstr "Kailangan ng lock ang function." + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" diff --git a/locale/fr.po b/locale/fr.po index 1710a5ae9..f9c007825 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -764,14 +764,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La fonction nécessite un verrou" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "La fonction nécessite un verrou." - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "le GPIO16 ne supporte pas le tirage (pull-up)" @@ -2902,6 +2898,10 @@ msgstr "type non supporté pour l'opérateur" msgid "unsupported types for %q: '%s', '%s'" msgstr "type non supporté pour %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() a échoué" @@ -2945,6 +2945,9 @@ msgstr "'step' nul" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Impossible de lire la valeur de l'attribut. status: 0x%08lX" +#~ msgid "Function requires lock." +#~ msgstr "La fonction nécessite un verrou." + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" diff --git a/locale/it_IT.po b/locale/it_IT.po index 758307ff3..693f8a03c 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -764,14 +764,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 non supporta pull-up" @@ -2876,6 +2872,10 @@ msgstr "tipo non supportato per l'operando" msgid "unsupported types for %q: '%s', '%s'" msgstr "tipi non supportati per %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() faillito" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 5d00b4e03..587ed00ba 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -757,14 +757,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 não suporta pull up." @@ -2826,6 +2822,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() falhou" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 3612b8d63..91c17f2d1 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -58,14 +58,22 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar uint32_t width = mp_obj_get_int(pos_args[0]); uint32_t height = mp_obj_get_int(pos_args[1]); uint32_t value_count = mp_obj_get_int(pos_args[2]); - uint32_t power_of_two = 1; - while (value_count > (1U << power_of_two)) { - power_of_two <<= 1; + uint32_t bits = 1; + + if (value_count == 0) { + mp_raise_ValueError(translate("value_count must be > 0")); + } + while ((value_count - 1) >> bits) { + if (bits < 8) { + bits <<= 1; + } else { + bits += 8; + } } displayio_bitmap_t *self = m_new_obj(displayio_bitmap_t); self->base.type = &displayio_bitmap_type; - common_hal_displayio_bitmap_construct(self, width, height, power_of_two); + common_hal_displayio_bitmap_construct(self, width, height, bits); return MP_OBJ_FROM_PTR(self); } -- cgit v1.2.3 From d553df95b0e597d4c275f33061b71d2d3168ece9 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Mon, 25 Mar 2019 21:09:15 +0100 Subject: Reuse "Not connected" message in bleio --- shared-bindings/bleio/CharacteristicBuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index 66d164954..c368de361 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -144,7 +144,7 @@ STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r raise_error_if_deinited(common_hal_bleio_characteristic_buffer_deinited(self)); raise_error_if_not_connected(self); if (!common_hal_bleio_characteristic_buffer_connected(self)) { - mp_raise_ValueError(translate("Not connected.")); + mp_raise_ValueError(translate("Not connected")); } mp_uint_t ret; if (request == MP_IOCTL_POLL) { -- cgit v1.2.3