diff --git a/shared-bindings/_bleio/ScanEntry.c b/shared-bindings/_bleio/ScanEntry.c index 5cb98a80c1..531986f349 100644 --- a/shared-bindings/_bleio/ScanEntry.c +++ b/shared-bindings/_bleio/ScanEntry.c @@ -45,28 +45,32 @@ //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... //| -//| def matches(self, prefixes: ScanEntry, *, all: bool = True) -> bool: -//| """Returns True if the ScanEntry matches all prefixes when ``all`` is True. This is stricter +//| def matches(self, prefixes: ScanEntry, *, match_all: bool = True) -> bool: +//| """Returns True if the ScanEntry matches all prefixes when ``match_all`` is True. This is stricter //| than the scan filtering which accepts any advertisements that match any of the prefixes -//| where all is False.""" +//| where ``match_all`` is False. +//| +//| ``all`` also works for ``match_all`` but will be removed in CircuitPython 8.""" //| ... //| STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_prefixes, ARG_all }; + enum { ARG_prefixes, ARG_all, ARG_match_all }; static const mp_arg_t allowed_args[] = { { MP_QSTR_prefixes, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_all, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, + { MP_QSTR_match_all, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, }; 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); + bool match_all = args[ARG_all].u_bool && args[ARG_match_all].u_bool; mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_prefixes].u_obj, &bufinfo, MP_BUFFER_READ); - return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, args[ARG_all].u_bool)); + return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, match_all)); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanentry_matches_obj, 2, bleio_scanentry_matches); diff --git a/shared-bindings/_bleio/ScanEntry.h b/shared-bindings/_bleio/ScanEntry.h index b37cb61097..35473fd50e 100644 --- a/shared-bindings/_bleio/ScanEntry.h +++ b/shared-bindings/_bleio/ScanEntry.h @@ -39,6 +39,6 @@ mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_ mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self); bool common_hal_bleio_scanentry_get_connectable(bleio_scanentry_obj_t *self); bool common_hal_bleio_scanentry_get_scan_response(bleio_scanentry_obj_t *self); -bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, uint8_t *prefixes, size_t prefixes_len, bool all); +bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, uint8_t *prefixes, size_t prefixes_len, bool match_all); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H diff --git a/shared-module/_bleio/ScanEntry.c b/shared-module/_bleio/ScanEntry.c index 28ff215a35..065d23d4f4 100644 --- a/shared-module/_bleio/ScanEntry.c +++ b/shared-module/_bleio/ScanEntry.c @@ -91,6 +91,6 @@ bool bleio_scanentry_data_matches(const uint8_t *data, size_t len, const uint8_t return !any; } -bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t *prefixes, size_t prefixes_len, bool all) { - return bleio_scanentry_data_matches(self->data->data, self->data->len, prefixes, prefixes_len, !all); +bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t *prefixes, size_t prefixes_len, bool match_all) { + return bleio_scanentry_data_matches(self->data->data, self->data->len, prefixes, prefixes_len, !match_all); }