Step3

Dependencies:   BLE_API BMP085 BMP180 I2C_Driver mbed nRF51822

Fork of nRF51822_SimpleControls by Kath VARGAS

Revision:
5:55d6789683d5
Parent:
4:33c71735c529
Child:
6:90c63672a17c
--- a/main.cpp	Wed Dec 14 10:38:35 2016 +0000
+++ b/main.cpp	Sun Jan 01 18:27:03 2017 +0000
@@ -22,7 +22,9 @@
 #include "Servo.h"
 #include "GattCallbackParamTypes.h"
 #include "BMP180.h"
-
+//#include "BMP"
+I2C i2c(D14, D15);
+BMP180 bmp180(&i2c);
 
 #define BLE_UUID_TXRX_SERVICE            0x0000 /**< The UUID of the Nordic UART Service. */
 #define BLE_UUID_TX_CHARACTERISTIC       0x0002 /**< The UUID of the TX Characteristic. */
@@ -108,7 +110,8 @@
             if(buf[1] == 0x01)
                 analog_enabled = 1;
             else
-                analog_enabled = 0;
+                analog_enabled = 0;   
+            
         }
         else if(buf[0] == 0x02)
         {
@@ -181,23 +184,32 @@
     }
     if(temperature_enabled)
     {
+        bmp180.startTemperature();
+        wait_ms(5);
+        
         float temp;
-        float t=bmp180.getTemperature(&temp);
-        uint16_t value=t*1024;
-        buf[0]=(0x0B) ;
-        buf[1]=(value>>8);
+        bmp180.getTemperature(&temp);    
+        uint16_t value=temp*1024;
+        buf[0]=(0x0B);
+        buf[1]=(value >> 8);
         buf[2]=(value);
         ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
+       // printf("Tempreature: %f \r\n", temp);
+        
     }
     if(pressure_enabled)        
     {
+       bmp180.startPressure(BMP180::ULTRA_LOW_POWER);
+       wait_ms(10);
+       
         int pres;
-        int p=bmp180.getPressure(&pres);
-        uint16_t value=p*1024;
+        bmp180.getPressure(&pres);
+        uint16_t value=pres*1024;
         buf[0]=(0x0B);
         buf[1]=(value>>8);
         buf[2]=(value);
         ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3);
+        //printf("Pressure: %d \r\n", pres);
     }
     
     // If digital in changes, report the state
@@ -241,7 +253,7 @@
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                    (const uint8_t *)"Biscuit", sizeof("Biscuit") - 1);
+                                    (const uint8_t *)"FaKa123", sizeof("FaKa123") - 1);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
     // 100ms; in multiples of 0.625ms. 
@@ -253,8 +265,11 @@
     
     pc.printf("Advertising Start \r\n");
     
+    bmp180.init();
+    
     while(1)
     {
+        //bmp180.init();
         ble.waitForEvent(); 
     }
 }