For MAX32630FTHR Demo Board: Controls LEDs on the demo board interfaced through BLE peripheral testing apps like LightBlue for iOS. Debug output on serial port.

Dependencies:   max32630fthr

Revision:
20:efe8deed8f74
Parent:
0:c671a4833315
--- a/main.cpp	Wed Jun 20 12:00:27 2018 +0100
+++ b/main.cpp	Sat Nov 09 01:44:19 2019 +0000
@@ -28,6 +28,24 @@
 #include "ble/GattServer.h"
 #include "BLEProcess.h"
 
+#include "mbed.h"
+#include "max32630fthr.h"
+
+MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+
+PwmOut PWM(P4_0);
+AnalogIn POT(AIN_0);
+DigitalOut rLED(LED1);
+DigitalOut gLED(LED2);
+DigitalOut bLED(LED3);
+DigitalIn Button(P2_3);
+
+DigitalOut dbled1(P5_6);
+DigitalOut dbled2(P5_5);
+DigitalOut dbled3(P5_4);
+DigitalOut dbled4(P5_3);
+
+
 using mbed::callback;
 
 /**
@@ -100,11 +118,6 @@
         _server->onConfirmationReceived(as_cb(&Self::when_confirmation_received));
 
         // print the handles
-        printf("clock service registered\r\n");
-        printf("service handle: %u\r\n", _clock_service.getHandle());
-        printf("\thour characteristic value handle %u\r\n", _hour_char.getValueHandle());
-        printf("\tminute characteristic value handle %u\r\n", _minute_char.getValueHandle());
-        printf("\tsecond characteristic value handle %u\r\n", _second_char.getValueHandle());
 
         _event_queue->call_every(1000 /* ms */, callback(this, &Self::increment_second));
     }
@@ -124,25 +137,26 @@
      */
     void when_data_written(const GattWriteCallbackParams *e)
     {
-        printf("data written:\r\n");
-        printf("\tconnection handle: %u\r\n", e->connHandle);
-        printf("\tattribute handle: %u", e->handle);
-        if (e->handle == _hour_char.getValueHandle()) {
-            printf(" (hour characteristic)\r\n");
-        } else if (e->handle == _minute_char.getValueHandle()) {
-            printf(" (minute characteristic)\r\n");
-        } else if (e->handle == _second_char.getValueHandle()) {
-            printf(" (second characteristic)\r\n");
-        } else {
-            printf("\r\n");
-        }
-        printf("\twrite operation: %u\r\n", e->writeOp);
-        printf("\toffset: %u\r\n", e->offset);
-        printf("\tlength: %u\r\n", e->len);
-        printf("\t data: ");
+        printf("data written from phone.\r\n");
 
         for (size_t i = 0; i < e->len; ++i) {
-            printf("%02X", e->data[i]);
+            printf("%02X:", e->data[i]);
+        }
+        
+        switch(e->data[0])
+        {
+            case 1:
+                dbled1 = !dbled1;
+                break;
+            case 2:
+                dbled2 = !dbled2;
+                break;
+            case 3:
+                dbled3 = !dbled3;
+                break;
+            case 4:
+                dbled4 = !dbled4;
+                break;
         }
 
         printf("\r\n");
@@ -153,18 +167,7 @@
      */
     void when_data_read(const GattReadCallbackParams *e)
     {
-        printf("data read:\r\n");
-        printf("\tconnection handle: %u\r\n", e->connHandle);
-        printf("\tattribute handle: %u", e->handle);
-        if (e->handle == _hour_char.getValueHandle()) {
-            printf(" (hour characteristic)\r\n");
-        } else if (e->handle == _minute_char.getValueHandle()) {
-            printf(" (minute characteristic)\r\n");
-        } else if (e->handle == _second_char.getValueHandle()) {
-            printf(" (second characteristic)\r\n");
-        } else {
-            printf("\r\n");
-        }
+        printf("Data was read.\r\n");
     }
 
     /**
@@ -393,6 +396,8 @@
 };
 
 int main() {
+    printf("\f---MAX32630FTHR BLE DEMO---\r\n");
+    
     BLE &ble_interface = BLE::Instance();
     events::EventQueue event_queue;
     ClockService demo_service;