Skip to content

Commit

Permalink
improve _bleio.Connection.bind() doc, validation, and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed Oct 18, 2024
1 parent 57fa43a commit ac0904e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
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

0 comments on commit ac0904e

Please sign in to comment.