ECE119 BLE Project Exploration

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351

Fork of Hexi_BLE_Example by Hexiwear

Revision:
5:8b1ff723682d
Parent:
4:20d4eebfa986
diff -r 20d4eebfa986 -r 8b1ff723682d main.cpp
--- a/main.cpp	Fri May 04 08:56:11 2018 +0000
+++ b/main.cpp	Thu Aug 09 22:45:09 2018 +0000
@@ -13,7 +13,7 @@
 void StopHaptic(void const *n);
 void txTask(void);
 
-Serial pc(USBTX, USBRX);
+static Serial pc(USBTX, USBRX);
 
 DigitalOut redLed(LED1,1);
 DigitalOut greenLed(LED2,1);
@@ -47,12 +47,14 @@
 /****************************Call Back Functions*******************************/
 void ButtonRight(void)
 {
+    printf("Right\r\n");
     StartHaptic();
     kw40z_device.ToggleAdvertisementMode();
 }
 
 void ButtonLeft(void)
 {
+    printf("Left\r\n");
     StartHaptic();
     kw40z_device.ToggleAdvertisementMode();
 }
@@ -70,27 +72,27 @@
 
 // Key modification: use the alert functionality enabled by the host-ble interface
 // to define our own command.
-void AlertReceived(uint8_t *data, uint8_t length)
+void MessageReceived(uint8_t *data, uint8_t length)
 {
     StartHaptic();
-    data[19] = 0;
-    pc.printf("%s\n\r", data);
+    data[length] = 0;
+    printf("%s\n\r", data);
     
     // data (our command) must 20 bytes long.
     // CMD for turning on: 'ledonledonledonledon'
-    if (data[4] == 'n') {
-        greenLed = LED_ON;
-        redLed = LED_ON;
-        blueLed = LED_ON;
-        pc.printf("on\n\r", data);
+    //if (data[4] == 'n') {
+//        greenLed = LED_ON;
+//        redLed = LED_ON;
+//        blueLed = LED_ON;
+//        pc.printf("on\n\r", data);
     
     // CMD for turning off: 'ledoffledoffledoffled'
-    } else if (data[4] == 'f') {
-        greenLed = LED_OFF;
-        redLed = LED_OFF;
-        blueLed = LED_OFF;
-        pc.printf("off\n\r", data);
-    }
+//    } else if (data[4] == 'f') {
+//        greenLed = LED_OFF;
+//        redLed = LED_OFF;
+//        blueLed = LED_OFF;
+//        pc.printf("off\n\r", data);
+//    }
 }
 /***********************End of Call Back Functions*****************************/
 
@@ -102,8 +104,9 @@
     kw40z_device.attach_buttonLeft(&ButtonLeft);
     kw40z_device.attach_buttonRight(&ButtonRight);
     kw40z_device.attach_passkey(&PassKey);
-    kw40z_device.attach_alert(&AlertReceived);
+    kw40z_device.attach_message(&MessageReceived);
 
+    pc.baud(115200);
     pc.printf("hello\n\r");
     
     /* Turn on the backlight of the OLED Display */
@@ -179,6 +182,9 @@
         kw40z_device.SendGyro(x,y,z);
         kw40z_device.SendAccel(z,x,y);
         kw40z_device.SendMag(y,z,x);
+        
+        uint8_t buf[6] = "Hello";
+        kw40z_device.SendMessage(buf, 5);
 
         Thread::wait(1000);                 
     }