This is mandatory

Dependencies:   BLE_API mbed nRF51822 SHT21_ncleee

Revision:
3:b6d2c5195055
Parent:
2:654ee4b3950f
Child:
4:fddb2d7c7c61
diff -r 654ee4b3950f -r b6d2c5195055 main.cpp
--- a/main.cpp	Mon Nov 09 23:09:16 2015 +0000
+++ b/main.cpp	Thu Nov 12 22:42:05 2015 +0000
@@ -1,34 +1,28 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+#define I2C_SDA p3
+#define I2C_SCL p4
 
 #include "mbed.h"
 #include "BLE.h"
 #include "battery.h"
 #include "WeatherService.h"
 #include "BatteryService.h"
+#include "BMP180.h"
 
 BLE        ble;
-DigitalOut led1(LED1);
-AnalogIn   batteryPin(p1);
+DigitalOut okLED(LED1);
+DigitalOut errLED(LED2);
+DigitalOut instrumentsPower(p30);
 
-const static char     DEVICE_NAME[]        = "Weather Station";
-static const uint16_t uuid16_list[] = {
+BMP180 bmp180;
+Serial pc(USBTX, USBRX);
+
+const static char DEVICE_NAME[] = "Weather Station";
+
+static const uint16_t serviceList[] = {
     GattService::UUID_ENVIRONMENTAL_SERVICE, 
     GattService::UUID_BATTERY_SERVICE
 };
+
 static volatile bool  triggerSensorPolling = false;
 
 /* Restart Advertising on disconnection*/
@@ -39,28 +33,51 @@
 
 void blink(void)
 {
-//    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
+//    statusLED = !statusLED;
     triggerSensorPolling = true;
 }
 
 int main(void)
 {
-    led1 = 1;
+    pc.printf("Start\n");
+    
+    okLED = 1;
+    errLED = 1;
+    instrumentsPower = 1;
+    wait(1);    
+    uint8_t c = bmp180.readByte(BMP180_ADDRESS, BMP180_WHO_AM_I);   
+
+    pc.printf("BMP-180 is 0x%x\n\r", c);
+    pc.printf("BMP-180 should be 0x55\n");
+
+    if(c == 0x55) {
+        okLED = 0;
+        pc.printf("BMP-180 online...\n");
+       
+        bmp180.BMP180Calibration();
+        pc.printf("BMP-180 calibration complete...\n");
+   }
+   else 
+   {
+        errLED = 0;
+        pc.printf("BMP-180 unreachable...\n");
+        while(1); // idle here forever
+   }
+
     Ticker ticker;
-    ticker.attach(blink, 1);
+    ticker.attach(blink, 2);
 
     ble.init();
     ble.gap().onDisconnection(disconnectionCallback);
 
     /* Setup weather service. */
-    float currentTemperature = 42.22;
     WeatherService weatherService(ble);
     BatteryService batteryService(ble, 0);
     Battery battery(BATTERY_PIN);
 
     /* setup advertising */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)serviceList, sizeof(serviceList));
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::UNKNOWN);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
@@ -69,19 +86,23 @@
 
     while (true) {
         if (triggerSensorPolling && ble.getGapState().connected) {
+            okLED = 1;
             triggerSensorPolling = false;
 
-            /* Do blocking calls or whatever is necessary for sensor polling. */
-            // error = sensor.readData();
-            // if (!error) {
-            //     thermometerService.updateTemperature(c);
-            // }
+            float temperature = (float)bmp180.BMP180GetTemperature()/10.0f;
+            float pressure = (float)bmp180.BMP180GetPressure();
+            float altitude = 44330.0f*( 1.0f - pow((pressure/101325.0f), (1.0f/5.255f)));
 
-            /* In our case, we simply update the dummy temperature measurement. */
-            currentTemperature += 0.1;
-            weatherService.updateTemperature(currentTemperature);
-            weatherService.updatePressure(0);
+            pc.printf("Temp: %.1f C\n", temperature);
+            pc.printf("Pressure: %.3f Pa\n", pressure);
+            pc.printf("Altitude: %.1f m\n", altitude);
+            pc.printf("---\n");
+
+            weatherService.updateTemperature(temperature);
+            weatherService.updatePressure(pressure);
             weatherService.updateHumidity(0);
+                        
+            
             batteryService.updateBatteryLevel(battery.read());
         } else {
             ble.waitForEvent();