bug fix

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_MIDI by Kaoru Shoji

Revision:
2:dbc6f81b9ba0
Parent:
1:cba2eba64f5c
Child:
4:53fa90f45a8e
--- a/BLEMIDI.cpp	Fri Apr 03 04:24:01 2015 +0000
+++ b/BLEMIDI.cpp	Mon Apr 06 09:10:07 2015 +0000
@@ -29,7 +29,6 @@
 }
 
 void BLEMIDI::dataWrittenCallback(const GattCharacteristicWriteCBParams *params) {
-    // read characteristic and write serial
     uint16_t length;
     uint8_t rxBuffer[20];
 
@@ -248,12 +247,16 @@
                     // last written uint8_t is for timestamp
                     if (sysExBufferPos > 0) {
                         sysExBuffer[sysExBufferPos - 1] = midiEvent;
-                        onSystemExclusive(sysExBuffer, sysExBufferPos);
+                        onSystemExclusive(sysExBuffer, sysExBufferPos, false);
                     }
 
                     sysExBufferPos = 0;
                     midiState = MIDI_STATE_TIMESTAMP;
                 } else {
+                    if (sysExBufferPos == 128) {
+                        onSystemExclusive(sysExBuffer, sysExBufferPos, true);
+                        sysExBufferPos = 0;
+                    }
                     sysExBuffer[sysExBufferPos++] = midiEvent;
                 }
             }
@@ -262,6 +265,10 @@
 }
 
 BLEMIDI::BLEMIDI(BLEDevice *dev) {
+    BLEMIDI(dev, "MIDI");
+}
+
+BLEMIDI::BLEMIDI(BLEDevice *dev, char *deviceName) {
     device = dev;
     isConnected = false;
     sysExBufferPos = 0;
@@ -271,10 +278,6 @@
     midiEventNote = 0;
     midiEventVelocity = 0;
 
-    // Advertise packet length is 31 bytes.
-    // device name is upto 4 bytes if the service UUID included
-    const char DEVICE_NAME[] = "MIDI";
-
     // MIDI characteristic
     LongUUIDBytes_t characteristicUuid = {
         0x77, 0x72, 0xe5, 0xdb, 0x38, 0x68, 0x41, 0x12, 
@@ -307,7 +310,7 @@
     /* setup advertising */
     device->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (uint8_t*)uuid128_list, sizeof(uuid128_list));
     device->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
-    device->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    device->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)deviceName, sizeof(deviceName));
 
     device->setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     device->setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */