Example for Bluetooth low energy interface
Dependencies: mbed HC_SR04_Ultrasonic_Library
Revision 3:829f081fde15, committed 2015-05-19
- Comitter:
- julientiron
- Date:
- Tue May 19 20:42:25 2015 +0000
- Parent:
- 2:b5166e24c7a6
- Commit message:
- hihi;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 19 17:46:51 2015 +0000
+++ b/main.cpp Tue May 19 20:42:25 2015 +0000
@@ -19,10 +19,9 @@
#define MAX_SERVICES_NOS 1
-static uint8_t proximity = 0;
-static uint8_t mm[2] = {0x00, proximity};
-static uint8_t rate = 1;
-static uint8_t upd[2] = {0x00, rate};
+
+static uint8_t mm[2] = {0x00, 0x00};
+static uint8_t upd[2] = {0x00, 0x00};
GattCharacteristic proxLevel(GattCharacteristic::UUID_ALERT_LEVEL_CHAR, mm, sizeof(mm), sizeof(mm),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY|GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ
@@ -40,12 +39,12 @@
void dist(int distance)
{
-
- if (dev.getGapState().connected) {
- mm[1] = distance;
- dev.updateCharacteristicValue(proxLevel.getHandle(), mm, sizeof(mm));
- }
- printf("Distance changed to %dmm\r\n", distance);
+ //if (dev.getGapState().connected) {
+ mm[0] = distance & 0xff;
+ mm[1] = (distance >> 8);
+ dev.updateCharacteristicValue(proxLevel.getHandle(), mm, sizeof(mm));
+ //}
+ DEBUG("%d%d Distance changed to %dmm\r\n", mm[1], mm[0], distance);
}
void ISR_pressed() // ISR for the button press
@@ -92,9 +91,8 @@
/**
* Triggered periodically by the 'ticker' interrupt; updates hrmCounter.
*/
-void periodicCallback(void)
+void periodicCallback()
{
- //myled = !myled; /* Do blinky on LED1 while we're waiting for BLE events */
}
int main() {
@@ -127,7 +125,7 @@
DEBUG("Starting Advertising...\n\r");
dev.startAdvertising();
dev.addService(proxService);
- ultrasonic mu(D8, D9, .5, 1, &dist);
+ ultrasonic mu(D8, D9, .1, 1, &dist);
mu.startUpdates();
while(1) {
@@ -145,7 +143,6 @@
mu.checkDistance();
myled = 1;
wait(1);
- //DEBUG("tic!\n\r");
periodicCallback();//Works from here!!
dev.waitForEvent();
}
Robotique FIP