kopia lustrzana https://github.com/micropython/micropython-lib
aioble: Add a shutdown handler for cleanup.
This allows `aioble.stop()` to reset all internal state. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>pull/426/head
rodzic
a61bfc1460
commit
10ec742baa
|
@ -86,7 +86,13 @@ def _central_irq(event, data):
|
|||
connection._event.set()
|
||||
|
||||
|
||||
register_irq_handler(_central_irq)
|
||||
def _central_shutdown():
|
||||
global _active_scanner, _connecting
|
||||
_active_scanner = None
|
||||
_connecting = set()
|
||||
|
||||
|
||||
register_irq_handler(_central_irq, _central_shutdown)
|
||||
|
||||
|
||||
# Cancel an in-progress scan.
|
||||
|
|
|
@ -78,7 +78,7 @@ def _client_irq(event, data):
|
|||
ClientCharacteristic._on_indicate(conn_handle, value_handle, bytes(indicate_data))
|
||||
|
||||
|
||||
register_irq_handler(_client_irq)
|
||||
register_irq_handler(_client_irq, None)
|
||||
|
||||
|
||||
# Async generator for discovering services, characteristics, descriptors.
|
||||
|
|
|
@ -43,17 +43,24 @@ def config(*args, **kwargs):
|
|||
return ble.config(*args, **kwargs)
|
||||
|
||||
|
||||
# Because different functionality is enabled by which files are available the
|
||||
# different modules can register their IRQ handlers and shutdown handlers
|
||||
# dynamically.
|
||||
_irq_handlers = []
|
||||
_shutdown_handlers = []
|
||||
|
||||
|
||||
def register_irq_handler(irq, shutdown):
|
||||
if irq:
|
||||
_irq_handlers.append(irq)
|
||||
if shutdown:
|
||||
_shutdown_handlers.append(shutdown)
|
||||
|
||||
|
||||
def stop():
|
||||
ble.active(False)
|
||||
|
||||
|
||||
# Because different functionality is enabled by which files are available
|
||||
# the different modules can register their IRQ handlers dynamically.
|
||||
_irq_handlers = []
|
||||
|
||||
|
||||
def register_irq_handler(handler):
|
||||
_irq_handlers.append(handler)
|
||||
for handler in _shutdown_handlers:
|
||||
handler()
|
||||
|
||||
|
||||
# Dispatch IRQs to the registered sub-modules.
|
||||
|
|
|
@ -26,7 +26,7 @@ def _device_irq(event, data):
|
|||
device._mtu_event.set()
|
||||
|
||||
|
||||
register_irq_handler(_device_irq)
|
||||
register_irq_handler(_device_irq, None)
|
||||
|
||||
|
||||
# Context manager to allow an operation to be cancelled by timeout or device
|
||||
|
|
|
@ -54,7 +54,12 @@ def _l2cap_irq(event, data):
|
|||
channel._event.set()
|
||||
|
||||
|
||||
register_irq_handler(_l2cap_irq)
|
||||
def _l2cap_shutdown():
|
||||
global _listening
|
||||
_listening = False
|
||||
|
||||
|
||||
register_irq_handler(_l2cap_irq, _l2cap_shutdown)
|
||||
|
||||
|
||||
# The channel was disconnected during a send/recvinto/flush.
|
||||
|
|
|
@ -63,7 +63,13 @@ def _peripheral_irq(event, data):
|
|||
connection._event.set()
|
||||
|
||||
|
||||
register_irq_handler(_peripheral_irq)
|
||||
def _peripheral_shutdown():
|
||||
global _incoming_connection, _connect_event
|
||||
_incoming_connection = None
|
||||
_connect_event = None
|
||||
|
||||
|
||||
register_irq_handler(_peripheral_irq, _peripheral_shutdown)
|
||||
|
||||
|
||||
# Advertising payloads are repeated packets of the following form:
|
||||
|
|
|
@ -149,7 +149,14 @@ def _security_irq(event, data):
|
|||
# log_warn("unknown passkey action")
|
||||
|
||||
|
||||
register_irq_handler(_security_irq)
|
||||
def _security_shutdown():
|
||||
global _secrets, _modified, _path
|
||||
_secrets = {}
|
||||
_modified = False
|
||||
_path = None
|
||||
|
||||
|
||||
register_irq_handler(_security_irq, _security_shutdown)
|
||||
|
||||
|
||||
# Use device.pair() rather than calling this directly.
|
||||
|
|
|
@ -56,7 +56,12 @@ def _server_irq(event, data):
|
|||
Characteristic._indicate_done(conn_handle, value_handle, status)
|
||||
|
||||
|
||||
register_irq_handler(_server_irq)
|
||||
def _server_shutdown():
|
||||
global _registered_characteristics
|
||||
_registered_characteristics = {}
|
||||
|
||||
|
||||
register_irq_handler(_server_irq, _server_shutdown)
|
||||
|
||||
|
||||
class Service:
|
||||
|
|
Ładowanie…
Reference in New Issue