Skip to content

Commit c82566c

Browse files
authored
Merge pull request #98 from lathoub/CustomSettings
Custom settings, thanks @RobertoHE et al
2 parents 2e4b39f + 04babb8 commit c82566c

13 files changed

+658
-499
lines changed

ci/build-arduino.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ shopt -s globstar
66
# Make sure we are inside the github workspace
77
cd $GITHUB_WORKSPACE
88
# Create directories
9-
mkdir $HOME/Arduino
10-
mkdir $HOME/Arduino/libraries
9+
mkdir $HOME/Arduino -p
10+
mkdir $HOME/Arduino/libraries -p
1111
# Install Arduino IDE
1212
export PATH=$PATH:$GITHUB_WORKSPACE/bin
1313
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
1414
arduino-cli config init
1515
arduino-cli config set library.enable_unsafe_install true
1616
# arduino-cli core update-index --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
17-
arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
17+
#arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
18+
sed -i 's+\[\]+\[https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json\]+g' /home/runner/.arduino15/arduino-cli.yaml
1819
arduino-cli core update-index
1920

2021
# Install Arduino AVR core
@@ -24,13 +25,13 @@ arduino-cli core install arduino:samd
2425
arduino-cli core install esp32:esp32
2526

2627
# List the boards
27-
arduino-cli board list
28+
arduino-cli board listall
2829

2930
# Link Arduino library
3031
ln -s $GITHUB_WORKSPACE $HOME/Arduino/libraries/CI_Test_Library
3132

3233
arduino-cli lib install "MIDI library"
33-
arduino-cli lib install ArduinoBLE
34+
#arduino-cli lib install ArduinoBLE
3435
arduino-cli lib install NimBLE-Arduino
3536

3637
# Compile all *.ino files for the Arduino Uno
@@ -48,7 +49,14 @@ arduino-cli lib install NimBLE-Arduino
4849
# arduino-cli compile -b arduino:esp8266:??? $f
4950
# done
5051

52+
dR=$(pwd)
53+
5154
# Compile all *.ino files for the Arduino Uno
5255
for f in **/*.ino ; do
53-
arduino-cli compile -b arduino:esp32:??? $f
56+
echo "Project: $f"
57+
d=$(dirname $(readlink -f $f))
58+
echo $d
59+
cd $d
60+
arduino-cli compile -b esp32:esp32:esp32 *.ino --clean
61+
cd $dR
5462
done
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include <BLEMIDI_Transport.h>
2+
3+
static uint32_t customPasskeyRequest()
4+
{
5+
// FILL WITH YOUR CUSTOM AUTH METHOD CODE or PASSKEY
6+
// FOR EXAMPLE:
7+
uint32_t passkey = 123456;
8+
9+
// Serial.println("Client Passkey Request");
10+
11+
/** return the passkey to send to the server */
12+
return passkey;
13+
};
14+
15+
struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings {
16+
//See all options and them explanation in the library.
17+
18+
/*
19+
##### BLE DEVICE NAME #####
20+
*/
21+
//static constexpr char *name = "BleMidiClient";
22+
/*
23+
###### TX POWER #####
24+
*/
25+
//static const esp_power_level_t clientTXPwr = ESP_PWR_LVL_P9;
26+
/*
27+
###### SECURITY #####
28+
*/
29+
//static const uint8_t clientSecurityCapabilities = BLE_HS_IO_NO_INPUT_OUTPUT;
30+
//static const bool clientBond = true;
31+
//static const bool clientMITM = false;
32+
//static const bool clientPair = true;
33+
//static constexpr PasskeyRequestCallback userOnPassKeyRequest = customPasskeyRequest;
34+
/*
35+
###### BLE COMMUNICATION PARAMS ######
36+
*/
37+
//static const uint16_t commMinInterval = 6; // 7.5ms
38+
//static const uint16_t commMaxInterval = 35; // 40ms
39+
//static const uint16_t commLatency = 0; //
40+
//static const uint16_t commTimeOut = 200; // 2000ms
41+
/*
42+
###### BLE FORCE NEW CONNECTION ######
43+
*/
44+
//static const bool forceNewConnection = false;
45+
/*
46+
###### BLE SUBSCRIPTION: NOTIFICATION & RESPONSE ######
47+
*/
48+
//static const bool notification = true;
49+
//static const bool response = true;
50+
/*
51+
###### AND THE OTHER SETTINGS OF MIDI LIBRARY ######
52+
*/
53+
static const size_t MaxBufferSize = 16;
54+
55+
};
56+
57+
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
58+
//#include <hardware/BLEMIDI_ESP32.h>
59+
//#include <hardware/BLEMIDI_ArduinoBLE.h>
60+
61+
#ifndef LED_BUILTIN
62+
#define LED_BUILTIN 2
63+
#endif
64+
65+
BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-NimBLE-MIDI", MIDI, CustomBufferSizeSettings);
66+
67+
unsigned long t0 = millis();
68+
bool isConnected = false;
69+
70+
71+
// -----------------------------------------------------------------------------
72+
// When BLE connected, LED will turn on (indication that connection was successful)
73+
// When receiving a NoteOn, LED will go out, on NoteOff, light comes back on.
74+
// This is an easy and conveniant way to show that the connection is alive and working.
75+
// -----------------------------------------------------------------------------
76+
void setup()
77+
{
78+
Serial.begin(115200);
79+
while (!Serial) {}
80+
Serial.println("booting");
81+
82+
MIDI.begin();
83+
84+
pinMode(LED_BUILTIN, OUTPUT);
85+
digitalWrite(LED_BUILTIN, LOW);
86+
87+
BLEMIDI.setHandleConnected([]() {
88+
isConnected = true;
89+
digitalWrite(LED_BUILTIN, HIGH);
90+
});
91+
92+
BLEMIDI.setHandleDisconnected([]() {
93+
isConnected = false;
94+
digitalWrite(LED_BUILTIN, LOW);
95+
});
96+
97+
MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
98+
digitalWrite(LED_BUILTIN, LOW);
99+
});
100+
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
101+
digitalWrite(LED_BUILTIN, HIGH);
102+
});
103+
}
104+
105+
// -----------------------------------------------------------------------------
106+
//
107+
// -----------------------------------------------------------------------------
108+
void loop()
109+
{
110+
MIDI.read();
111+
112+
if (isConnected && (millis() - t0) > 1000)
113+
{
114+
t0 = millis();
115+
116+
MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 100 on channel 1
117+
}
118+
}

examples/MidiBle/MidiBle.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
//#include <hardware/BLEMIDI_ESP32_NimBLE.h>
44
#include <hardware/BLEMIDI_ESP32.h>
5-
//#include <hardware/BLEMIDI_nRF52.h>
65
//#include <hardware/BLEMIDI_ArduinoBLE.h>
76

7+
#ifndef LED_BUILTIN
8+
#define LED_BUILTIN 2
9+
#endif
10+
811
BLEMIDI_CREATE_DEFAULT_INSTANCE()
912

1013
unsigned long t0 = millis();

examples/MidiBle_Client/MidiBle_Client.ino

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* the name of the server or the BLE address of the server. If you want to connect
1515
* to the first MIDI server BLE found by the device, you just have to set the name field empty ("").
1616
*
17-
* FOR ADVANCED USERS: Other advanced BLE configurations can be changed in hardware/BLEMIDI_Client_ESP32.h
18-
* #defines in the head of the file (IMPORTANT: Only the first user defines must be modified). These configurations
19-
* are related to security (password, pairing and securityCallback()), communication params, the device name
20-
* and other stuffs. Modify defines at your own risk.
17+
* FOR ADVANCED USERS: Other advanced BLE configurations can be changed with a struct that heritate
18+
* from BLEMIDI_NAMESPACE::DefaultSettingsClient. These configurations are related to
19+
* security (password, pairing and securityCallback()), communication params, the device name
20+
* and other stuffs. Modify those settings at your own risk.
2121
*
2222
*
2323
*
@@ -29,17 +29,25 @@
2929
#include <BLEMIDI_Transport.h>
3030

3131
#include <hardware/BLEMIDI_Client_ESP32.h>
32-
3332
//#include <hardware/BLEMIDI_ESP32_NimBLE.h>
3433
//#include <hardware/BLEMIDI_ESP32.h>
35-
//#include <hardware/BLEMIDI_nRF52.h>
3634
//#include <hardware/BLEMIDI_ArduinoBLE.h>
3735

38-
BLEMIDI_CREATE_DEFAULT_INSTANCE(); //Connect to first server found
36+
#ifndef LED_BUILTIN
37+
#define LED_BUILTIN 2
38+
#endif
39+
40+
//See DefaultSettingsClient in hardware/BLEMIDI_Client_ESP32.h for more configurable settings
41+
// If you do not redefine a parameter, it will use the default value for these parameter
42+
struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettingsClient {
43+
static const size_t MaxBufferSize = 16;
44+
};
45+
46+
BLEMIDI_CREATE_CUSTOM_INSTANCE("Esp32-BLE-MIDI", MIDI, CustomBufferSizeSettings); // Connect to a server named "Esp32-BLE-MIDI" and use CustomBufferSizeSettings as settings of client
3947

40-
//BLEMIDI_CREATE_INSTANCE("",MIDI) //Connect to the first server found
41-
//BLEMIDI_CREATE_INSTANCE("f2:c1:d9:36:e7:6b",MIDI) //Connect to a specific BLE address server
42-
//BLEMIDI_CREATE_INSTANCE("MyBLEserver",MIDI) //Connect to a specific name server
48+
//BLEMIDI_CREATE_INSTANCE("",MIDI) //Connect to the first server found, using default settings
49+
//BLEMIDI_CREATE_INSTANCE("f2:c1:d9:36:e7:6b",MIDI) //Connect to a specific BLE address server, using default settings
50+
//BLEMIDI_CREATE_INSTANCE("MyBLEserver",MIDI) //Connect to a specific name server, using default settings
4351

4452
#ifndef LED_BUILTIN
4553
#define LED_BUILTIN 2 //modify for match with yout board

examples/SysEx_Receive/SysEx_Receive.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
//#include <hardware/BLEMIDI_ESP32_NimBLE.h>
44
#include <hardware/BLEMIDI_ESP32.h>
5-
//#include <hardware/BLEMIDI_nRF52.h>
65
//#include <hardware/BLEMIDI_ArduinoBLE.h>
76

7+
#ifndef LED_BUILTIN
8+
#define LED_BUILTIN 2
9+
#endif
10+
811
BLEMIDI_CREATE_INSTANCE("CustomName", MIDI)
912

1013
bool isConnected = false;

examples/SysEx_Send/SysEx_Send.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
44
//#include <hardware/BLEMIDI_ESP32.h>
5-
//#include <hardware/BLEMIDI_nRF52.h>
65
//#include <hardware/BLEMIDI_ArduinoBLE.h>
76

7+
#ifndef LED_BUILTIN
8+
#define LED_BUILTIN 2
9+
#endif
10+
811
byte sysex4[] = { 0xF0, 0x43, 0x20, 0xF7 };
912
byte sysex5[] = { 0xF0, 0x43, 0x20, 0x7E, 0xF7 };
1013
byte sysex6[] = { 0xF0, 0x43, 0x20, 0x7E, 0x4C, 0xF7 };

src/BLEMIDI_Settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN_BLEMIDI_NAMESPACE
66

77
struct DefaultSettings
88
{
9-
static const size_t MaxBufferSize = 64;
9+
static const short MaxBufferSize = 64;
1010
};
1111

1212
END_BLEMIDI_NAMESPACE

src/BLEMIDI_Transport.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ static const char *const CHARACTERISTIC_UUID = "7772e5db-3868-4112-a1a9-f2669d10
2626
template <class T, class _Settings = DefaultSettings>
2727
class BLEMIDI_Transport
2828
{
29-
typedef _Settings Settings;
30-
3129
private:
32-
byte mRxBuffer[Settings::MaxBufferSize];
30+
byte mRxBuffer[_Settings::MaxBufferSize];
3331
unsigned mRxIndex = 0;
3432

35-
byte mTxBuffer[Settings::MaxBufferSize]; // minimum 5 bytes
33+
byte mTxBuffer[_Settings::MaxBufferSize]; // minimum 5 bytes
3634
unsigned mTxIndex = 0;
3735

3836
char mDeviceName[24];
@@ -187,6 +185,7 @@ class BLEMIDI_Transport
187185
void (*_connectedCallback)() = nullptr;
188186
void (*_connectedCallbackDeviceName)(char *) = nullptr;
189187
void (*_disconnectedCallback)() = nullptr;
188+
void (*_connectedCallbackDeviceName)(char *) = nullptr;
190189

191190
BLEMIDI_Transport &setName(const char *deviceName)
192191
{
@@ -207,6 +206,12 @@ class BLEMIDI_Transport
207206
return *this;
208207
}
209208

209+
BLEMIDI_Transport &setHandleConnected(void (*fptr)(char*))
210+
{
211+
_connectedCallbackDeviceName= fptr;
212+
return *this;
213+
}
214+
210215
BLEMIDI_Transport &setHandleDisconnected(void (*fptr)())
211216
{
212217
_disconnectedCallback = fptr;
@@ -265,10 +270,10 @@ class BLEMIDI_Transport
265270
byte headerByte = buffer[lPtr++];
266271

267272
auto timestampHigh = 0x3f & headerByte;
268-
273+
timestampHigh = timestampHigh; // <-- This line is for avoid Warning message due it is unused
269274
byte timestampByte = buffer[lPtr++];
270275
uint16_t timestamp = 0;
271-
276+
timestamp = timestamp; // <-- This line is for avoid Warning message due it is unused
272277
bool sysExContinuation = false;
273278
bool runningStatusContinuation = false;
274279

0 commit comments

Comments
 (0)