Revision 0:e9a647f18c71, committed 2010-11-04
- Comitter:
- shintamainjp
- Date:
- Thu Nov 04 14:33:43 2010 +0000
- Commit message:
- Initial version.
Changed in this revision
diff -r 000000000000 -r e9a647f18c71 extlib/EthernetNetIf.lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/extlib/EthernetNetIf.lib Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r e9a647f18c71 extlib/HTTPClient.lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/extlib/HTTPClient.lib Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#d0be6af2d1db
diff -r 000000000000 -r e9a647f18c71 extlib/TextLCD.lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/extlib/TextLCD.lib Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#a53b3e2d6f1e
diff -r 000000000000 -r e9a647f18c71 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,188 @@
+/**
+ * =============================================================================
+ * Expansion Board One - Example application No.2 (Version 0.0.1)
+ * http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex2_en/
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#include "mbed.h"
+#include "PachubeV2CSV.h"
+#include "EthernetNetIf.h"
+#include "HTTPClient.h"
+#include "ThermistorMCP9701.h"
+#include "TextLCD.h"
+#include "appconf.h"
+
+/*
+ * Definitions for a configuration file.
+ */
+#define CONFIG_FILENAME "/local/SBOE2.CFG"
+
+LocalFileSystem localfs("local");
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+EthernetNetIf netif;
+BusOut led(LED1, LED2, LED3, LED4);
+ThermistorMCP9701 thermistor1(p16);
+ThermistorMCP9701 thermistor2(p17);
+ThermistorMCP9701 thermistor3(p18);
+ThermistorMCP9701 thermistor4(p19);
+ThermistorMCP9701 thermistor5(p20);
+static appconf_t appconf;
+
+/**
+ * Display a splash screen.
+ */
+void splash(void) {
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("StarBoard Orange");
+ lcd.locate(0, 1);
+ lcd.printf("Expansion Board ");
+ wait(2);
+
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("Example app No.2");
+ lcd.locate(0, 1);
+ lcd.printf(" ");
+ wait(2);
+}
+
+/**
+ * Convert double to char.
+ *
+ * @param val Value.
+ * @param buf A pointer to a buffer.
+ * @param bufsiz The buffer size.
+ */
+void convertDoubleToChar(double val, char *buf, size_t bufsiz) {
+ snprintf(buf, bufsiz, "%f", val);
+}
+
+/**
+ * Entry point.
+ */
+int main() {
+
+ /*
+ * Splash.
+ */
+ splash();
+
+ /*
+ * Initialize ethernet interface.
+ */
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("Initializing. ");
+ lcd.locate(0, 1);
+ lcd.printf("Ethernet: ");
+ EthernetErr ethErr = netif.setup();
+ if (ethErr) {
+ lcd.locate(0, 1);
+ lcd.printf("Ethernet:NG ");
+ error("Network setup failed.\n");
+ } else {
+ lcd.locate(0, 1);
+ lcd.printf("Ethernet:OK ");
+ }
+ wait(2);
+
+ /*
+ * Read configuration variables from a file.
+ */
+ appconf_init(&appconf);
+ if (appconf_read(CONFIG_FILENAME, &appconf) != 0) {
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("ConfigFile");
+ lcd.locate(0, 1);
+ lcd.printf("Read error.");
+ error("Failure to read a configuration file.\n");
+ }
+
+ /*
+ * Check the interval time.
+ */
+ if (appconf.interval < 60) {
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("Invalid interval");
+ error("Inavlid interval time found.\n");
+ }
+
+ /*
+ * Initialize objects.
+ */
+ PachubeV2CSV web(appconf.apikey);
+
+ int cnt = 0;
+ do {
+ /*
+ * Sense.
+ */
+ lcd.cls();
+ int v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0;
+ for (int i = 0; i < appconf.interval; i++) {
+ led = 1 << (i % 4);
+ printf("%d/%d\n", i + 1, appconf.interval);
+ v1 += thermistor1.read();
+ v2 += thermistor2.read();
+ v3 += thermistor3.read();
+ v4 += thermistor4.read();
+ v5 += thermistor5.read();
+ lcd.locate(0, 0);
+ lcd.printf("| 0| 1| 2| 3| 4|");
+ lcd.locate(0, 1);
+ lcd.printf("|%-2.0f|%-2.0f|%-2.0f|%-2.0f|%-2.0f|", thermistor1.read(), thermistor2.read(), thermistor3.read(), thermistor4.read(), thermistor5.read());
+ wait(1);
+ }
+ v1 /= appconf.interval;
+ v2 /= appconf.interval;
+ v3 /= appconf.interval;
+ v4 /= appconf.interval;
+ v5 /= appconf.interval;
+
+ /*
+ * Post.
+ */
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("Posting No.%d", ++cnt);
+ char val1[16];
+ char val2[16];
+ char val3[16];
+ char val4[16];
+ char val5[16];
+ convertDoubleToChar(v1, val1, sizeof(val1));
+ convertDoubleToChar(v2, val2, sizeof(val2));
+ convertDoubleToChar(v3, val3, sizeof(val3));
+ convertDoubleToChar(v4, val4, sizeof(val4));
+ convertDoubleToChar(v5, val5, sizeof(val5));
+ printf("updateDataStream(%d)\n", web.updateDataStream(atoi(appconf.feedid), "0", std::string(val1)));
+ printf("updateDataStream(%d)\n", web.updateDataStream(atoi(appconf.feedid), "1", std::string(val2)));
+ printf("updateDataStream(%d)\n", web.updateDataStream(atoi(appconf.feedid), "2", std::string(val3)));
+ printf("updateDataStream(%d)\n", web.updateDataStream(atoi(appconf.feedid), "3", std::string(val4)));
+ printf("updateDataStream(%d)\n", web.updateDataStream(atoi(appconf.feedid), "4", std::string(val5)));
+ } while (1);
+}
diff -r 000000000000 -r e9a647f18c71 mbed.bld
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
diff -r 000000000000 -r e9a647f18c71 mylib/ConfigFile.lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/ConfigFile.lib Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/ConfigFile/#f6ceafabe9f8
diff -r 000000000000 -r e9a647f18c71 mylib/Pachube.lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/Pachube.lib Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/Pachube/#19accbe9a05e
diff -r 000000000000 -r e9a647f18c71 mylib/ThermistorPack.lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/ThermistorPack.lib Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/ThermistorPack/#4f84f03b1703
diff -r 000000000000 -r e9a647f18c71 mylib/appconf/appconf.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/appconf/appconf.cpp Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,99 @@
+/**
+ * =============================================================================
+ * Application configuration for 'Expansion Board One' example no.2
+ * http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex2_en/
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#include "appconf.h"
+#include "ConfigFile.h"
+
+#define KEY_PACHUBE_APIKEY "PACHUBE_APIKEY"
+#define KEY_PACHUBE_FEEDID "PACHUBE_FEEDID"
+#define KEY_PACHUBE_INTERVAL "PACHUBE_INTERVAL"
+
+/**
+ * Initialize configuration.
+ *
+ * @param p A pointer to a application config.
+ */
+void appconf_init(appconf_t *p) {
+ memset(p->apikey, 0, sizeof(p->apikey));
+ memset(p->feedid, 0, sizeof(p->feedid));
+ p->interval = 0;
+}
+
+/**
+ * Read configuration.
+ *
+ * @param filename Filename.
+ * @param p A pointer to a application config.
+ * @return Return zero if it succeed.
+ */
+int appconf_read(char *filename, appconf_t *p) {
+ ConfigFile cf;
+ if (!cf.read(filename)) {
+ return -1;
+ }
+ if (!cf.getValue(KEY_PACHUBE_APIKEY, p->apikey, sizeof(p->apikey))) {
+ return -2;
+ }
+ if (!cf.getValue(KEY_PACHUBE_FEEDID, p->feedid, sizeof(p->feedid))) {
+ return -3;
+ }
+ char buf[64];
+ if (!cf.getValue(KEY_PACHUBE_INTERVAL, buf, sizeof(buf))) {
+ return -4;
+ } else {
+ if (sscanf(buf, "%d", &(p->interval)) != 1) {
+ return -5;
+ }
+ }
+ return 0;
+}
+
+/**
+ * Write configuration.
+ *
+ * @param filename Filename.
+ * @param p A pointer to a application config.
+ * @return Return zero if it succeed.
+ */
+int appconf_write(char *filename, appconf_t *p) {
+ ConfigFile cf;
+ if (!cf.setValue(KEY_PACHUBE_APIKEY, p->apikey)) {
+ return -1;
+ }
+ if (!cf.setValue(KEY_PACHUBE_FEEDID, p->feedid)) {
+ return -2;
+ }
+ char buf[64];
+ snprintf(buf, sizeof(buf) - 1, "%d", p->interval);
+ if (!cf.setValue(KEY_PACHUBE_INTERVAL, buf)) {
+ return -3;
+ }
+ if (!cf.write(filename)) {
+ return -4;
+ }
+ return 0;
+}
diff -r 000000000000 -r e9a647f18c71 mylib/appconf/appconf.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/appconf/appconf.h Thu Nov 04 14:33:43 2010 +0000
@@ -0,0 +1,57 @@
+/**
+ * =============================================================================
+ * Application configuration for 'Expansion Board One' example no.2
+ * http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex2_en/
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+typedef struct {
+ char apikey[256];
+ char feedid[128];
+ int interval;
+} appconf_t;
+
+/**
+ * Initialize configuration.
+ *
+ * @param p A pointer to a application config.
+ */
+void appconf_init(appconf_t *p);
+
+/**
+ * Read configuration.
+ *
+ * @param filename Filename.
+ * @param p A pointer to a application config.
+ * @return Return zero if it succeed.
+ */
+int appconf_read(char *filename, appconf_t *p);
+
+/**
+ * Write configuration.
+ *
+ * @param filename Filename.
+ * @param p A pointer to a application config.
+ * @return Return zero if it succeed.
+ */
+int appconf_write(char *filename, appconf_t *p);