8000 Merge pull request #2647 from dhalbert/enable-bleio-adapter-on-import · adafruit/circuitpython@e9ade63 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9ade63

Browse files
authored
Merge pull request #2647 from dhalbert/enable-bleio-adapter-on-import
Enable _bleio adapter when _bleio is imported
2 parents 6759300 + e31ac71 commit e9ade63

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#define MICROPY_HELPER_REPL (1)
7373
#define MICROPY_KBD_EXCEPTION (1)
7474
#define MICROPY_MEM_STATS (0)
75+
#define MICROPY_MODULE_BUILTIN_INIT (1)
7576
#define MICROPY_NONSTANDARD_TYPECODES (0)
7677
#define MICROPY_OPT_COMPUTED_GOTO (1)
7778
#define MICROPY_PERSISTENT_CODE_LOAD (1)

shared-bindings/_bleio/Adapter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const mp_obj_property_t bleio_adapter_address_obj = {
117117

118118
//| .. attribute:: name
119119
//|
120-
//| name of the BLE adapter used once connected. Not used in advertisements.
120+
//| name of the BLE adapter used once connected.
121121
//| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``,
122122
//| to make it easy to distinguish multiple CircuitPython boards.
123123
//|

shared-bindings/_bleio/__init__.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ NORETURN void mp_raise_bleio_SecurityError(const compressed_string_t* fmt, ...)
132132
nlr_raise(exception);
133133
}
134134

135+
// Called when _bleio is imported.
136+
STATIC mp_obj_t bleio___init__(void) {
137+
common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, true);
138+
return mp_const_none;
139+
}
140+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(bleio___init___obj, bleio___init__);
141+
142+
135143
STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
136144
// Name must be the first entry so that the exception printing below is correct.
137145
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__bleio) },
@@ -156,6 +164,10 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
156164
{ MP_ROM_QSTR(MP_QSTR_ConnectionError), MP_ROM_PTR(&mp_type_bleio_ConnectionError) },
157165
{ MP_ROM_QSTR(MP_QSTR_RoleError), MP_ROM_PTR(&mp_type_bleio_RoleError) },
158166
{ MP_ROM_QSTR(MP_QSTR_SecurityError), MP_ROM_PTR(&mp_type_bleio_SecurityError) },
167+
168+
// Initialization
169+
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&bleio___init___obj) },
170+
159171
};
160172

161173
STATIC MP_DEFINE_CONST_DICT(bleio_module_globals, bleio_module_globals_table);

0 commit comments

Comments
 (0)
0