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

#include <MIDI_Interfaces/BLEMIDI/ArduinoBLEBackend.hpp>

Detailed Description

ArduinoBLE backend intended to be plugged into GenericBLEMIDI_Interface.

Definition at line 14 of file ArduinoBLEBackend.hpp.

+ Inheritance diagram for ArduinoBLEBackend:
+ Collaboration diagram for ArduinoBLEBackend:

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<ArduinoBLEBackend>
 

Private Member Functions

void handleConnect (BLEConnectionHandle) 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, 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

bool connected = false
 Are we connected to a BLE Central?
 
bool subscribed = false
 Did the BLE Central subscribe to be notified for the MIDI characteristic?
 
BufferedBLEMIDIParser< 1024 > parser
 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 51 of file ArduinoBLEBackend.hpp.

◆ Sender

Definition at line 79 of file ArduinoBLEBackend.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 18 of file ArduinoBLEBackend.hpp.

◆ handleDisconnect()

void handleDisconnect ( BLEConnectionHandle conn_handle)
inlineoverrideprivatevirtual

Called by the BLE stack when a connection is terminated.

Implements MIDIBLEInstance.

Definition at line 19 of file ArduinoBLEBackend.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 22 of file ArduinoBLEBackend.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 25 of file ArduinoBLEBackend.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 29 of file ArduinoBLEBackend.hpp.

◆ popMessage()

bool popMessage ( IncomingMIDIMessage & incomingMessage)
inline

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

Definition at line 54 of file ArduinoBLEBackend.hpp.

◆ begin() [1/2]

void begin ( BLESettings ble_settings)
inline

Initialize the BLE stack etc.

Definition at line 67 of file ArduinoBLEBackend.hpp.

◆ end()

void end ( )
inline

Deinitialize the BLE stack.

Definition at line 73 of file ArduinoBLEBackend.hpp.

◆ isConnected()

bool isConnected ( ) const
inline

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

Definition at line 75 of file ArduinoBLEBackend.hpp.

◆ sendData()

void sendData ( BLEDataView data)
inlineprivate

Send the given MIDI BLE packet.

Definition at line 82 of file ArduinoBLEBackend.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

bool connected = false
private

Are we connected to a BLE Central?

Definition at line 44 of file ArduinoBLEBackend.hpp.

◆ subscribed

bool subscribed = false
private

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

Definition at line 46 of file ArduinoBLEBackend.hpp.

◆ parser

BufferedBLEMIDIParser<1024> parser
private

Contains incoming BLE MIDI data to be parsed.

Definition at line 48 of file ArduinoBLEBackend.hpp.

◆ Sender

friend Sender
private

Definition at line 80 of file ArduinoBLEBackend.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: