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:
7:f7c98d836f81
Parent:
6:898c306f7990
--- a/file.cpp	Sun Jan 15 13:28:12 2012 +0000
+++ b/file.cpp	Thu Mar 15 02:42:39 2012 +0000
@@ -16,6 +16,7 @@
 #endif
 #include "ConfigFile.h"
 
+extern struct Sensor offset;
 static SDFileSystem sd(p5, p6, p7, p8, "sd");
 static LocalFileSystem *local;
 #ifdef USE_USB
@@ -25,6 +26,45 @@
 struct Config conf;
 static char filename[30] = "";
 
+// date time from filesystem
+int fstime (char *d, time_t *tim) {
+    DIR_t dir;
+    FILINFO fno;
+#if _USE_LFN
+    static char lfn[_MAX_LFN + 1];
+    fno.lfname = lfn;
+    fno.lfsize = sizeof(lfn);
+#endif
+    DWORD fattime = 0, ft;
+    struct tm t;
+
+    if (f_opendir(&dir, "") == FR_OK) {
+        for (;;) {
+            if (f_readdir(&dir, &fno) != FR_OK) break;
+            if (fno.fname[0] == 0) break;
+            if (fno.fdate != 0) {
+            printf("%s %d\r\n", fno.fname, fno.fdate);
+                ft = (fno.fdate << 16) | fno.ftime;
+                if (ft > fattime) {
+                    fattime = ft;
+                }
+            }
+        }
+        if (fattime) {
+            t.tm_year = ((fattime >> 25) & 0x7f) + 80;
+            t.tm_mon = ((fattime >> 21) & 0x0f) - 1; 
+            t.tm_mday = (fattime >> 16) & 0x1f;
+            t.tm_hour = (fattime >> 11) & 0x1f;
+            t.tm_min = (fattime >> 5) & 0x3f;
+            t.tm_sec = (fattime << 1) & 0x3e;
+            *tim = mktime(&t);
+            return 0;
+        }
+    }
+    return -1;
+}
+
+// write CSV file
 int write_log (const char *buf) {
     FILE *fp;
 
@@ -47,7 +87,7 @@
     return 0;
 }
 
-int init_file () {
+int init_log () {
     int seq = 0;
     char dir[8];
     FILE *fp;
@@ -242,6 +282,7 @@
         conf.inputtype = (enum eINPUTTYPE)atoi(buf);
     }
 
+    memset(&offset, 0, sizeof(offset));
     if (cfg.getValue("OFFSET[P]", buf, sizeof_1(buf))) {
         offset.pres = atof(buf);
     }