ECE119 BLE Project Exploration
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
Fork of Hexi_BLE_Example by
Revision 4:20d4eebfa986, committed 2018-05-04
- Comitter:
- xihan94
- Date:
- Fri May 04 08:56:11 2018 +0000
- Parent:
- 3:c2ab3a0de448
- Child:
- 5:8b1ff723682d
- Commit message:
- Test program for ECE BLE project;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Sep 26 05:29:51 2016 +0000
+++ b/main.cpp Fri May 04 08:56:11 2018 +0000
@@ -13,6 +13,8 @@
void StopHaptic(void const *n);
void txTask(void);
+Serial pc(USBTX, USBRX);
+
DigitalOut redLed(LED1,1);
DigitalOut greenLed(LED2,1);
DigitalOut blueLed(LED3,1);
@@ -66,6 +68,30 @@
oled.TextBox((uint8_t *)text,0,40,95,18);
}
+// 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)
+{
+ StartHaptic();
+ data[19] = 0;
+ pc.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);
+
+ // 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);
+ }
+}
/***********************End of Call Back Functions*****************************/
/********************************Main******************************************/
@@ -76,7 +102,10 @@
kw40z_device.attach_buttonLeft(&ButtonLeft);
kw40z_device.attach_buttonRight(&ButtonRight);
kw40z_device.attach_passkey(&PassKey);
+ kw40z_device.attach_alert(&AlertReceived);
+ pc.printf("hello\n\r");
+
/* Turn on the backlight of the OLED Display */
oled.DimScreenON();
@@ -111,7 +140,7 @@
while (true)
{
- blueLed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/
+ // blueLed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/
Thread::wait(50);
}
}
