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:
1:6c7141895545
Parent:
0:bdb53686c194
Child:
2:a3e5edf84f74
--- a/sensor.cpp	Mon Jul 04 15:16:45 2011 +0000
+++ b/sensor.cpp	Sun Jul 10 15:36:46 2011 +0000
@@ -1,3 +1,13 @@
+/*
+ * Weather Station - mbed Weather Platform
+ * Copyright (c) 2011 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+/** @file
+ * @brief Weather Station
+ */
+
 #include "mbed.h"
 #include "weather.h"
 #include "BMP085.h"
@@ -14,9 +24,9 @@
 static AnalogIn ailight(p16), aiuv(p17);
 static AnalogIn *aimoist;
 static InterruptIn *intin;
-static volatile int count_counter;
-static volatile unsigned long lastCountTime;
-static volatile int inputtype;
+static volatile int count_counter = 0;
+static volatile unsigned long lastCountTime = 0;
+static volatile enum eINPUTTYPE inputtype = INPUT_MOIST;
 
 float get_light (AnalogIn &ain) {
     float f;
@@ -86,12 +96,13 @@
     sensor.light = get_light(ailight);
     sensor.uv = get_uv(aiuv);
 
-    if (inputtype) {
+    if (inputtype == INPUT_MOIST) {
+        // moist sensor
+        sensor.moist = get_moist(*aimoist);
+    } else
+    if (inputtype == INPUT_MOIST) {
         // counter
         sensor.moist = get_counter(inputtype & INPUT_CPM ? 0 : 1);
-    } else {
-        // moist sensor
-        sensor.moist = get_moist(*aimoist);
     }
 
     return 0;
@@ -108,13 +119,15 @@
     // moist sensor or counter
     if (cfg.getValue("INPUT", buf, sizeof(buf))) {
         // counter
-        inputtype = atoi(buf);
-        intin = new InterruptIn(p18);
-        if (inputtype & INPUT_FALL) {
+        inputtype = (eINPUTTYPE)atoi(buf);
+        if (inputtype & (INPUT_FALL|INPUT_RISE)) {
             intin->fall(&isr_counter);
-        }
-        if (inputtype & INPUT_RISE) {
-            intin->rise(&isr_counter);
+            if (inputtype & INPUT_FALL) {
+                intin = new InterruptIn(p18);
+            }
+            if (inputtype & INPUT_RISE) {
+                intin = new InterruptIn(p18);
+            }
         }
     } else {
         // moist
@@ -155,6 +168,7 @@
                     flg = fmt[i + 1] - '0';
                     i ++;
 
+                    // next char
                     c = fmt[i + 1];
                     i ++;
                 }
@@ -189,7 +203,7 @@
                 value = sensor.moist;
                 break;
             case 'p':
-                value = sensor.temp;
+                value = sensor.temp2;
                 break;
 
             case 'y':
@@ -241,6 +255,14 @@
                 j ++;
                 continue;
 
+            case 'n':
+                buf[j] = '\n';
+                j ++;
+                continue;
+            case 'r':
+                buf[j] = '\r';
+                j ++;
+                continue;
             default:
                 buf[j] = c;
                 j ++;