Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve _bleio.Connection.bind() doc, validation, and error messages #9732

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ msgstr ""
msgid "%q, %q, and %q must all be the same length"
msgstr ""

#: py/objint.c shared-bindings/storage/__init__.c
#: py/objint.c shared-bindings/_bleio/Connection.c
#: shared-bindings/storage/__init__.c
msgid "%q=%q"
msgstr ""

Expand Down Expand Up @@ -550,6 +551,10 @@ msgstr ""
msgid "Already have all-matches listener"
msgstr ""

#: ports/espressif/common-hal/_bleio/__init__.c
msgid "Already in progress"
msgstr ""

#: ports/espressif/bindings/espnow/ESPNow.c
#: ports/espressif/common-hal/espulp/ULP.c
#: shared-module/memorymonitor/AllocationAlarm.c
Expand Down Expand Up @@ -3173,10 +3178,6 @@ msgstr ""
msgid "indices must be integers, slices, or Boolean lists"
msgstr ""

#: ports/espressif/common-hal/busio/I2C.c
msgid "init I2C"
msgstr ""

#: extmod/ulab/code/scipy/optimize/optimize.c
msgid "initial values must be iterable"
msgstr ""
Expand Down
3 changes: 3 additions & 0 deletions ports/espressif/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void check_nimble_error(int rc, const char *file, size_t line) {
case BLE_HS_ENOTCONN:
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
return;
case BLE_HS_EALREADY:
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Already in progress"));
return;
default:
#if CIRCUITPY_VERBOSE_BLE || CIRCUITPY_DEBUG
if (file) {
Expand Down
3 changes: 3 additions & 0 deletions ports/nordic/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void check_nrf_error(uint32_t err_code) {
case NRF_ERROR_INVALID_PARAM:
mp_raise_ValueError(MP_ERROR_TEXT("Invalid BLE parameter"));
return;
case NRF_ERROR_INVALID_STATE:
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Invalid state"));
return;
case BLE_ERROR_INVALID_CONN_HANDLE:
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
return;
Expand Down
8 changes: 7 additions & 1 deletion shared-bindings/_bleio/Connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_disconnect_obj, bleio_connecti


//| def pair(self, *, bond: bool = True) -> None:
//| """Pair to the peer to improve security."""
//| """Pair to the peer to improve security.
//|
//| **Limitation**: Currently ``bond``must be ``True``: bonding always occurs.
//| """
//| ...
static mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
Expand All @@ -79,6 +82,9 @@ static mp_obj_t bleio_connection_pair(mp_uint_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);

if (args[ARG_bond].u_bool == false) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q=%q"), MP_QSTR_bond, MP_QSTR_False);
}
bleio_connection_ensure_connected(self);

common_hal_bleio_connection_pair(self->connection, args[ARG_bond].u_bool);
Expand Down