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

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

Revision:
2:a3e5edf84f74
Parent:
1:6c7141895545
Child:
5:90f840432195
--- a/main.cpp	Sun Jul 10 15:36:46 2011 +0000
+++ b/main.cpp	Wed Aug 24 13:22:32 2011 +0000
@@ -9,18 +9,25 @@
  */
 
 #include "mbed.h"
+#include <new>
 #include "weather.h"
+#include "EthernetPowerControl.h"
 
 const char VERSION[] = "mbed Weather Platform 0.4.0 (C) 2011 Suga koubou";
 Serial pc(USBTX, USBRX);
-DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
+PwmOut led1(LED1);
+DigitalOut led2(LED2), led3(LED3), led4(LED4);
 #ifdef USE_3LED
 DigitalOut led_red(p28), led_yellow(p23);
 #endif
-static volatile int interval = 60;
-char csv[120];
-static char csv_mesg[120] = "%y-%m-%d %h:%i:%s,%.2P,%.2T,%.2H,%.2A,%.2V,%.2R,%.2L,%.2U,%.2M,%.2p";
+volatile uint32_t locUpTime = 0;
+char csv[FORMAT_STR_SIZE];
+
 
+void no_memory () {
+    printf("panic: can't allocate to memory!\r\n");
+    exit(-1);
+}
 
 // Interrupt 10Hz
 void isr_timer () {
@@ -35,35 +42,31 @@
 }
 
 void init () {
-    char buf[128];
 
     init_conf();
 
-    if (cfg.getValue("DIR", buf, sizeof(buf))) {
-        init_ilip(buf);
-    }
-
-    if (cfg.getValue("BAUD", buf, sizeof(buf))) {
-        pc.baud(atoi(buf));
+    if (conf.baud) {
+        pc.baud(conf.baud);
     }
 
-    if (cfg.getValue("CSV_MESG", csv_mesg, sizeof(csv_mesg))) {
-        chop(csv_mesg);
+    init_ilip(conf.dir);
+    init_file();
+    init_display();
+
+    if (init_net()) {
+        pc.printf("Power down: ethernet\r\n");
+        PHY_PowerDown();
     }
 
-    if (cfg.getValue("INTERVAL", buf, sizeof(buf))) {
-        interval = atoi(buf);
-        pc.printf("Interval: %d sec.\r\n", interval);
-    }
-
-    init_file();
-    init_display();
-    init_net();
+    pc.printf("Interval: %d sec.\r\n", conf.interval);
 }
 
 int main() {
     Timer timer;
     Ticker ticker;
+    int ledlevel = 0, ledflg = 0;
+
+    set_new_handler(no_memory); // new handler function
 
     LED_BUSY_ON;
     init();
@@ -81,7 +84,7 @@
         __enable_irq();
 
         // create CSV
-        format_str(csv_mesg, csv, sizeof(csv));
+        format_str(conf.csv_mesg, csv, sizeof_1(csv));
         pc.printf(csv);
         pc.printf("\r\n");
         write_log(csv);
@@ -98,7 +101,18 @@
         }
 
         // interval (wait)
-        while (timer.read() < interval) {
+        while (timer.read() < conf.interval) {
+            ledlevel = ledlevel + (ledflg ? -5 : 5);
+            if (ledlevel > 100) {
+                ledlevel = 100;
+                ledflg = 1;
+            } else
+            if (ledlevel < 0) {
+                ledlevel = 0;
+                ledflg = 0;
+            }
+            led1 = ledlevel / 100.0;
+            
             pool_net();
             wait_ms(100);