ECE119 BLE Project Exploration
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
Fork of Hexi_BLE_Example by
Revision 5:8b1ff723682d, committed 2018-08-09
- Comitter:
- xihan94
- Date:
- Thu Aug 09 22:45:09 2018 +0000
- Parent:
- 4:20d4eebfa986
- Child:
- 6:c20139d0e707
- Commit message:
- dev
Changed in this revision
| Hexi_KW40Z.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Hexi_KW40Z.lib Fri May 04 08:56:11 2018 +0000 +++ b/Hexi_KW40Z.lib Thu Aug 09 22:45:09 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#3f5ed7abc5c7 +http://mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#84ead63f7353
--- 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);
}
