DesignForAmputee hw 5 project

Dependencies:   mbed BLE_API nRF51822

Revision:
10:0193462ea6f1
Parent:
8:114fea2afa09
Child:
11:8500dadc8a7e
--- a/main.cpp	Sat Nov 08 02:27:42 2014 +0000
+++ b/main.cpp	Sun Nov 09 22:38:56 2014 +0000
@@ -1,11 +1,10 @@
 #include "mbed.h"
 #include "BLEDevice.h"
- 
+#include <string>
 #include "UARTService.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. */
-
 Serial pc(USBTX, USBRX);
 
 #if NEED_CONSOLE_OUTPUT
@@ -35,10 +34,11 @@
 {
     if ((uartServicePtr != NULL) && (params->charHandle == uartServicePtr->getTXCharacteristicHandle())) {
         float temp = tempPin.read(); // temperature voltage
-
-        float tempC = ((temp*3)-0.5)*100; // conversion to celcius
-        float tempF = (tempC*9/5)+32;                 // conversion to fahrenheit
-
+        
+        float tempC = ((temp*3.0)-0.5)*100.0; // conversion to celcius
+        float tempF = (tempC*9.0/5.0)+32.0;                 // conversion to fahrenheit
+        DEBUG("temp[V]:%f\ttemp[C]:%f\ttemp[F]:%f\n",temp,tempC,tempF);
+        //DEBUG(params->data, "%
         uint16_t bytesRead = params->len;
         DEBUG("received %u bytes\n\r", bytesRead);
         DEBUG("first byte received: %u\n\r", params->data[0]);
@@ -51,8 +51,11 @@
             led2 = 0;
             powerSwitch = 0;
         }
-        ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
-        //ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)&tempF, sizeof(tempF));
+        //ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
+        char buffer[30];
+        sprintf(buffer,"%4.0f",tempF);
+        char *data [] = {buffer};
+        ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t *)data, sizeof(&data));
 
     }
 }