10000 Merge pull request #3861 from dhalbert/ble-fixes-6.0.x · domdfcoding/circuitpython@3266720 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3266720

Browse files
authored
Merge pull request adafruit#3861 from dhalbert/ble-fixes-6.0.x
BLE fixes
2 parents 42ca57f + 078a799 commit 3266720

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

locale/circuitpython.pot

Lines changed: 14 additions & 2 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-11-04 21:18+0530\n"
11+
"POT-Creation-Date: 2020-12-21 23:48-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 <LL@li.org>\n"
@@ -2861,7 +2861,7 @@ msgid "max_length must be 0-%d when fixed_length is %s"
28612861
msgstr ""
28622862

28632863
#: shared-bindings/_bleio/Characteristic.c shared-bindings/_bleio/Descriptor.c
2864-
msgid "max_length must be > 0"
2864+
msgid "max_length must be >= 0"
28652865
msgstr ""
28662866

28672867
#: py/runtime.c
@@ -2999,6 +2999,14 @@ msgstr ""
29992999
msgid "non-keyword arg after keyword arg"
30003000
msgstr ""
30013001

3002+
#: ports/nrf/common-hal/_bleio/Adapter.c
3003+
msgid "non-zero timeout must be > 0.01"
3004+
msgstr ""
3005+
3006+
#: shared-bindings/_bleio/Adapter.c
3007+
msgid "non-zero timeout must be >= interval"
3008+
msgstr ""
3009+
30023010
#: shared-bindings/_bleio/UUID.c
30033011
msgid "not a 128-bit UUID"
30043012
msgstr ""
@@ -3400,6 +3408,10 @@ msgstr ""
34003408
msgid "timeout must be 0.0-100.0 seconds"
34013409
msgstr ""
34023410

3411+
#: ports/nrf/common-hal/_bleio/Adapter.c
3412+
msgid "timeout must be < 655.35 secs"
3413+
msgstr ""
3414+
34033415
#: shared-bindings/_bleio/CharacteristicBuffer.c
34043416
msgid "timeout must be >= 0.0"
34053417
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 9951 = (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)
0