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:
0:bdb53686c194
Child:
1:6c7141895545
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ilip.cpp	Mon Jul 04 15:16:45 2011 +0000
@@ -0,0 +1,189 @@
+/** @file
+ * @brief mbed Weather Platform
+ */
+#include "mbed.h"
+#include "weather.h"
+#ifdef USE_IL
+#include "ILinterpreter.h"
+
+static ILinterpreter ilip;
+#endif
+static Serial xbee(p13, p14);
+static volatile int measure_flg = 0;
+
+#ifdef USE_IL
+// input relay
+float cb_input(char key, int keynum, eEXPRESSION exp, int old) {
+    float value = 0;
+    Sensor *s;
+
+    if (old) {
+        s = &sensor_old;
+    } else {
+        s = &sensor;
+    }
+
+    switch (key) {
+    case 'A': // sensor
+        switch (keynum) {
+        case 0:
+            value = s->pres;
+            break;
+        case 1:
+            value = s->temp;
+            break;
+        case 2:
+            value = s->humi;
+            break;
+        case 3:
+            value = s->anemo;
+            break;
+        case 4:
+            value = s->vane;
+            break;
+        case 5:
+            value = s->rain;
+            break;
+        case 6:
+            value = s->light;
+            break;
+        case 7:
+            value = s->uv;
+            break;
+        case 8:
+            value = s->moist;
+            break;
+        case 99:
+            value = measure_flg;
+            break;
+        }
+        break;
+        
+    case 'I': // input
+        if (keynum >= INPUT_NUM) break;
+        value = s->input[keynum];
+        break;
+
+    case 'Q': // output
+        if (keynum >= OUTPUT_NUM) break;
+        value = s->output[keynum];
+        break;
+    }
+
+    return value;
+}
+
+// output relay
+void cb_output(char key, int keynum, int reg, eMNEMONIC mne) {
+
+#ifdef DEBUG
+    pc.printf("OUT [%c %d] %d %d\r\n", key, keynum, reg, mne);
+#endif
+    pool_net();
+
+    switch (key) {
+    case 'Q': // output
+        if (keynum >= OUTPUT_NUM) break;
+        if (mne == MNE_OUT) {
+            sensor.output[keynum] = reg;
+        } else
+        if (mne == MNE_SET && reg) {
+            sensor.output[keynum] = 1;
+        } else
+        if (mne == MNE_RST && reg) {
+            sensor.output[keynum] = 0;
+        }
+        break;
+
+    case 'P': // Pachube
+        if (mne == MNE_OUT && reg) {
+            pachube(csv);
+        }
+        break;
+
+    case 'S': // Weather Stations
+        if (mne == MNE_OUT && reg) {
+            weatherstations();
+        }
+        break;
+
+    case 'W': // Twitter
+        if (mne == MNE_OUT && reg) {
+            twitter(keynum);
+        }
+        break;
+
+    case 'X': // XBee
+        if (mne == MNE_OUT && reg) {
+            xbee.printf(csv);
+        }
+        break;
+
+    case 'E': // E-mail
+        if (mne == MNE_OUT && reg) {
+            email(keynum);
+        }
+        break;
+    }
+
+    pool_net();
+}
+#endif
+
+void pool_ilip () {
+#ifdef USE_IL
+    ilip.pool();
+#endif
+}
+
+// execute IL
+void exec_ilip (int enable) {
+    Sensor sensor_tmp;
+
+    measure_flg = enable;
+
+    // set input
+//    sensor.input[0] = conf.inputtype ? *aimoist > 0.5 : 0;
+//    sensor.input[1] = swin2;
+
+    sensor_tmp = sensor;
+
+#ifdef USE_IL
+    // every time
+    if (ilip.exec()) {
+        printf("IL: out of stack\r\n");
+    }
+#else
+    if (enable) {
+        weatherstations();
+        pachube(csv);
+        email(0);
+    }
+#endif
+
+    // set output
+//    led3 = swout1 = sensor.output[0];
+//    led4 = swout2 = sensor.output[1];
+
+    sensor_old = sensor_tmp;
+}
+
+// init IL
+int init_ilip (char *dir) {
+    char buf[40];
+
+    if (cfg.getValue("XBEE", buf, sizeof(buf))) {
+        xbee.baud(atoi(chop(buf)));
+    }
+
+#ifdef USE_IL
+    strcpy(buf, dir);
+    strcat(buf, IL_FILE);
+    if (! ilip.load(buf)) {
+        pc.printf("IL load %s\r\n", buf);
+        ilip.attach(cb_input, cb_output);
+    }
+#endif
+
+    return 0;
+}