ble

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

Revision:
4:69a35a56ac48
Parent:
3:829f081fde15
--- a/main.cpp	Tue May 19 20:42:25 2015 +0000
+++ b/main.cpp	Thu Jul 09 13:33:36 2015 +0000
@@ -1,40 +1,40 @@
 #include "mbed.h"
 #include "ultrasonic.h"
- 
-DigitalOut myled(LED1);
- 
+#include "Servo.h"
 #include "debug.h"
 #include "btle.h"
 //#include "BlueNRGDevice.h"//User does not use any platform specific header file
 #include "BLEDevice.h"
 #include "UUID.h"
 #include "Utils.h"
- 
+
 BLEDevice dev;
- 
+DigitalOut myled(LED1);
+Servo servo1(D15);
+
 const static char  DEVICE_NAME[] = "FearInProgress";
 const uint8_t device_address[6] = { 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 }; //Peripheral address
 //InterruptIn event_button(USER_BUTTON);
 volatile bool go_to_sleep = true;
 
-#define MAX_SERVICES_NOS 1                                                                                                                                   
+#define MAX_SERVICES_NOS 1
 
 
 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
-                            /*GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE*/);
- 
-GattCharacteristic updateRate(GattCharacteristic::UUID_MEASUREMENT_INTERVAL_CHAR , upd, sizeof(upd), sizeof(upd), 
-                            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE|
-                            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE|GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);                            
- 
+
+GattCharacteristic proxLevel(GattCharacteristic::UUID_ALERT_LEVEL_CHAR, mm, sizeof(mm), sizeof(mm),
+                             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY|GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ
+                             /*GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE*/);
+
+GattCharacteristic updateRate(GattCharacteristic::UUID_MEASUREMENT_INTERVAL_CHAR , upd, sizeof(upd), sizeof(upd),
+                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE|
+                              GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE|GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
+
 GattCharacteristic *proxChars[] = {&proxLevel, &updateRate };
 //UUID PROXSERVICE(GattService::UUID_IMMEDIATE_ALERT_SERVICE);
 GattService proxService(GattService::UUID_IMMEDIATE_ALERT_SERVICE, proxChars, sizeof(proxChars) / sizeof(GattCharacteristic *));
- 
+
 static const uint16_t uuid16_list[] = {GattService::UUID_IMMEDIATE_ALERT_SERVICE};
 
 void dist(int distance)
@@ -61,11 +61,16 @@
     DEBUG("Restarting the advertising process\n\r");
     dev.startAdvertising();
 }
- 
-void onWriteCallback(uint16_t attributeHandle) {
-    DEBUG("Write Callback!!\n\r");
+
+void onWriteCallback(uint16_t attributeHandle)
+{
+    if(attributeHandle == updateRate.getHandle()){
+    servo1.write(upd[0]);
     }
-    
+    DEBUG("Write Callback!! %d %d \n\r", attributeHandle, updateRate.getHandle());
+
+}
+
 void onConnectionCallback(uint16_t Handle_t) {
     //myled = 1; // LED is ON
     DEBUG("Connected BlueNRG!!\n\r");