Sarah Marsh / Mbed OS mbed-os-example-ble-voice

Fork of mbed-os-example-ble-LED by mbed-os-examples

Revision:
23:46aad4b5185f
Parent:
11:7404978b24e7
Child:
24:0770ad9edb2d
diff -r 6ce5103bf480 -r 46aad4b5185f source/main.cpp
--- a/source/main.cpp	Tue Mar 14 15:45:45 2017 +0000
+++ b/source/main.cpp	Mon Apr 03 14:47:34 2017 +0000
@@ -17,19 +17,21 @@
 #include <events/mbed_events.h>
 #include <mbed.h>
 #include "ble/BLE.h"
-#include "LEDService.h"
+#include "UARTService.h"
 
 DigitalOut alivenessLED(LED1, 0);
 DigitalOut actuatedLED(LED2, 0);
 
-const static char     DEVICE_NAME[] = "LED";
-static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID};
+DigitalOut light(D2);
+
+const static char     DEVICE_NAME[] = "mbedVoiceUART";
+static const uint16_t uuid16_list[] = {UARTServiceShortUUID};
 
 static EventQueue eventQueue(
     /* event count */ 10 * /* event size */ 32
 );
 
-LEDService *ledServicePtr;
+UARTService *UARTServicePtr;
 
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
 {
@@ -42,6 +44,16 @@
     alivenessLED = !alivenessLED; /* Do blinky on LED1 to indicate system aliveness. */
 }
 
+void check_command(char* cmd){
+    if(strstr(cmd, "panic")){
+        light = 1;
+    }
+    else if(strstr(cmd, "chill")){
+        light = 0;
+    }
+    
+}
+
 /**
  * This callback allows the LEDService to receive updates to the ledState Characteristic.
  *
@@ -49,9 +61,15 @@
  *     Information about the characterisitc being updated.
  */
 void onDataWrittenCallback(const GattWriteCallbackParams *params) {
-    if ((params->handle == ledServicePtr->getValueHandle()) && (params->len == 1)) {
-        actuatedLED = *(params->data);
+    char  rcv[UARTServicePtr->BLE_UART_SERVICE_MAX_DATA_LEN];
+    int c = UARTServicePtr->_getc();
+    int i = 0;
+    while (c != EOF){
+        rcv[i++] = (char)c;
+        c = UARTServicePtr->_getc();     
     }
+    printf("%s\r\n", rcv);
+    check_command(rcv);
 }
 
 /**
@@ -84,15 +102,14 @@
     ble.gap().onDisconnection(disconnectionCallback);
     ble.gattServer().onDataWritten(onDataWrittenCallback);
 
-    bool initialValueForLEDCharacteristic = false;
-    ledServicePtr = new LEDService(ble, initialValueForLEDCharacteristic);
+    UARTServicePtr = new UARTService(ble);
 
     /* setup advertising */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.gap().setAdvertisingInterval(1000); /* 1000ms. */
+    ble.gap().setAdvertisingInterval(160); /* 1000ms. */
     ble.gap().startAdvertising();
 }
 
@@ -103,6 +120,7 @@
 
 int main()
 {
+    light = 0; 
     eventQueue.call_every(500, blinkCallback);
 
     BLE &ble = BLE::Instance();