for camera

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_GATT_Example by Bluetooth Low Energy

Revision:
24:64e7d23021ba
Parent:
23:8cd0bcd06533
Child:
25:56d5b129dfd6
--- a/main.cpp	Tue Jun 06 00:15:32 2017 +0000
+++ b/main.cpp	Tue Jun 06 00:44:39 2017 +0000
@@ -6,10 +6,13 @@
 uint16_t readCharUUID       = 0xA001;
 uint16_t writeCharUUID      = 0xA002;
 
-const uint8_t lookUpTable[6][5] = { {1,0,0,0,1},
+#define LEN_SEQUENCE 5
+#define NUM_CASES
+const uint8_t lookUpTable[NUM_CASES][LEN_SEQUENCE] = { {1,0,0,0,1},
                                     {1,0,0,1,1},
                                     {1,1,0,0,1},
                                     {1,0,1,0,1},
+                                    {1,1,0,1,1},
                                     {1,1,0,1,1}};
 
 const static char     DEVICE_NAME[]        = "timesync1"; // change this
@@ -43,18 +46,29 @@
     /* Check to see what characteristic was written, by handle */
     if(params->handle == writeChar.getValueHandle()) {
         /* toggle LED if only 1 byte is written */
-        if(params->len == 1) {
-            led = params->data[0];
-            (params->data[0] == 0x00) ? printf("led on\n\r") : printf("led off\n\r"); // print led toggle
+//        if(params->len == 1) {
+//            led = params->data[0];
+//            (params->data[0] == 0x00) ? printf("led on\n\r") : printf("led off\n\r"); // print led toggle
+//        }
+//        /* Print the data if more than 1 byte is written */
+//        else {
+//            printf("Data received: length = %d, data = 0x",params->len);
+//            for(int x=0; x < params->len; x++) {
+//                printf("%x", params->data[x]);
+//            }
+//            printf("\n\r");
+//        }
+        // lookup table
+        if (params->len == 1) {
+            int instruction = params->data[0];
+            if ((instruction >= 0) && (instruction < NUM_CASES)) {
+                for (int i = 0; i < LEN_SEQUENCE; i++) {
+                    led = lookUpTable[instruction][i];
+                    delay(500);
+                }
+            }
         }
-        /* Print the data if more than 1 byte is written */
-        else {
-            printf("Data received: length = %d, data = 0x",params->len);
-            for(int x=0; x < params->len; x++) {
-                printf("%x", params->data[x]);
-            }
-            printf("\n\r");
-        }
+        
         /* Update the readChar with the value of writeChar */
         BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), params->data, params->len);
     }