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
Diff: main.cpp
- Revision:
- 10:848a2205aed1
- Parent:
- 9:8c63e4f3edab
- Child:
- 11:c6356e5949cd
--- a/main.cpp Tue Feb 22 14:40:11 2011 +0000 +++ b/main.cpp Sun Feb 27 13:39:45 2011 +0000 @@ -8,8 +8,8 @@ * @brief mbed Weather Platform */ -#define VERSION "mbed Weather Platform 0.1.4 (C) 2011 Suga koubou Co.,Ltd." -//#define USE_I2CLEDDISP // I2C LED Display +#define VERSION "mbed Weather Platform 0.2.0 (C) 2011 Suga koubou Co.,Ltd." + //#define NONBLOCKING // ethernet function non-bloking #include "mbed.h" @@ -23,10 +23,8 @@ #include "HTTPClient.h" #include "Agentbed.h" #include "conf.h" - -#ifdef USE_I2CLEDDISP #include "I2CLEDDisp.h" -#endif +#include "I2CLCD.h" Serial pc(USBTX, USBRX), xbee(p13, p14); int seq = 0; @@ -45,14 +43,12 @@ AnalogIn ailight(p16), aimoist(p18), aiuv(p17); DigitalOut swout1(p29), swout2(p30); +I2CLEDDisp *leddisp; +I2CLCD *lcd; +int ledpos, ledflg; +char ledbuf[200]; Ticker ticker; -#ifdef USE_I2CLEDDISP -I2CLEDDisp leddisp(i2c); -int ledpos, ledflg; -char ledbuf[100]; -#endif - // Ethernet EthernetNetIf *eth; NTPClient *ntp; @@ -65,6 +61,7 @@ void writefile (char *); void pachube (char *); +char *fmtstr (char *, char *, int); void twitter (); void weatherstations (); void ntpdate (); @@ -97,24 +94,25 @@ } void ledscroll () { -#ifdef USE_I2CLEDDISP - 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(' '); + if (conf.leddisp_mesg[0]) { + 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; } } - ledpos ++; - if (ledpos >= len + 4) { - ledpos = -4; - } -#endif locUpTime = locUpTime + 40; // 0.4s led_y = 1; @@ -254,35 +252,33 @@ swout1 = 0; swout2 = 0; led1 = 1; -#ifdef USE_I2CLEDDISP + ledpos = -4; ledflg = 0; - ledpos = -4; strcpy(ledbuf, VERSION); -#endif ticker.attach(&ledscroll, 0.4); init(); - pc.printf(VERSION "\r\n\r\n"); + pc.printf("%s\r\n\r\n", VERSION); if (conf.filetype) { strcpy(buf, "date,pres(hPa),temp(`C),humi(%%),anemo(m/s),vane(`),rain(mm),light(lx),uv(mW/cm2),moist(kohm),\r\n"); 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"); + if (conf.leddisp_mesg[0]) { + 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 @@ -326,14 +322,19 @@ action(&buf[20]); -#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); + if (conf.leddisp_mesg[0]) { + if (ledflg) { + ledpos = -4; + fmtstr(conf.leddisp_mesg, ledbuf, sizeof(ledbuf)); + } + ledflg = 1; } - ledflg = 1; -#endif + if (conf.lcd_mesg[0]) { + fmtstr(conf.lcd_mesg, buf, sizeof(buf)); + lcd->cls(); + lcd->puts(buf); + } + led1 = 1; while (timer.read() < conf.interval) {