22
33// I N D E V E L O P M E N T
44
5- // #include <bluefruit.h>
5+ #include < bluefruit.h>
66
77BEGIN_BLEMIDI_NAMESPACE
88
99template <class _Settings >
1010class BLEMIDI_nRF52
1111{
1212private:
13- // BLEDis bledis;
14- // BLEMidi blemidi;
13+ BLEDis bledis;
14+ // BLEMidi blemidi;
1515
1616 BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52 <_Settings>, _Settings>* _bleMidiTransport;
1717
18- template <class > friend class MyServerCallbacks ;
19- template <class > friend class MyCharacteristicCallbacks ;
18+ // template <class> friend class MyServerCallbacks;
19+ // template <class> friend class MyCharacteristicCallbacks;
2020
2121public:
2222 BLEMIDI_nRF52 ()
@@ -62,6 +62,23 @@ class BLEMIDI_nRF52
6262 }
6363};
6464
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+
6582template <class _Settings >
6683bool BLEMIDI_nRF52<_Settings>::begin(const char * deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52 <_Settings>, _Settings>* bleMidiTransport)
6784{
@@ -70,34 +87,39 @@ bool BLEMIDI_nRF52<_Settings>::begin(const char* deviceName, BLEMIDI_NAMESPACE::
7087 // Config the peripheral connection with maximum bandwidth
7188 // more SRAM required by SoftDevice
7289 // Note: All config***() function must be called before begin()
73- // Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
90+ Bluefruit.configPrphBandwidth (BANDWIDTH_MAX);
7491
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
7895
7996 // 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);
81101
82102 // 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 ();
86106
87107 // Start advertising ----------------------------
88108
89109 // 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);
91111
92112 // Advertise TX Power
93- // Bluefruit.Advertising.addTxPower();
113+ Bluefruit.Advertising .addTxPower ();
94114
95115 // Advertise BLE MIDI Service
96- // Bluefruit.Advertising.addService(blemidi);
116+ Bluefruit.Advertising .addService (blemidi);
117+
118+ // blemidi.write((uint8_t)0);
97119
98120 // Secondary Scan Response packet (optional)
99121 // Since there is no room for 'Name' in Advertising packet
100- // Bluefruit.ScanResponse.addName();
122+ Bluefruit.ScanResponse .addName ();
101123
102124 /* Start Advertising
103125 * - Enable auto advertising if disconnected
@@ -108,10 +130,10 @@ bool BLEMIDI_nRF52<_Settings>::begin(const char* deviceName, BLEMIDI_NAMESPACE::
108130 * For recommended advertising interval
109131 * https://developer.apple.com/library/content/qa/qa1931/_index.html
110132 */
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
115137
116138 return true ;
117139}
0 commit comments