workss

Dependencies:   mbed BLE_API nRF51822 VL53L0X

Revision:
26:793d65b08afb
Parent:
25:0a0805c118c0
Child:
27:903ec28ea7a0
--- a/main.cpp	Thu Mar 07 19:01:23 2019 +0000
+++ b/main.cpp	Thu Mar 07 19:09:08 2019 +0000
@@ -36,46 +36,13 @@
 
 HeartRateService         *hrService;
 DeviceInformationService *deviceInfo;
-uint8_t hrmCounter = 100; // init HRM to 100bps
-
-/* Set Up custom Characteristics */
-static uint8_t readValue[10] = {0};
-ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(readValue)> readChar(readCharUUID, readValue);
-
-static uint8_t writeValue[10] = {0};
-WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeValue)> writeChar(writeCharUUID, writeValue);
-
-/* Set up custom service */
-GattCharacteristic *characteristics[] = {&readChar, &writeChar};
-GattService        customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
+uint8_t hrmCounter = 0; 
 
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *)
 {
     BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
 }
 
-void writeCharCallback(const GattWriteCallbackParams *params)
-{
-    /* Check to see what characteristic was written, by handle */
-    if(params->handle == writeChar.getValueHandle()) {
-        /* toggle LED if only 1 byte is written */
-        if(params->len == 1) {
-            led = params->data[0];
-            (params->data[0] == 0x00) ? printf("led on\n\r") : printf("led off\n\r"); // print led toggle
-        }
-        /* Print the data if more than 1 byte is written */
-        else {
-            printf("Data received: length = %d, data = 0x",params->len);
-            for(int x=0; x < params->len; x++) {
-                printf("%x", params->data[x]);
-            }
-            printf("\n\r");
-        }
-        /* Update the readChar with the value of writeChar */
-        BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), params->data, params->len);
-    }
-}
-
 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
 {
     BLE &ble          = params->ble;
@@ -95,7 +62,6 @@
     ble.gap().setAdvertisingInterval(100); // 100ms.
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
 
-    ble.addService(customService);
     ble.gap().startAdvertising();
 }
 void wakeup_event_cb() {
@@ -103,10 +69,12 @@
     
     status1 = range1.get_distance(&distance1);
     status2 = range2.get_distance(&distance2);
+    
     if (status1 == VL53L0X_ERROR_NONE) {
         printf("Range1 [mm]:            %6ld\r\n", distance1);
         if (distance1 > 40 && distance1 < 2200) {
             led1 = 0;
+            hrmCounter++;
         }
         else {
             led1 = 1;
@@ -119,12 +87,13 @@
         printf("Range2 [mm]:            %6ld\r\n", distance2);
     if (distance2 > 40 && distance2 < 2200) {
         led2 = 0;
+        hrmCounter++;
     }
     } else {
         printf("Range2 [mm]:                --\r\n");
         led2 = 1;
     }
-//  wait(0.2);    
+    hrService->updateHeartRate(hrmCounter);
 }
 
 int main(void)