Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_Example by
Diff: main.cpp
- Revision:
- 26:b3e90d7672f8
- Parent:
- 25:56d5b129dfd6
- Child:
- 27:ed42554cf870
--- a/main.cpp	Tue Jun 06 00:48:09 2017 +0000
+++ b/main.cpp	Sat Jun 10 00:51:10 2017 +0000
@@ -6,17 +6,8 @@
 uint16_t readCharUUID       = 0xA001;
 uint16_t writeCharUUID      = 0xA002;
 
-#define LEN_SEQUENCE 5
-#define NUM_CASES 6
-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
-static const uint16_t uuid16_list[]        = {0xFFFF}; //Custom UUID, FFFF is reserved for development
+static const uint16_t uuid16_list[]        = {0xA000}; //Custom UUID, FFFF is reserved for development
 
 /* Set Up custom Characteristics */
 static uint8_t readValue[10] = {0};
@@ -29,46 +20,21 @@
 GattCharacteristic *characteristics[] = {&readChar, &writeChar};
 GattService        customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
 
-
-/*
- *  Restart advertising when phone app disconnects
-*/
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *)
 {
     BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
 }
 
-/*
- *  Handle writes to writeCharacteristic
-*/
 void writeCharCallback(const GattWriteCallbackParams *params)
 {
     /* 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
-//        }
-//        /* 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];
-                    wait(0.5);
-                }
-            }
+        if(params->len == 1) {
+            led = 1;
+            wait(0.5);
+            led = 0;
         }
-        
         /* Update the readChar with the value of writeChar */
         BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), params->data, params->len);
     }
    