2
2
3
3
// I N D E V E L O P M E N T
4
4
5
- // #include <bluefruit.h>
5
+ #include < bluefruit.h>
6
6
7
7
BEGIN_BLEMIDI_NAMESPACE
8
8
9
9
template <class _Settings >
10
10
class BLEMIDI_nRF52
11
11
{
12
12
private:
13
- // BLEDis bledis;
14
- // BLEMidi blemidi;
13
+ BLEDis bledis;
14
+ // BLEMidi blemidi;
15
15
16
16
BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52 <_Settings>, _Settings>* _bleMidiTransport;
17
17
18
- template <class > friend class MyServerCallbacks ;
19
- template <class > friend class MyCharacteristicCallbacks ;
18
+ // template <class> friend class MyServerCallbacks;
19
+ // template <class> friend class MyCharacteristicCallbacks;
20
20
21
21
public:
22
22
BLEMIDI_nRF52 ()
@@ -62,6 +62,23 @@ class BLEMIDI_nRF52
62
62
}
63
63
};
64
64
65
+ void connect_callback (uint16_t conn_handle)
66
+ {
67
+ Serial.println (" Connected" );
68
+
69
+ // Get the reference to current connection
70
+ BLEConnection* connection = Bluefruit.Connection (conn_handle);
71
+ }
72
+
73
+ void disconnect_callback (uint16_t conn_handle, uint8_t reason)
74
+ {
75
+ (void ) conn_handle;
76
+ (void ) reason;
77
+
78
+ Serial.println ();
79
+ Serial.print (" Disconnected, reason = 0x" ); Serial.println (reason, HEX);
80
+ }
81
+
65
82
template <class _Settings >
66
83
bool BLEMIDI_nRF52<_Settings>::begin(const char * deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52 <_Settings>, _Settings>* bleMidiTransport)
67
84
{
@@ -70,34 +87,39 @@ bool BLEMIDI_nRF52<_Settings>::begin(const char* deviceName, BLEMIDI_NAMESPACE::
70
87
// Config the peripheral connection with maximum bandwidth
71
88
// more SRAM required by SoftDevice
72
89
// Note: All config***() function must be called before begin()
73
- // Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
90
+ Bluefruit.configPrphBandwidth (BANDWIDTH_MAX);
74
91
75
- // Bluefruit.begin();
76
- // Bluefruit.setName(deviceName);
77
- // Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
92
+ Bluefruit.begin ();
93
+ Bluefruit.setName (deviceName);
94
+ Bluefruit.setTxPower (4 ); // Check bluefruit.h for supported values
78
95
79
96
// Setup the on board blue LED to be enabled on CONNECT
80
- // Bluefruit.autoConnLed(true);
97
+ Bluefruit.autoConnLed (true );
98
+
99
+ Bluefruit.Periph .setConnectCallback (connect_callback);
100
+ Bluefruit.Periph .setDisconnectCallback (disconnect_callback);
81
101
82
102
// Configure and Start Device Information Service
83
- // bledis.setManufacturer("Adafruit Industries");
84
- // bledis.setModel("Bluefruit Feather52");
85
- // bledis.begin();
103
+ bledis.setManufacturer (" Adafruit Industries" );
104
+ bledis.setModel (" Bluefruit Feather52" );
105
+ bledis.begin ();
86
106
87
107
// Start advertising ----------------------------
88
108
89
109
// Set General Discoverable Mode flag
90
- // Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
110
+ Bluefruit.Advertising .addFlags (BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
91
111
92
112
// Advertise TX Power
93
- // Bluefruit.Advertising.addTxPower();
113
+ Bluefruit.Advertising .addTxPower ();
94
114
95
115
// Advertise BLE MIDI Service
96
- // Bluefruit.Advertising.addService(blemidi);
116
+ Bluefruit.Advertising .addService (blemidi);
117
+
118
+ // blemidi.write((uint8_t)0);
97
119
98
120
// Secondary Scan Response packet (optional)
99
121
// Since there is no room for 'Name' in Advertising packet
100
- // Bluefruit.ScanResponse.addName();
122
+ Bluefruit.ScanResponse .addName ();
101
123
102
124
/* Start Advertising
103
125
* - Enable auto advertising if disconnected
@@ -108,10 +130,10 @@ bool BLEMIDI_nRF52<_Settings>::begin(const char* deviceName, BLEMIDI_NAMESPACE::
108
130
* For recommended advertising interval
109
131
* https://developer.apple.com/library/content/qa/qa1931/_index.html
110
132
*/
111
- // Bluefruit.Advertising.restartOnDisconnect(true);
112
- // Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
113
- // Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
114
- // Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
133
+ Bluefruit.Advertising .restartOnDisconnect (true );
134
+ Bluefruit.Advertising .setInterval (32 , 244 ); // in unit of 0.625 ms
135
+ Bluefruit.Advertising .setFastTimeout (30 ); // number of seconds in fast mode
136
+ Bluefruit.Advertising .start (0 ); // 0 = Don't stop advertising after n seconds
115
137
116
138
return true ;
117
139
}
0 commit comments