BLE fixes

This commit is contained in:
Dan Halbert 2020-12-21 22:58:17 -05:00
parent 42ca57ff8f
commit 6fd9c4803b
4 changed files with 24 additions and 8 deletions

View File

@ -470,7 +470,16 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t*
ble_drv_add_event_handler(scan_on_ble_evt, self->scan_results);
uint32_t nrf_timeout = SEC_TO_UNITS(timeout, UNIT_10_MS);
if (timeout <= 0.0001) {
if (nrf_timeout > UINT16_MAX) {
// 0xffff / 100
mp_raise_ValueError(translate("timeout must be < 655.35 secs"));
}
if (nrf_timeout == 0 && timeout > 0.0f) {
// Make sure converted timeout is > 0 if original timeout is > 0.
mp_raise_ValueError(translate("non-zero timeout must be > 0.01"));
}
if (nrf_timeout) {
nrf_timeout = BLE_GAP_SCAN_TIMEOUT_UNLIMITED;
}

View File

@ -33,8 +33,8 @@
#include "shared-bindings/_bleio/Address.h"
#include "shared-bindings/_bleio/Adapter.h"
#define ADV_INTERVAL_MIN (0.0020f)
#define ADV_INTERVAL_MIN_STRING "0.0020"
#define ADV_INTERVAL_MIN (0.02001f)
#define ADV_INTERVAL_MIN_STRING "0.02001"
#define ADV_INTERVAL_MAX (10.24f)
#define ADV_INTERVAL_MAX_STRING "10.24"
// 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
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_float_t timeout = 0;
mp_float_t timeout = 0.0f;
if (args[ARG_timeout].u_obj != mp_const_none) {
timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
}
@ -325,6 +325,13 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
if (timeout != 0.0f && timeout < interval) {
mp_raise_ValueError(translate("non-zero timeout must be >= interval"));
}
#pragma GCC diagnostic pop
const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj);
if (window > interval) {
mp_raise_ValueError(translate("window must be <= interval"));

View File

@ -110,8 +110,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
const mp_int_t max_length_int = args[ARG_max_length].u_int;
if (max_length_int <= 0) {
mp_raise_ValueError(translate("max_length must be > 0"));
if (max_length_int < 0) {
mp_raise_ValueError(translate("max_length must be >= 0"));
}
const size_t max_length = (size_t) max_length_int;
const bool fixed_length = args[ARG_fixed_length].u_bool;

View File

@ -101,8 +101,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
const mp_int_t max_length_int = args[ARG_max_length].u_int;
if (max_length_int <= 0) {
mp_raise_ValueError(translate("max_length must be > 0"));
if (max_length_int < 0) {
mp_raise_ValueError(translate("max_length must be >= 0"));
}
const size_t max_length = (size_t) max_length_int;
const bool fixed_length = args[ARG_fixed_length].u_bool;