hrm1017 with gy-801 temp

Dependencies:   BLE_API TMP102 mbed nRF51822

Fork of BLE_HTM_HRM1017 by Switch Science

Revision:
8:f753b4b022a8
Parent:
6:c3d9dbadd654
Child:
9:554af3c63d0c
--- a/main.cpp	Sat Sep 13 09:32:10 2014 +0000
+++ b/main.cpp	Thu Aug 27 15:14:41 2015 +0000
@@ -1,7 +1,6 @@
 #include "mbed.h"
 #include "TMP102.h"
-#include "BLEDevice.h"
-#include "ble_hts.h"
+#include "BLE.h"
 
 #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
                                * it will have an impact on code-size and power consumption. */
@@ -17,7 +16,7 @@
 static volatile bool  triggerSensorPolling = false;
 
 BLEDevice  ble;
-TMP102      healthThemometer(p22, p20, 0x90);  /* The TMP102 connected to our board */
+TMP102      healthThemometer(I2C_SDA0, I2C_SCL0, 0x90);  /* The TMP102 connected to our board */
 //TMP102      healthThemometer(I2C_SDA1, I2C_SCL1, 0x90);  /* The TMP102 connected to our board */
 
 /* LEDs for indication: */
@@ -56,19 +55,19 @@
 {
     advertisingStateLed = 1;
     
-    DEBUG("Disconnected handle %u, reason %u\n", handle, reason);
-    DEBUG("Restarting the advertising process\n\r");
-    ble.startAdvertising();
+    DEBUG("Disconnected handle %u, reason %u\r\n", handle, reason);
+    DEBUG("Restarting the advertising process\r\n");
+    ble.gap().startAdvertising();
 }
 
-void onConnectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *params)   //Mod
+void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params)   //Mod
 {
     advertisingStateLed = 0;
 
-    DEBUG("connected. Got handle %u\r\n", handle);
+    DEBUG("connected. Got handle %u\r\n", params->handle);
 
     connectionParams.slaveLatency = 1;
-    if (ble.updateConnectionParams(handle, &connectionParams) != BLE_ERROR_NONE) {
+    if (ble.gap().updateConnectionParams(params->handle, &connectionParams) != BLE_ERROR_NONE) {
         DEBUG("failed to update connection paramter\r\n");
     }
 }
@@ -95,28 +94,28 @@
     Ticker ticker;
     ticker.attach(periodicCallback, 1);
        
-    DEBUG("Initialising the nRF51822\n");
+    DEBUG("Initialising the nRF51822\r\n");
     ble.init();
-    DEBUG("Init done\n");
-    ble.onDisconnection(disconnectionCallback);
-    ble.onConnection(onConnectionCallback);
+    DEBUG("Init done\r\n");
+    ble.gap().onDisconnection(disconnectionCallback);
+    ble.gap().onConnection(onConnectionCallback);
 
-    ble.getPreferredConnectionParams(&connectionParams);
+    ble.gap().getPreferredConnectionParams(&connectionParams);
 
     /* setup advertising */
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list));
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
-    ble.startAdvertising();
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
+    ble.gap().startAdvertising();
     advertisingStateLed = 1;
-    DEBUG("Start Advertising\n");
+    DEBUG("Start Advertising\r\n");
 
-    ble.addService(htmService);
-    ble.addService(battService);
-    DEBUG("Add Service\n");
+    ble.gattServer().addService(htmService);
+    ble.gattServer().addService(battService);
+    DEBUG("Add Service\r\n");
 
     while (true) {
         if (triggerSensorPolling) {
@@ -140,11 +139,11 @@
       
       /* Update the temperature. Note that we need to convert to an ieee11073 format float. */
       float temperature = healthThemometer.read();
-      DEBUG("temp:%f\n", temperature);
+      DEBUG("temp:%f\r\n", temperature);
       uint32_t temp_ieee11073 = quick_ieee11073_from_float(temperature);
       memcpy(thermTempPayload+1, &temp_ieee11073, 4);
-      ble.updateCharacteristicValue(tempChar.getValueAttribute().getHandle(), thermTempPayload, sizeof(thermTempPayload));  //Mod
-      ble.updateCharacteristicValue(battLevel.getValueAttribute().getHandle(), (uint8_t *)&batt, sizeof(batt));             //Mod
+      ble.gattServer().write(tempChar.getValueAttribute().getHandle(), thermTempPayload, sizeof(thermTempPayload));  //Mod
+      ble.gattServer().write(battLevel.getValueAttribute().getHandle(), (uint8_t *)&batt, sizeof(batt));             //Mod
 }
 
 /**
@@ -159,4 +158,3 @@
     
     return ( ((uint32_t)exponent) << 24) | mantissa;
 }
-