Add HeartRateMonitor

Dependencies:   BLE_API_Native_TBO TMP102 mbed

Fork of BLE_Health_Thermometer_IRC by Yoshihiro TSUBOI

Files at this revision

API Documentation at this revision

Comitter:
ghz2000
Date:
Mon Jun 16 15:13:32 2014 +0000
Parent:
4:51e3d15f6b54
Commit message:
Add HeartRateMonitor

Changed in this revision

BLE_API_Native_IRC.lib Show diff for this revision Revisions of this file
BLE_API_Native_TBO.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BLE_API_Native_IRC.lib	Wed Jun 11 15:20:50 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/ytsuboi/code/BLE_API_Native_IRC/#d84e7516652b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_API_Native_TBO.lib	Mon Jun 16 15:13:32 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ghz2000/code/BLE_API_Native_TBO/#a58a51c92075
--- 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));
 }
 
 /**