test

Dependencies:   BLE_API mbed nRF51822

Fork of Connect_Test4 by Aura-Tech Solutions

Revision:
18:8454c63488ee
Parent:
17:dfe796bba97c
Child:
19:da48cacdb4c1
diff -r dfe796bba97c -r 8454c63488ee main.cpp
--- a/main.cpp	Thu Apr 02 20:27:35 2015 +0000
+++ b/main.cpp	Mon Nov 09 14:34:14 2015 +0000
@@ -6,9 +6,40 @@
 uint16_t customServiceUUID  = 0xA000;
 uint16_t readCharUUID       = 0xA001;
 uint16_t writeCharUUID      = 0xA002;
+uint16_t A16                = 0xA005;
 
-const static char     DEVICE_NAME[]        = "ChangeMe!!"; // change this
-static const uint16_t uuid16_list[]        = {0xFFFF}; //Custom UUID, FFFF is reserved for development
+
+
+
+uint8_t b1_id               = 0x01;
+uint8_t b2_id               = 0x02;
+uint8_t b3_id               = 0x03;
+uint8_t b4_id               = 0x04;
+uint8_t b5_id               = 0x05;
+uint8_t b6_id               = 0x06;
+uint8_t b7_id               = 0x07;
+
+PinName flood_p              = P0_4;
+
+PinName b1_p             = P0_28;
+PinName b2_p             = P0_29;
+PinName b3_p             = P0_15;
+PinName b4_p             = P0_10; //CTX
+PinName b5_p             = P0_9;  //TXD
+PinName b6_p             = P0_11; //RXD
+PinName b7_p             = P0_8;  //RTS
+
+
+/*
+PinName b4_p             = CTX; //CTX
+PinName b5_p             = TXD;  //TXD
+PinName b6_p             = D0; //RXD
+PinName b7_p             = D3;  //RTS
+*/
+
+
+const static char     DEVICE_NAME[]        = "PETE2"; // change this
+static const uint16_t uuid16_list[]        = {0xFF02}; //Custom UUID, FFFF is reserved for development
 
 // Set Up custom Characteristics
 static uint8_t readValue[10] = {0};
@@ -21,6 +52,20 @@
 GattCharacteristic *characteristics[] = {&readChar, &writeChar};
 GattService        customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
 
+//setup led
+DigitalOut led1(P0_19);
+
+
+DigitalOut b1(b1_p);
+DigitalOut b2(b2_p);
+DigitalOut b3(b3_p);
+DigitalOut b4(b4_p);
+DigitalOut b5(b5_p);
+DigitalOut b6(b6_p);
+DigitalOut b7(b7_p);
+
+
+DigitalIn enable(flood_p);
 
 /*
  *  Restart advertising when phone app disconnects
@@ -36,18 +81,54 @@
 void writeCharCallback(const GattCharacteristicWriteCBParams *params)
 {
     // check to see what characteristic was written, by handle
-    if(params->charHandle == writeChar.getValueHandle()) {
-        // toggle LED if only 1 byte is written
-        if(params->len == 1) {
-            led = params->data[0];
-            (params->data[0] == 0x00) ? printf("\n\rled on ") : printf("\n\rled off "); // print led toggle
+    if(params->charHandle == writeChar.getValueHandle()) 
+    {
+        // toggle LED if...
+        if(params->data[0] == b1_id)
+        {
+            b1 = !b1;
+            //led1 = 0;
+        }
+        else if(params->data[0] == b2_id)
+        {
+            b2 = !b2;
+            //led1 = 0;
+        }
+        else if(params->data[0] == b3_id)
+        {
+            b3 = !b3;
+            //led1 = 0;
+        }
+        if(params->data[0] == b4_id)
+        {
+            b4 = !b4;
+        }
+        else if(params->data[0] == b5_id)
+        {
+            b5 = !b5;
+            //led1 = 0;
+        }
+        else if(params->data[0] == b6_id)
+        {
+            b6 = !b6;
+            //led1 = 0;
+        }
+        else if(params->data[0] == b7_id)
+        {
+            b7 = !b7;
+            led1 = 0;
+            wait(3);
+            led1 = 1;
         }
         // print the data if more than 1 byte is written
-        else {
+        else 
+        {
+            
             printf("\n\r Data received: length = %d, data = 0x",params->len); 
             for(int x=0; x < params->len; x++) {
                 printf("%x",params->data[x]);
             }
+            
         }
         // update the readChar with the value of writeChar
         ble.updateCharacteristicValue(readChar.getValueHandle(),params->data,params->len);
@@ -62,8 +143,22 @@
 {
     /* initialize stuff */
     printf("\n\r********* Starting Main Loop *********\n\r");
+    led1 = 1;
+    
+    b1 = 1;//b1_p = P0_28;
+    b2 = 1;//b2_p = P0_29;
+    b3 = 1;//b3_p = P0_9;
+    b4 = 1;//b4_p = P0_10; //CTX
+    b5 = 1;//b5_p = P0_9;  //TXD
+    b6 = 1;//b6_p = P0_11; //RXD
+    b7 = 1;//b7_p = P0_8;  //RTS
+              
+    
+
+    
     ble.init();
     ble.onDisconnection(disconnectionCallback);
+    
     ble.onDataWritten(writeCharCallback);
 
     /* setup advertising */