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:
4:46ad190e6328
--- a/sensor.cpp	Sun Jul 10 15:36:46 2011 +0000
+++ b/sensor.cpp	Wed Aug 24 13:22:32 2011 +0000
@@ -16,7 +16,7 @@
 
 #define AREF 3.3 // V
 
-Sensor sensor, offset, sensor_old;
+struct Sensor sensor, offset, sensor_old;
 I2C i2c(p9, p10);
 static BMP085 bmp085(i2c, BMP085_oss4);
 static SHT sht15(p12, p11, SHT_high); // sclock, data
@@ -26,7 +26,6 @@
 static InterruptIn *intin;
 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;
@@ -96,20 +95,19 @@
     sensor.light = get_light(ailight);
     sensor.uv = get_uv(aiuv);
 
-    if (inputtype == INPUT_MOIST) {
+    if (conf.inputtype == INPUT_MOIST) {
         // moist sensor
         sensor.moist = get_moist(*aimoist);
     } else
-    if (inputtype == INPUT_MOIST) {
+    if (conf.inputtype == INPUT_MOIST) {
         // counter
-        sensor.moist = get_counter(inputtype & INPUT_CPM ? 0 : 1);
+        sensor.moist = get_counter(conf.inputtype & INPUT_CPM ? 0 : 1);
     }
 
     return 0;
 }
 
 int init_sensor () {
-    char buf[20];
 
     memset(&sensor, 0, sizeof(sensor));
     sensor.sec = time(NULL);
@@ -117,31 +115,19 @@
     offset = sensor;
 
     // moist sensor or counter
-    if (cfg.getValue("INPUT", buf, sizeof(buf))) {
-        // counter
-        inputtype = (eINPUTTYPE)atoi(buf);
-        if (inputtype & (INPUT_FALL|INPUT_RISE)) {
-            intin->fall(&isr_counter);
-            if (inputtype & INPUT_FALL) {
-                intin = new InterruptIn(p18);
-            }
-            if (inputtype & INPUT_RISE) {
-                intin = new InterruptIn(p18);
-            }
-        }
-    } else {
+    if (conf.inputtype == INPUT_MOIST) {
         // moist
         aimoist = new AnalogIn(p18);
-    }
-
-    if (cfg.getValue("OFFSET[P]", buf, sizeof(buf))) {
-        offset.pres = atof(buf);
-    }
-    if (cfg.getValue("OFFSET[T]", buf, sizeof(buf))) {
-        offset.temp = atof(buf);
-    }
-    if (cfg.getValue("OFFSET[H]", buf, sizeof(buf))) {
-        offset.humi = atof(buf);
+    } else
+    if (conf.inputtype & (INPUT_FALL|INPUT_RISE)) {
+        // counter
+        intin->fall(&isr_counter);
+        if (conf.inputtype & INPUT_FALL) {
+            intin = new InterruptIn(p18);
+        }
+        if (conf.inputtype & INPUT_RISE) {
+            intin = new InterruptIn(p18);
+        }
     }
 
     return 0;
@@ -271,16 +257,16 @@
 
             switch (flg) {
             case 1:
-                sprintf(&buf[j], "%.1f", value);
+                snprintf(&buf[j], len - j, "%.1f", value);
                 break;
             case 2:
-                sprintf(&buf[j], "%.2f", value);
+                snprintf(&buf[j], len - j, "%.2f", value);
                 break;
             case -1:
-                sprintf(&buf[j], "%02d", (int)value);
+                snprintf(&buf[j], len - j, "%02d", (int)value);
                 break;
             default:
-                sprintf(&buf[j], "%d", (int)value);
+                snprintf(&buf[j], len - j, "%d", (int)value);
                 break;
             }
             j = strlen(buf);