mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
extmod/modbluetooth: Simplify management of pre-allocated event data.
The address, adv payload and uuid fields of the event are pre-allocated by modbluetooth, and reused in the IRQ handler. Simplify this and move all storage into the `mp_obj_bluetooth_ble_t` instance. This now allows users to hold on to a reference to these instances without crashes, although they may be overwritten by future events. If they want to hold onto the values longer term they need to copy them.
This commit is contained in:
committed by
Damien George
parent
fbb7646e3b
commit
e873d352ad
@@ -52,6 +52,12 @@ Event Handling
|
||||
The optional *trigger* parameter allows you to set a mask of events that
|
||||
your program is interested in. The default is all events.
|
||||
|
||||
Note: the ``addr``, ``adv_data`` and ``uuid`` entries in the tuples are
|
||||
references to data managed by the :mod:`ubluetooth` module (i.e. the same
|
||||
instance will be re-used across multiple calls to the event handler). If
|
||||
your program wants to use this data outside of the handler, then it must
|
||||
copy them first, e.g. by using ``bytes(addr)`` or ``bluetooth.UUID(uuid)``.
|
||||
|
||||
An event handler showing all possible events::
|
||||
|
||||
def bt_irq(event, data):
|
||||
|
||||
Reference in New Issue
Block a user