EEP fORK

Dependencies:   BLE_API mbed nRF51822

Fork of MCS_LRF by Farshad N

Revision:
1:e18634cb382a
Parent:
0:d58d1cdf43a9
Child:
2:79a9dad8bc5e
--- a/main.cpp	Fri Aug 07 00:36:11 2015 +0000
+++ b/main.cpp	Fri Aug 07 00:45:04 2015 +0000
@@ -52,33 +52,36 @@
 }
 
 /* set io pins based on the data color, r=red, y=yellow, o=off */
-static void processData(uint8_t data)
+static void processData(const GattWriteCallbackParams *params)
 {
-    DEBUG("data: %d   ", data);
-    switch(data) {
-        case 'r':
-            pin0 = 0;
-            pin1 = 0;
-            DEBUG("r \r\n");
-            break;
+    DEBUG("data: %d   ", *(params->data));
+    
+    if(params->len == 1) {
+        switch(*(params->data)) {
+            case 'r':
+                pin0 = 0;
+                pin1 = 0;
+                DEBUG("r \r\n");
+                break;
 
-        case 'y':
-            pin0 = 1;
-            pin1 = 0;
-            DEBUG("y \r\n");
-            break;
+            case 'y':
+                pin0 = 1;
+                pin1 = 0;
+                DEBUG("y \r\n");
+                break;
 
-        case 'o':
-            pin0 = 1;
-            pin1 = 1;
-            DEBUG("o \r\n");
-            break;
+            case 'o':
+                pin0 = 1;
+                pin1 = 1;
+                DEBUG("o \r\n");
+                break;
 
-        default:
-            DEBUG("default \r\n");
-            pin0 = 0;
-            pin1 = 1;
-            break;
+            default:
+                DEBUG("default \r\n");
+                pin0 = 0;
+                pin1 = 1;
+                break;
+        }
     }
 }
 
@@ -93,8 +96,8 @@
         DEBUG("\n\r", bytesRead);
 
         ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
-        if(params->len == 1)
-            processData(*(params->data));
+
+        processData(params);
     }
 }
 
@@ -122,7 +125,7 @@
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,(const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
-                                        (uint8_t *)GattService::UUID_DEVICE_INFORMATION_SERVICE, sizeof(GattService::UUID_DEVICE_INFORMATION_SERVICE));
+                                     (uint8_t *)GattService::UUID_DEVICE_INFORMATION_SERVICE, sizeof(GattService::UUID_DEVICE_INFORMATION_SERVICE));
     ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
     ble.startAdvertising();