mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   EthernetNetIf SDHCFileSystem I2CLEDDisp Agentbed NTPClient_NetServices mbed BMP085 HTTPClient ConfigFile I2CLCD

Revision:
3:60f5f6d5f765
Parent:
2:4125fe2283ef
Child:
5:9fa79cb5ec98
--- a/main.cpp	Mon Dec 13 16:40:19 2010 +0000
+++ b/main.cpp	Wed Dec 15 16:58:30 2010 +0000
@@ -7,11 +7,15 @@
 /** @file
  * @brief mbed Weather Platform
  */
+
+#define VERSION "mbed Weather Platform 0.1.1 (C) 2010 Suga koubou Co.,Ltd."
+#define USE_I2CLEDDISP // I2C LED Display
+//#define NONBLOCKING // ethernet function non-bloking
+ 
 #include "mbed.h"
 #include "BMP085.h"
 #include "SHT.h"
 #include "WeatherMeters.h"
-//#include "I2CLCD.h"
 #include "ConfigFile.h"
 #include "SDFileSystem.h"
 #include "MSCFileSystem.h"
@@ -19,9 +23,9 @@
 #include "NTPClient.h"
 #include "HTTPClient.h"
 
-#define VERSION "mbed Weather Platform 0.1a (C) 2010 Suga koubou Co.,Ltd."
-
-//#define NONBLOCKING
+#ifdef USE_I2CLEDDISP
+#include "I2CLEDDisp.h"
+#endif
 
 Serial pc(USBTX, USBRX);
 int seq = 0;
@@ -35,11 +39,17 @@
 float pres, temp, humi, light, anemo, vane, rain, uv, moist, temp2;
 I2C i2c(p9, p10);
 BMP085 bmp085(i2c, BMP085_oss4);
-//I2CLCD i2clcd(i2c);
 SHT sht15(p12, p11, SHT_high); // sclock, data
 WeatherMeters wmeters(p21, p15, p22); // anemo, vane, rain
 AnalogIn ailight(p16), aimoist(p18), aiuv(p17);
 
+#ifdef USE_I2CLEDDISP
+I2CLEDDisp leddisp(i2c);
+Ticker ticker;
+int ledpos, ledflg;
+char ledbuf[100];
+#endif
+
 // Ethernet
 EthernetNetIf *eth; 
 NTPClient *ntp;
@@ -78,24 +88,41 @@
     return f;
 }
 
+#ifdef USE_I2CLEDDISP
+void ledscroll () {
+    int i, addr, len;
+
+    len = strlen(ledbuf);
+    leddisp.locate(0, 0);
+    for (i = 0; i < 4; i ++) {
+        addr = ledpos + i;
+        if (addr >= 0 && addr < len) {
+            leddisp.putc(ledbuf[addr]);
+        } else {
+            leddisp.putc(' ');
+        }
+    }
+    ledpos ++;
+    if (ledpos >= len + 4) {
+        ledpos = -4;
+    }
+}
+#endif
+
 void action (char *buf) {
     if (check_action('H')) {
-pc.putc('H');
         led4 = 1;
     }
     if (check_action('L')) {
-pc.putc('L');
         led4 = 0;
     }
     if (check_action('P')) {
         if (conf.ipaddr[0] && conf.pachube_apikey[0] && conf.pachube_feedid[0]) {
-pc.putc('P');
             pachube(buf);
         }
     }
     if (check_action('T')) {
         if (conf.ipaddr[0] && conf.twitter_user[0] && conf.twitter_pwd[0]) {
-pc.putc('T');
             twitter();
         }
     }
@@ -189,6 +216,12 @@
     char buf[100];
     
     led1 = 1;
+#ifdef USE_I2CLEDDISP
+    ledflg = 0;
+    ledpos = -4;
+    strcpy(ledbuf, VERSION);
+    ticker.attach(&ledscroll, 0.4);
+#endif
     init();
     pc.printf(VERSION "\r\n\r\n");
 
@@ -197,6 +230,22 @@
         writefile(buf);
     }
     
+#ifdef USE_I2CLEDDISP
+    ledpos = -4;
+    sec = time(NULL);
+    strftime(ledbuf, sizeof(ledbuf), "%H:%M", localtime(&sec));
+    sprintf(&ledbuf[5], " %ds %s", conf.interval, filename);
+    if (conf.ipaddr[0]) {
+        sprintf(&ledbuf[strlen(ledbuf)], " %d.%d.%d.%d", conf.ipaddr[0], conf.ipaddr[1], conf.ipaddr[2], conf.ipaddr[3]);
+        if (conf.pachube_apikey[0] && conf.pachube_feedid[0]) {
+            strcat(ledbuf, " P");
+        }
+        if (conf.twitter_user[0] && conf.twitter_pwd[0]) {
+            strcat(ledbuf, " T");
+        }
+    }
+#endif
+    
     timer.start();
 #ifdef NONBLOCKING
     while (timer.read() < 5) {
@@ -204,7 +253,7 @@
     }
     timer.reset();
 #endif
-    
+
     while(1) {
         led1 = 0;
 
@@ -227,12 +276,6 @@
         light = get_photo(ailight);
         moist = get_moist(aimoist);
         uv = get_uv(aiuv);
-/*
-        i2clcd.locate(0, 0);
-        i2clcd.printf("%4.1f hPa", p);
-        i2clcd.locate(0, 1);
-        i2clcd.printf("%2.1f C / %2.1f %%", t, h);
-*/
 
         sprintf(&buf[strlen(buf)], ",%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\r\n", pres, temp, humi, anemo, vane, rain, light, uv, moist, temp2);
         pc.printf(buf);
@@ -240,20 +283,17 @@
             // csv
             writefile(buf);
         }
-        
+
         action(&buf[20]);
-/*
-        if (conf.ipaddr[0]) {
-            if (conf.pachube_apikey[0] && conf.pachube_feedid[0]) {
-                // pachube
-                pachube(&buf[20]);
-            }
-            if (conf.twitter_user[0] && conf.twitter_pwd[0]) {
-                // twitter
-//                twitter();
-            }
+
+#ifdef USE_I2CLEDDISP
+        if (ledflg) {
+            ledpos = -4;
+            strftime(ledbuf, sizeof(ledbuf), "%H:%M", localtime(&sec));
+            sprintf(&ledbuf[5], " %dhPa %d\x1b %d%% %dm/s %d' %dmm/h", (int)pres, (int)temp, (int)humi, (int)anemo, (int)vane, (int)rain);
         }
-*/
+        ledflg = 1;
+#endif
         led1 = 1;
 
         while (timer.read() < conf.interval) {