Skip to content

Commit 40b0857

Browse files
authored
Merge pull request #5006 from tannewt/scanentry_match_all
ScanEntry.matches() kwarg all -> match_all
2 parents 2afd3c2 + 448597b commit 40b0857

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

shared-bindings/_bleio/ScanEntry.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,32 @@
4545
//| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`."""
4646
//| ...
4747
//|
48-
//| def matches(self, prefixes: ScanEntry, *, all: bool = True) -> bool:
49-
//| """Returns True if the ScanEntry matches all prefixes when ``all`` is True. This is stricter
48+
//| def matches(self, prefixes: ScanEntry, *, match_all: bool = True) -> bool:
49+
//| """Returns True if the ScanEntry matches all prefixes when ``match_all`` is True. This is stricter
5050
//| than the scan filtering which accepts any advertisements that match any of the prefixes
51-
//| where all is False."""
51+
//| where ``match_all`` is False.
52+
//|
53+
//| ``all`` also works for ``match_all`` but will be removed in CircuitPython 8."""
5254
//| ...
5355
//|
5456
STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
5557
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
5658

57-
enum { ARG_prefixes, ARG_all };
59+
enum { ARG_prefixes, ARG_all, ARG_match_all };
5860
static const mp_arg_t allowed_args[] = {
5961
{ MP_QSTR_prefixes, MP_ARG_OBJ | MP_ARG_REQUIRED },
6062
{ MP_QSTR_all, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
63+
{ MP_QSTR_match_all, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
6164
};
6265

6366
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
6467
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
6568

69+
bool match_all = args[ARG_all].u_bool && args[ARG_match_all].u_bool;
6670

6771
mp_buffer_info_t bufinfo;
6872
mp_get_buffer_raise(args[ARG_prefixes].u_obj, &bufinfo, MP_BUFFER_READ);
69-
return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, args[ARG_all].u_bool));
73+
return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, match_all));
7074
}
7175
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanentry_matches_obj, 2, bleio_scanentry_matches);
7276

shared-bindings/_bleio/ScanEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_
3939
mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self);
4040
bool common_hal_bleio_scanentry_get_connectable(bleio_scanentry_obj_t *self);
4141
bool common_hal_bleio_scanentry_get_scan_response(bleio_scanentry_obj_t *self);
42-
bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, uint8_t *prefixes, size_t prefixes_len, bool all);
42+
bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, uint8_t *prefixes, size_t prefixes_len, bool match_all);
4343

4444
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H

shared-module/_bleio/ScanEntry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ bool bleio_scanentry_data_matches(const uint8_t *data, size_t len, const uint8_t
9191
return !any;
9292
}
9393

94-
bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t *prefixes, size_t prefixes_len, bool all) {
95-
return bleio_scanentry_data_matches(self->data->data, self->data->len, prefixes, prefixes_len, !all);
94+
bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t *prefixes, size_t prefixes_len, bool match_all) {
95+
return bleio_scanentry_data_matches(self->data->data, self->data->len, prefixes, prefixes_len, !match_all);
9696
}

0 commit comments

Comments
 (0)