workss

Dependencies:   mbed BLE_API nRF51822 VL53L0X

Revision:
33:3fad9e7238a4
Parent:
32:b9306ebceb61
Child:
34:1d3818f8c1a1
--- a/main.cpp	Wed Mar 13 19:58:19 2019 +0000
+++ b/main.cpp	Wed Mar 13 20:05:54 2019 +0000
@@ -27,20 +27,16 @@
 static DigitalOut shutdown2_pin(range2_XSHUT);
 static VL53L0X range2(&devI2c, &shutdown2_pin, NC);
  
-uint32_t distance1;
-uint32_t distance2;
-int dist1;
-int dist2;
-int status1;
-int status2;
+uint32_t distance1, distance2;
+int dist1, dist2, status1, status2;
 
 const static int cw = 20 / TIME_SCALE;
 int countdown = cw;
 bool countdown1_triggered = false, countdown2_triggered = false;
 bool step_in = false, step_out = false;
  
-const static char     DEVICE_NAME[]        = "OCCUPY-CRICHTON-ST"; // change this
-static const uint16_t uuid16_list[]        = {GattService::UUID_HEART_RATE_SERVICE}; //Custom UUID, FFFF is reserved for development
+const static char     DEVICE_NAME[]        = "OCCUPY-CRICHTON-ST"; 
+static const uint16_t uuid16_list[]        = {GattService::UUID_HEART_RATE_SERVICE};
  
 HeartRateService         *hrService;
 uint8_t hrmCounter = 0; 
@@ -68,18 +64,17 @@
     ble.gap().onDisconnection(disconnectionCallback);
     hrService = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER);
  
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); // BLE only, no classic BT
-    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); // advertising type
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); // add name
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); // UUID's broadcast in advertising packet
-    ble.gap().setAdvertisingInterval(100); // 100ms.
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.gap().setAdvertisingInterval(100);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
  
     ble.gap().startAdvertising();
 }
  
 int format_dist(int distance) {
-   // local variable declaration
    int result;
  
    if (distance > 1270)
@@ -133,6 +128,7 @@
     } else {
         printf("Range1 [mm]:                --\r\n");
         led1 = 1;
+        
     }
     if (status2 == VL53L0X_ERROR_NONE) {
         printf("Range2 [mm]:            %6ld\r\n", dist2);
@@ -160,13 +156,10 @@
     range1.init_sensor(range1_addr);
     range2.init_sensor(range2_addr);
     
-    printf("\n\r********* Starting Main Loop *********\n\r");
-  
     BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
     ble.init(bleInitComplete);
     
     Ticker ticker;
-    
     ticker.attach(wakeup_event_cb, 0.1 * TIME_SCALE);
     
     while (ble.hasInitialized()) {