Graduation Thesis, use Nucleo and X-Nucleo BLE

Dependencies:   PulseSensor GSM Thermometer KalmanFilter

Revision:
4:e44cd8682f1c
Parent:
3:9b552b775c6e
Child:
5:c12c16c0d2ea
diff -r 9b552b775c6e -r e44cd8682f1c application/main.cpp
--- a/application/main.cpp	Thu Feb 15 12:53:31 2018 +0000
+++ b/application/main.cpp	Thu Feb 15 17:41:06 2018 +0000
@@ -4,17 +4,26 @@
   * Revision:
   * version 0.8     02-12-2018
   * version 0.8.5   02-14-2018
-  * version 0.9     02-15-2018  Pulse sensor added
+  * version 0.9     02-15-2018  Pulse sensor and thermometer added 
+  * version 0.9.5   02-16-2018  Calculation for pulse sensor and thermometer. GSM library added 
 
 /* ======================== INCLUDES ========================= */
 #include <events/mbed_events.h>
 #include <mbed.h>
 #include "ble/BLE.h"
 #include "ble_healthcare_service.h"
+#include "GMS.h"
+#include "LM35.h"
 #include "PulseSensor.h"
 
+
+
 /* ======================== DEFINES ========================== */
-#define SENSOR_PIN      A0
+#define THERM_FINGER_LOCATION   3
+#define HRM_FINGER_LOCATION     3
+
+#define PULSE_SENSOR_PIN        A0
+#define THERM_SENSOR_PIN        A1
 
 /* ======================= VARIABLES ========================= */
 /* GLOBAL VARIABLES */
@@ -30,7 +39,16 @@
 HealthCareService       *HealthCareServicePtr;
 //PulseSensor              PulseSensor();
 
+Serial                   serial(USBTX, USBRX);
+
 /* ================== FUNCTION PROTOTYPES ==================== */
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *);
+void onBleInitError(BLE &ble, ble_error_t error);
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params);
+void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context);
+
+void main_event(void);
+void periodicCallback(void);
 
 /* ==================== FUNCTION DETAILS ===================== */
 /* Restart Advertising on disconnection*/
@@ -43,14 +61,16 @@
        In our case, we simply update the Temperature measurement. */
     currentTemperature = (currentTemperature + 0.1 > 43.0) ? 39.6 : currentTemperature + 0.1;
     currentHRMCounter  = (currentHRMCounter + 1 > 120) ? 80 : currentHRMCounter + 1;
-    HealthCareServicePtr->updateTemperature(currentTemperature);
-    HealthCareServicePtr->updateHeartRate(currentHRMCounter);
+    if (BLE::Instance().gap().getState().connected) {
+        HealthCareServicePtr->updateTemperature(currentTemperature);
+        HealthCareServicePtr->updateHeartRate(currentHRMCounter);        
+    }
+
 }
 
 void periodicCallback(void) {
-    if (BLE::Instance().gap().getState().connected) {
-        eventQueue.call(main_event);
-    }
+    /* call main_event immediately */
+    eventQueue.call(main_event);
 }
 
 void printMacAddress() {
@@ -67,6 +87,7 @@
 
 void onBleInitError(BLE &ble, ble_error_t error) {
    /* Initialization error handling should go here */
+   
 }
 
 /** 
@@ -87,8 +108,8 @@
     }
 
     ble.gap().onDisconnection(disconnectionCallback);
-    HealthCareServicePtr = new HealthCareService(ble, currentTemperature, 3, 
-                                                      currentHRMCounter, 3);
+    HealthCareServicePtr = new HealthCareService(ble, currentTemperature, THERM_FINGER_LOCATION, 
+                                                      currentHRMCounter, HRM_FINGER_LOCATION);
 
     /* setup advertising */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
@@ -110,12 +131,18 @@
 
 /* MAIN FUNCTION */
 int main() {
+    
+    serial.baud(115200);
+    printf("\r\n BODY WIRELESS SENSOR NETWORK\r\n");
+    /* call periodicCallback every 500ms */
     eventQueue.call_every(500, periodicCallback);
-
+    
+    /* init BLE */
     BLE &ble = BLE::Instance();
     ble.onEventsToProcess(scheduleBleEventsProcessing);
     ble.init(bleInitComplete);
-
+    
+    /* dispatch the event queue */
     eventQueue.dispatch_forever();
 
     return 0;