Skip to content

Commit 5be8751

Browse files
committed
pybricks.iodevices.lwp3device: Add disconnect method.
Fixes pybricks/support#802
1 parent ce8a7c9 commit 5be8751

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
### Added
88
- Added optional keyword arguments to `pybricks.tools.read_input_byte()` for
99
automatic conversion via `chr` and to skip to the last byte ([support#1574]).
10+
- Added `disconnect` method to `pybricks.pupdevices.Remote` and
11+
`pybricks.iodevices.LWP3Device` ([support#802]).
1012

1113
### Changed
1214
- Raise a descriptive error when the `Car` class can't find a steering mechanism
@@ -15,6 +17,7 @@
1517
### Fixed
1618
- Fixed hubs not shutting down when holding hub button ([support#1419]).
1719

20+
[support#802]: https://github.com/pybricks/support/issues/802
1821
[support#1419]: https://github.com/pybricks/support/issues/1419
1922
[support#1564]: https://github.com/pybricks/support/issues/1564
2023
[support#1574]: https://github.com/pybricks/support/issues/1574

pybricks/iodevices/pb_type_iodevices_lwp3device.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,22 @@ STATIC mp_obj_t pb_lwp3device_name(size_t n_args, const mp_obj_t *args) {
433433
}
434434
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pb_lwp3device_name_obj, 1, 2, pb_lwp3device_name);
435435

436+
STATIC mp_obj_t pb_lwp3device_disconnect(mp_obj_t self_in) {
437+
pb_lwp3device_t *lwp3device = &pb_lwp3device_singleton;
438+
pb_lwp3device_assert_connected();
439+
pbdrv_bluetooth_peripheral_disconnect(&lwp3device->task);
440+
return pb_module_tools_pbio_task_wait_or_await(&lwp3device->task);
441+
}
442+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pb_lwp3device_disconnect_obj, pb_lwp3device_disconnect);
443+
436444
STATIC const pb_attr_dict_entry_t pb_type_pupdevices_Remote_attr_dict[] = {
437445
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_buttons, pb_type_pupdevices_Remote_obj_t, buttons),
438446
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_light, pb_type_pupdevices_Remote_obj_t, light),
439447
PB_ATTR_DICT_SENTINEL
440448
};
441449

442450
STATIC const mp_rom_map_elem_t pb_type_pupdevices_Remote_locals_dict_table[] = {
451+
{ MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&pb_lwp3device_disconnect_obj) },
443452
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pb_lwp3device_name_obj) },
444453
};
445454
STATIC MP_DEFINE_CONST_DICT(pb_type_pupdevices_Remote_locals_dict, pb_type_pupdevices_Remote_locals_dict_table);
@@ -525,6 +534,7 @@ STATIC mp_obj_t lwp3device_read(mp_obj_t self_in) {
525534
STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwp3device_read_obj, lwp3device_read);
526535

527536
STATIC const mp_rom_map_elem_t pb_type_iodevices_LWP3Device_locals_dict_table[] = {
537+
{ MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&pb_lwp3device_disconnect_obj) },
528538
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pb_lwp3device_name_obj) },
529539
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&lwp3device_write_obj) },
530540
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&lwp3device_read_obj) },

0 commit comments

Comments
 (0)