Ashu Joshi / Mbed 2 deprecated SensorInterface

Dependencies:   BME280 SerialGPS libmDot mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
AshuJoshi
Date:
Mon Jul 04 22:29:31 2016 +0000
Parent:
1:36e336869699
Child:
3:5c2bcba214b5
Commit message:
Added mDot support - logging, init, and sleep. Minor enhancements to BME280 - formatted output as strings.

Changed in this revision

libmDot.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmDot.lib	Mon Jul 04 22:29:31 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/MultiTech/code/libmDot/#50142f513ba8
--- a/main.cpp	Sun Jul 03 16:00:14 2016 +0000
+++ b/main.cpp	Mon Jul 04 22:29:31 2016 +0000
@@ -7,8 +7,17 @@
  
  #include "mbed.h"
  #include <math.h>
+ #include <string>
+ #include "mDot.h"
+ #include "MTSLog.h"
+ #include "MTSText.h"
  #include "BME280.h"
  
+using namespace mts;
+ 
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+ 
 // mDot UDK Specific
 // MDot Pinout: https://developer.mbed.org/platforms/MTS-mDot-F411/#pinout-diagram
 // Uncomment this line if using a full sized UDK2.0 instead of a Micro UDK
@@ -28,12 +37,17 @@
 
 // Globals
 Ticker tick;
+mDot* dot;
+
 
 // Function Declarations
 void endLessTestLoop();
 void setUpLEDBlink();
 void blink();
 void readandprintBME280();
+void mDotConfig();
+void mDotGotoDeepSleep(int seconds);
+
 
 
 /*****************************************************
@@ -43,12 +57,35 @@
 
     // Simple Test Functions, "Hello World on UDK
     setUpLEDBlink();
-    
+    mDotConfig();
     endLessTestLoop();
     
     return 0;
 }
 
+/*****************************************************
+ *         mDot Functions
+ ****************************************************/
+
+
+void mDotConfig() {
+    // get a mDot handle
+    dot = mDot::getInstance();
+    //dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+    dot->setLogLevel(mts::MTSLog::TRACE_LEVEL);
+    // print library version information
+    logInfo("version: %s", dot->getId().c_str());
+}
+
+void mDotGotoDeepSleep(int seconds) {
+    // logInfo("input to sleep routine %d", seconds);
+    // Should  sleep here and wakeup after a set interval.
+    uint32_t sleep_time = MAX((dot->getNextTxMs() / 1000), seconds);
+    logInfo("going to sleep for %d seconds", sleep_time);
+    // go to sleep and wake up automatically sleep_time seconds later
+    dot->sleep(sleep_time, mDot::RTC_ALARM, false);
+
+}
 
 
 
@@ -57,7 +94,25 @@
  ****************************************************/
 
 void readandprintBME280() {
-    printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", b280.getTemperature(), b280.getPressure(), b280.getHumidity());
+    float temperature;
+    float pressure;
+    float humidity;
+    char string_buffer[64];
+    
+    // Temperature
+    temperature = b280.getTemperature();
+    sprintf(string_buffer, "%s%3.2f", "TC:", temperature);
+    logInfo("The temperature is %s", string_buffer);
+    // Pressure
+    pressure = b280.getPressure();
+    sprintf(string_buffer, "%s%04.2f", "hPa:", pressure);
+    logInfo("The pressure is %s", string_buffer);
+    // Humidity
+    humidity = b280.getHumidity();
+    sprintf(string_buffer, "%s%03.2f", "H%:", humidity);
+    logInfo("The humidty is %s", string_buffer);
+    
+    // printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", temperature, pressure, humidity);
 }
 
 
@@ -76,7 +131,9 @@
         // printf("Hello world!\r\n");
         printf("BME280 Sensor: \n");
         readandprintBME280();
-        wait(5);   
+        
+        mDotGotoDeepSleep(10);
+       
     }
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Jul 04 22:29:31 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#4c105b8d7cae