Sample BLE thermometer profile for nRF51-DK with sensing from LM35

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_Thermometer by Bluetooth Low Energy

Revision:
4:83c07b0e93d6
Parent:
2:a34d554282b0
Child:
8:63addc0221e7
--- a/main.cpp	Thu Sep 04 07:14:25 2014 +0000
+++ b/main.cpp	Mon Sep 22 10:47:20 2014 +0000
@@ -20,9 +20,10 @@
 #include "DHT.h"
 
 BLEDevice  ble;
+DigitalOut led1(LED1);
 DHT        sensor(D10, DHT11);
 
-#define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
+#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
                                * it will have an impact on code-size and power consumption. */
 
 #if NEED_CONSOLE_OUTPUT
@@ -45,6 +46,8 @@
 
 void periodicCallback(void)
 {
+    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
+
     /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
      * heavy-weight sensor polling from the main thread. */
     triggerSensorPolling = true;
@@ -52,8 +55,9 @@
 
 int main(void)
 {
+    led1 = 1;
     Ticker ticker;
-    ticker.attach(periodicCallback, 3);
+    ticker.attach(periodicCallback, 1);
 
     DEBUG("Initialising the nRF51822\n\r");
     ble.init();
@@ -71,18 +75,19 @@
     float initialTemperature = 39.6;
     HealthThermometerService thermometerService(ble, initialTemperature, HealthThermometerService::LOCATION_EAR);
 
+    int error = 0;
+    float c = 0.0f;
+
     while (true) {
         if (triggerSensorPolling) {
             triggerSensorPolling = false;
 
-            wait(2);
-            
             /* Do blocking calls or whatever is necessary for sensor polling. */
             /* In our case, we simply update the dummy HRM measurement. */
-            int error = sensor.readData();
-            DEBUG("sensor read returned %d\r\n", error);
+            error = sensor.readData();
             if (!error) {
-                thermometerService.updateTemperature(sensor.ReadTemperature(CELCIUS));
+                c = sensor.ReadTemperature(CELCIUS);
+                thermometerService.updateTemperature(c);
             }
         } else {
             ble.waitForEvent();