Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
BTstackBackgroundBackend Class Reference

#include <MIDI_Interfaces/BLEMIDI/BTstackBackgroundBackend.hpp>

Detailed Description

Raspberry Pi Pico BTstack background backend intended to be plugged into GenericBLEMIDI_Interface.

Definition at line 20 of file BTstackBackgroundBackend.hpp.

+ Inheritance diagram for BTstackBackgroundBackend:
+ Collaboration diagram for BTstackBackgroundBackend:

Classes

struct  VolatileSize
 

Public Types

using IncomingMIDIMessage = AnyMIDIMessage
 

Public Member Functions

bool popMessage (IncomingMIDIMessage &incomingMessage)
 Retrieve and remove a single incoming MIDI message from the buffer.
 
void begin (BLESettings ble_settings)
 Initialize the BLE stack etc.
 
void end ()
 Deinitialize the BLE stack.
 
bool isConnected () const
 Returns true if we are connected to a BLE Central device.
 

Private Types

using Sender = PollingBLEMIDISender<BTstackBackgroundBackend>
 

Private Member Functions

void handleConnect (BLEConnectionHandle conn_handle) override
 Called by the BLE stack when a connection is established.
 
void handleDisconnect (BLEConnectionHandle) override
 Called by the BLE stack when a connection is terminated.
 
void handleMTU (BLEConnectionHandle, uint16_t mtu) override
 Called by the BLE stack when the maximum transmission unit for the connection changes.
 
void handleSubscribe (BLEConnectionHandle, BLECharacteristicHandle char_handle, bool notify) override
 Called by the BLE stack when the central subscribes to receive notifications for the MIDI GATT characteristic.
 
void handleData (BLEConnectionHandle, BLEDataGenerator &&data, BLEDataLifetime) override
 Called by the BLE stack when the central writes data to the MIDI GATT characteristic.
 
void sendData (BLEDataView data)
 Send the given MIDI BLE packet.
 
void begin ()
 Initialize.
 
ProtectedBuilder acquirePacket ()
 Acquire exclusive access to the buffer.
 
void releasePacketAndNotify (ProtectedBuilder &lck)
 Release exclusive access to the buffer and notify the sender thread that data is available.
 
void sendNow (ProtectedBuilder &lck)
 Sends the data immediately without waiting for the timeout.
 
void updateMTU (uint16_t mtu)
 Set the maximum transmission unit of the Bluetooth link.
 
uint16_t getMinMTU () const
 Get the minimum MTU of all connected clients.
 
void forceMinMTU (uint16_t mtu)
 Force the MTU to an artificially small value (used for testing).
 
void setTimeout (std::chrono::milliseconds timeout)
 Set the timeout, the number of milliseconds to buffer the outgoing MIDI messages.
 

Private Attributes

volatile sig_atomic_t connected = 0xFFFF
 Are we connected to a BLE Central?
 
volatile sig_atomic_t subscribed = 0xFFFF
 Did the BLE Central subscribe to be notified for the MIDI characteristic?
 
BufferedBLEMIDIParser< 1024, VolatileSizeparser
 Contains incoming BLE MIDI data to be parsed.
 
friend Sender
 
BLEMIDIPacketBuilder packet
 View of the data to send.
 
unsigned long timeout
 Timeout before the sender thread sends a packet.
 
unsigned long packet_start_time
 Time point when the packet was started.
 
uint16_t min_mtu
 The minimum MTU of all connected clients.
 
uint16_t force_min_mtu
 Override the minimum MTU (0 means don't override, nonzero overrides if it's smaller than the minimum MTU of the clients).
 

Member Typedef Documentation

◆ IncomingMIDIMessage

Definition at line 88 of file BTstackBackgroundBackend.hpp.

◆ Sender

Definition at line 114 of file BTstackBackgroundBackend.hpp.

Member Function Documentation

◆ handleConnect()

void handleConnect ( BLEConnectionHandle conn_handle)
inlineoverrideprivatevirtual

Called by the BLE stack when a connection is established.

Implements MIDIBLEInstance.

Definition at line 25 of file BTstackBackgroundBackend.hpp.

◆ handleDisconnect()

void handleDisconnect ( BLEConnectionHandle conn_handle)
inlineoverrideprivatevirtual

Called by the BLE stack when a connection is terminated.

Implements MIDIBLEInstance.

Definition at line 28 of file BTstackBackgroundBackend.hpp.

◆ handleMTU()

void handleMTU ( BLEConnectionHandle conn_handle,
uint16_t mtu )
inlineoverrideprivatevirtual

Called by the BLE stack when the maximum transmission unit for the connection changes.

Implements MIDIBLEInstance.

Definition at line 31 of file BTstackBackgroundBackend.hpp.

◆ handleSubscribe()

void handleSubscribe ( BLEConnectionHandle conn_handle,
BLECharacteristicHandle char_handle,
bool notify )
inlineoverrideprivatevirtual

Called by the BLE stack when the central subscribes to receive notifications for the MIDI GATT characteristic.

Implements MIDIBLEInstance.

Definition at line 34 of file BTstackBackgroundBackend.hpp.

◆ handleData()

void handleData ( BLEConnectionHandle conn_handle,
BLEDataGenerator && data,
BLEDataLifetime lifetime )
inlineoverrideprivatevirtual

Called by the BLE stack when the central writes data to the MIDI GATT characteristic.

Implements MIDIBLEInstance.

Definition at line 39 of file BTstackBackgroundBackend.hpp.

◆ popMessage()

bool popMessage ( IncomingMIDIMessage & incomingMessage)
inline

Retrieve and remove a single incoming MIDI message from the buffer.

Definition at line 91 of file BTstackBackgroundBackend.hpp.

◆ begin() [1/2]

void begin ( BLESettings ble_settings)
inline

Initialize the BLE stack etc.

Definition at line 102 of file BTstackBackgroundBackend.hpp.

◆ end()

void end ( )
inline

Deinitialize the BLE stack.

Definition at line 108 of file BTstackBackgroundBackend.hpp.

◆ isConnected()

bool isConnected ( ) const
inline

Returns true if we are connected to a BLE Central device.

Definition at line 110 of file BTstackBackgroundBackend.hpp.

◆ sendData()

void sendData ( BLEDataView data)
inlineprivate

Send the given MIDI BLE packet.

Definition at line 117 of file BTstackBackgroundBackend.hpp.

◆ begin() [2/2]

void begin ( )
inherited

Initialize.

◆ acquirePacket()

ProtectedBuilder acquirePacket ( )
inherited

Acquire exclusive access to the buffer.

Returns
A RAII wrapper that automatically releases the buffer upon destruction. Just make sure you don't keep any pointers to the packet member.

◆ releasePacketAndNotify()

void releasePacketAndNotify ( ProtectedBuilder & lck)
inherited

Release exclusive access to the buffer and notify the sender thread that data is available.

◆ sendNow()

void sendNow ( ProtectedBuilder & lck)
inherited

Sends the data immediately without waiting for the timeout.

◆ updateMTU()

void updateMTU ( uint16_t mtu)
inherited

Set the maximum transmission unit of the Bluetooth link.

Used to compute the MIDI BLE packet size.

◆ getMinMTU()

uint16_t getMinMTU ( ) const
inlineinherited

Get the minimum MTU of all connected clients.

Definition at line 42 of file PollingBLEMIDISender.hpp.

◆ forceMinMTU()

void forceMinMTU ( uint16_t mtu)
inherited

Force the MTU to an artificially small value (used for testing).

◆ setTimeout()

void setTimeout ( std::chrono::milliseconds timeout)
inherited

Set the timeout, the number of milliseconds to buffer the outgoing MIDI messages.

Member Data Documentation

◆ connected

volatile sig_atomic_t connected = 0xFFFF
private

Are we connected to a BLE Central?

Definition at line 57 of file BTstackBackgroundBackend.hpp.

◆ subscribed

volatile sig_atomic_t subscribed = 0xFFFF
private

Did the BLE Central subscribe to be notified for the MIDI characteristic?

Definition at line 59 of file BTstackBackgroundBackend.hpp.

◆ parser

BufferedBLEMIDIParser<1024, VolatileSize> parser
private

Contains incoming BLE MIDI data to be parsed.

Definition at line 85 of file BTstackBackgroundBackend.hpp.

◆ Sender

friend Sender
private

Definition at line 115 of file BTstackBackgroundBackend.hpp.

◆ packet

BLEMIDIPacketBuilder packet
privateinherited

View of the data to send.

Definition at line 56 of file PollingBLEMIDISender.hpp.

◆ timeout

unsigned long timeout
privateinherited

Timeout before the sender thread sends a packet.

See also
setTimeout()

Definition at line 59 of file PollingBLEMIDISender.hpp.

◆ packet_start_time

unsigned long packet_start_time
privateinherited

Time point when the packet was started.

Definition at line 61 of file PollingBLEMIDISender.hpp.

◆ min_mtu

uint16_t min_mtu
privateinherited

The minimum MTU of all connected clients.

Definition at line 65 of file PollingBLEMIDISender.hpp.

◆ force_min_mtu

uint16_t force_min_mtu
privateinherited

Override the minimum MTU (0 means don't override, nonzero overrides if it's smaller than the minimum MTU of the clients).

See also
forceMinMTU()

Definition at line 69 of file PollingBLEMIDISender.hpp.


The documentation for this class was generated from the following file: