Skip to content

Commit a1e3ab1

Browse files
authored
Merge pull request #3874 from dhalbert/ble-fixes-6.0.x-to-main
Merge ble-fixes from 6.0.x to main
2 parents 966f4de + 153a686 commit a1e3ab1

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

locale/circuitpython.pot

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-12-14 12:59-0500\n"
11+
"POT-Creation-Date: 2020-12-23 16:41-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -949,10 +949,6 @@ msgstr ""
949949
msgid "Framebuffer requires %d bytes"
950950
msgstr ""
951951

952-
#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c
953-
msgid "Frequency captured is above capability. Capture Paused."
954-
msgstr ""
955-
956952
#: ports/stm/common-hal/pwmio/PWMOut.c
957953
msgid "Frequency must match existing PWMOut using this timer"
958954
msgstr ""
@@ -3009,7 +3005,7 @@ msgid "max_length must be 0-%d when fixed_length is %s"
30093005
msgstr ""
30103006

30113007
#: shared-bindings/_bleio/Characteristic.c shared-bindings/_bleio/Descriptor.c
3012-
msgid "max_length must be > 0"
3008+
msgid "max_length must be >= 0"
30133009
msgstr ""
30143010

30153011
#: extmod/ulab/code/ndarray.c
@@ -3147,6 +3143,14 @@ msgstr ""
31473143
msgid "non-keyword arg after keyword arg"
31483144
msgstr ""
31493145

3146+
#: ports/nrf/common-hal/_bleio/Adapter.c
3147+
msgid "non-zero timeout must be > 0.01"
3148+
msgstr ""
3149+
3150+
#: shared-bindings/_bleio/Adapter.c
3151+
msgid "non-zero timeout must be >= interval"
3152+
msgstr ""
3153+
31503154
#: extmod/ulab/code/linalg/linalg.c
31513155
msgid "norm is defined for 1D and 2D arrays"
31523156
msgstr ""
@@ -3568,6 +3572,10 @@ msgstr ""
35683572
msgid "timeout must be 0.0-100.0 seconds"
35693573
msgstr ""
35703574

3575+
#: ports/nrf/common-hal/_bleio/Adapter.c
3576+
msgid "timeout must be < 655.35 secs"
3577+
msgstr ""
3578+
35713579
#: shared-bindings/_bleio/CharacteristicBuffer.c
35723580
msgid "timeout must be >= 0.0"
35733581
msgstr ""

ports/nrf/common-hal/_bleio/Adapter.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,16 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t*
470470
ble_drv_add_event_handler(scan_on_ble_evt, self->scan_results);
471471

472472
uint32_t nrf_timeout = SEC_TO_UNITS(timeout, UNIT_10_MS);
473-
if (timeout <= 0.0001) {
473+
if (nrf_timeout > UINT16_MAX) {
474+
// 0xffff / 100
475+
mp_raise_ValueError(translate("timeout must be < 655.35 secs"));
476+
}
477+
if (nrf_timeout == 0 && timeout > 0.0f) {
478+
// Make sure converted timeout is > 0 if original timeout is > 0.
479+
mp_raise_ValueError(translate("non-zero timeout must be > 0.01"));
480+
}
481+
482+
if (nrf_timeout) {
474483
nrf_timeout = BLE_GAP_SCAN_TIMEOUT_UNLIMITED;
475484
}
476485

shared-bindings/_bleio/Adapter.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include "shared-bindings/_bleio/Address.h"
3434
#include "shared-bindings/_bleio/Adapter.h"
3535

36-
#define ADV_INTERVAL_MIN (0.0020f)
37-
#define ADV_INTERVAL_MIN_STRING "0.0020"
36+
#define ADV_INTERVAL_MIN (0.02001f)
37+
#define ADV_INTERVAL_MIN_STRING "0.02001"
3838
#define ADV_INTERVAL_MAX (10.24f)
3939
#define ADV_INTERVAL_MAX_STRING "10.24"
4040
// 20ms is recommended by Apple
@@ -307,7 +307,7 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
307307
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
308308
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
309309

310-
mp_float_t timeout = 0;
310+
mp_float_t timeout = 0.0f;
311311
if (args[ARG_timeout].u_obj != mp_const_none) {
312312
timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
313313
}
@@ -325,6 +325,13 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
325325
mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING);
326326
}
327327

328+
#pragma GCC diagnostic push
329+
#pragma GCC diagnostic ignored "-Wfloat-equal"
330+
if (timeout != 0.0f && timeout < interval) {
331+
mp_raise_ValueError(translate("non-zero timeout must be >= interval"));
332+
}
333+
#pragma GCC diagnostic pop
334+
328335
const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj);
329336
if (window > interval) {
330337
mp_raise_ValueError(translate("window must be <= interval"));

shared-bindings/_bleio/Characteristic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
110110
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
111111

112112
const mp_int_t max_length_int = args[ARG_max_length].u_int;
113-
if (max_length_int <= 0) {
114-
mp_raise_ValueError(translate("max_length must be > 0"));
113+
if (max_length_int < 0) {
114+
mp_raise_ValueError(translate("max_length must be >= 0"));
115115
}
116116
const size_t max_length = (size_t) max_length_int;
117117
const bool fixed_length = args[ARG_fixed_length].u_bool;

shared-bindings/_bleio/Descriptor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
101101
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
102102

103103
const mp_int_t max_length_int = args[ARG_max_length].u_int;
104-
if (max_length_int <= 0) {
105-
mp_raise_ValueError(translate("max_length must be > 0"));
104+
if (max_length_int < 0) {
105+
mp_raise_ValueError(translate("max_length must be >= 0"));
106106
}
107107
const size_t max_length = (size_t) max_length_int;
108108
const bool fixed_length = args[ARG_fixed_length].u_bool;

0 commit comments

Comments
 (0)