File tree Expand file tree Collapse file tree 8 files changed +50
-14
lines changed
micropython/bluetooth/aioble/aioble Expand file tree Collapse file tree 8 files changed +50
-14
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,13 @@ def _central_irq(event, data):
86
86
connection ._event .set ()
87
87
88
88
89
- register_irq_handler (_central_irq )
89
+ def _central_shutdown ():
90
+ global _active_scanner , _connecting
91
+ _active_scanner = None
92
+ _connecting = set ()
93
+
94
+
95
+ register_irq_handler (_central_irq , _central_shutdown )
90
96
91
97
92
98
# Cancel an in-progress scan.
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ def _client_irq(event, data):
78
78
ClientCharacteristic ._on_indicate (conn_handle , value_handle , bytes (indicate_data ))
79
79
80
80
81
- register_irq_handler (_client_irq )
81
+ register_irq_handler (_client_irq , None )
82
82
83
83
84
84
# Async generator for discovering services, characteristics, descriptors.
Original file line number Diff line number Diff line change @@ -43,17 +43,24 @@ def config(*args, **kwargs):
43
43
return ble .config (* args , ** kwargs )
44
44
45
45
46
- def stop ():
47
- ble .active (False )
46
+ # Because different functionality is enabled by which files are available the
47
+ # different modules can register their IRQ handlers and shutdown handlers
48
+ # dynamically.
49
+ _irq_handlers = []
50
+ _shutdown_handlers = []
48
51
49
52
50
- # Because different functionality is enabled by which files are available
51
- # the different modules can register their IRQ handlers dynamically.
52
- _irq_handlers = []
53
+ def register_irq_handler (irq , shutdown ):
54
+ if irq :
55
+ _irq_handlers .append (irq )
56
+ if shutdown :
57
+ _shutdown_handlers .append (shutdown )
53
58
54
59
55
- def register_irq_handler (handler ):
56
- _irq_handlers .append (handler )
60
+ def stop ():
61
+ ble .active (False )
62
+ for handler in _shutdown_handlers :
63
+ handler ()
57
64
58
65
59
66
# Dispatch IRQs to the registered sub-modules.
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def _device_irq(event, data):
26
26
device ._mtu_event .set ()
27
27
28
28
29
- register_irq_handler (_device_irq )
29
+ register_irq_handler (_device_irq , None )
30
30
31
31
32
32
# Context manager to allow an operation to be cancelled by timeout or device
Original file line number Diff line number Diff line change @@ -54,7 +54,12 @@ def _l2cap_irq(event, data):
54
54
channel ._event .set ()
55
55
56
56
57
- register_irq_handler (_l2cap_irq )
57
+ def _l2cap_shutdown ():
58
+ global _listening
59
+ _listening = False
60
+
61
+
62
+ register_irq_handler (_l2cap_irq , _l2cap_shutdown )
58
63
59
64
60
65
# The channel was disconnected during a send/recvinto/flush.
Original file line number Diff line number Diff line change @@ -63,7 +63,13 @@ def _peripheral_irq(event, data):
63
63
connection ._event .set ()
64
64
65
65
66
- register_irq_handler (_peripheral_irq )
66
+ def _peripheral_shutdown ():
67
+ global _incoming_connection , _connect_event
68
+ _incoming_connection = None
69
+ _connect_event = None
70
+
71
+
72
+ register_irq_handler (_peripheral_irq , _peripheral_shutdown )
67
73
68
74
69
75
# Advertising payloads are repeated packets of the following form:
Original file line number Diff line number Diff line change @@ -149,7 +149,14 @@ def _security_irq(event, data):
149
149
# log_warn("unknown passkey action")
150
150
151
151
152
- register_irq_handler (_security_irq )
152
+ def _security_shutdown ():
153
+ global _secrets , _modified , _path
154
+ _secrets = {}
155
+ _modified = False
156
+ _path = None
157
+
158
+
159
+ register_irq_handler (_security_irq , _security_shutdown )
153
160
154
161
155
162
# Use device.pair() rather than calling this directly.
Original file line number Diff line number Diff line change @@ -56,7 +56,12 @@ def _server_irq(event, data):
56
56
Characteristic ._indicate_done (conn_handle , value_handle , status )
57
57
58
58
59
- register_irq_handler (_server_irq )
59
+ def _server_shutdown ():
60
+ global _registered_characteristics
61
+ _registered_characteristics = {}
62
+
63
+
64
+ register_irq_handler (_server_irq , _server_shutdown )
60
65
61
66
62
67
class Service :
You can’t perform that action at this time.
0 commit comments