blatann.examples.central_event_driven module¶
This example demonstrates programming with blatann in an event-driven, object-oriented manner. The BLE device is set up in the main context, however all logic past that point is done using event callbacks. The main context is blocked by a “GenericWaitable”, which is notified when the program completes its intended function.
The program’s logic itself is equivalent to the central example, where it connects and pairs to a device, registers a notification callback for the counting characteristic, then tests out the conversion of strings to hex.
One thing to note: when using event-driven callbacks, it is imperative that the callbacks themselves do not ever block on events (i.e. use the .wait() functionality). If this happens, you are essentially blocking the event thread from processing any more events and will wait indefinitely. A good rule of thumb when using blatann is just to not mix blocking and non-blocking calls.
This is designed to work alongside the peripheral example running on a separate nordic chip
- class blatann.examples.central_event_driven.HexConverterTest(characteristic, waitable)¶
Bases:
object
Class to perform the hex conversion process. It is passed in the hex conversion characteristic and the waitable to signal when the process completes
- start()¶
Starts a new hex conversion process by writing the data to the peripheral’s characteristic
- class blatann.examples.central_event_driven.MyPeripheralConnection(peer, waitable)¶
Bases:
object
Class to handle the post-connection database discovery and pairing process
- class blatann.examples.central_event_driven.ConnectionManager(ble_device, exit_waitable)¶
Bases:
object
Manages scanning and connecting to the target peripheral
- scan_and_connect(name, timeout=4)¶
Starts the scanning process and sets up the callback for when scanning completes
- Parameters
name – The name of the peripheral to look for
timeout – How long to scan for
- blatann.examples.central_event_driven.main(serial_port)¶