Sample BLE Test

Dependencies:   mbed X_NUCLEO_IDB0XA1 BLE_API X_NUCLEO_IKS01A1

Files at this revision

API Documentation at this revision

Comitter:
olivasil
Date:
Fri Feb 22 11:29:35 2019 +0000
Parent:
3:a51ca6313ad2
Commit message:
Sample test

Changed in this revision

X_NUCLEO_IKS01A1.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IKS01A1.lib	Fri Feb 22 11:29:35 2019 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A1/#a91987e8cf51
--- a/main.cpp	Tue Sep 29 15:06:46 2015 +0000
+++ b/main.cpp	Fri Feb 22 11:29:35 2019 +0000
@@ -20,14 +20,31 @@
 #include "ble/services/BatteryService.h"
 #include "ble/services/DeviceInformationService.h"
 
+#include "x_nucleo_iks01a1.h"
+
+
 BLE  ble;
 DigitalOut led1(LED1);
+InterruptIn event(USER_BUTTON);
 
 const static char     DEVICE_NAME[]        = "HRM1";
 static const uint16_t uuid16_list[]        = {GattService::UUID_HEART_RATE_SERVICE,
                                               GattService::UUID_DEVICE_INFORMATION_SERVICE};
 static volatile bool  triggerSensorPolling = false;
 
+/* Instantiatethe expansion board */
+static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
+static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
+
+
+int button_pressed = 0;
+ 
+void pressed()
+{
+    button_pressed = 1;
+}
+
+
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
 {
     ble.gap().startAdvertising(); // restart advertising
@@ -46,6 +63,7 @@
     led1 = 1;
     Ticker ticker;
     ticker.attach(periodicCallback, 1); // blink LED every second
+    float value1;
 
     ble.init();
     ble.gap().onDisconnection(disconnectionCallback);
@@ -65,6 +83,8 @@
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.gap().setAdvertisingInterval(1000); /* 1000ms */
     ble.gap().startAdvertising();
+    
+    event.fall(&pressed);
 
     // infinite loop
     while (1) {
@@ -74,7 +94,14 @@
 
             // Do blocking calls or whatever is necessary for sensor polling.
             // In our case, we simply update the HRM measurement.
-            hrmCounter++;
+            temp_sensor1->GetTemperature(&value1);
+            //printf("HTS221: [temp] %7s°C\r\n", printDouble(buffer1, value1));            
+
+            if (button_pressed == 1)
+            {
+              hrmCounter++;
+              button_pressed = 0;
+            }
 
             //  100 <= HRM bps <=175
             if (hrmCounter == 175) {
@@ -82,7 +109,8 @@
             }
 
             // update bps
-            hrService.updateHeartRate(hrmCounter);
+            //hrService.updateHeartRate(hrmCounter);
+            hrService.updateHeartRate((uint8_t)value1);
         } else {
             ble.waitForEvent(); // low power wait for event
         }