Add HeartRateMonitor

Dependencies:   BLE_API_Native_TBO TMP102 mbed

Fork of BLE_Health_Thermometer_IRC by Yoshihiro TSUBOI

Revision:
5:0b26ee423037
Parent:
2:f11df1469db2
--- a/main.cpp	Wed Jun 11 15:20:50 2014 +0000
+++ b/main.cpp	Mon Jun 16 15:13:32 2014 +0000
@@ -32,6 +32,14 @@
 GattCharacteristic  thermTemp (GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR,
                                5, 5, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE);
 
+/* Heart Rate Servece */
+uint8_t            heartRate = 100;
+uint8_t            heartRatePayload[8] =  { 0,0,0,0,0,0,0,0};
+GattService        heartRateService (GattService::UUID_HEART_RATE_SERVICE);
+GattCharacteristic heartRateChar (GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR,
+                                8,8, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
+
+
 /* Battery Level Service */
 uint8_t            batt = 100;     /* Battery level */
 uint8_t            read_batt = 0; /* Variable to hold battery level reads */
@@ -41,13 +49,15 @@
                                  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
 
 
+
 /* Advertising data and parameters */
 GapAdvertisingData   advData;
 GapAdvertisingData   scanResponse;
 GapAdvertisingParams advParams ( GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED );
 
 uint16_t             uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE,
-                                      GattService::UUID_BATTERY_SERVICE};
+                                      GattService::UUID_BATTERY_SERVICE,
+                                      GattService::UUID_HEART_RATE_SERVICE};
 
 uint32_t quick_ieee11073_from_float(float temperature);
 void updateServiceValues(void);
@@ -106,6 +116,10 @@
     thermService.addCharacteristic(thermTemp);
     nrf.getGattServer().addService(thermService);
     
+    /* Heart Rate Service */
+    heartRateService.addCharacteristic(heartRateChar);
+    nrf.getGattServer().addService(heartRateService);
+    
     /* Add the Battery Level service */
     battService.addCharacteristic(battLevel);
     nrf.getGattServer().addService(battService);
@@ -127,6 +141,9 @@
     @brief  Ticker callback to switch advertisingStateLed state
 */
 /**************************************************************************/
+
+int sec = 0;
+
 void updateServiceValues(void)
 {
       /* Toggle the one second LEDs */
@@ -142,6 +159,19 @@
       uint32_t temp_ieee11073 = quick_ieee11073_from_float(temperature);
       memcpy(thermTempPayload+1, &temp_ieee11073, 4);
       nrf.getGattServer().updateValue(thermTemp.handle, thermTempPayload, sizeof(thermTempPayload));
+      
+      /* Update the HeartRate */
+      if(sec ==3){
+          if(heartRate < 200)heartRate++;
+          else heartRate = 0;
+          sec = 0;
+      }else{
+          sec++;
+      }
+      uint8_t heartRateFlags = 0x00;
+      heartRatePayload[0] = heartRateFlags;
+      heartRatePayload[1] = heartRate;
+      nrf.getGattServer().updateValue(heartRateChar.handle, heartRatePayload , sizeof(heartRatePayload));
 }
 
 /**