Dependencies:   ChaNFSSD mbed BMP085 SHT2x

Revision:
2:f546aaa0e1d5
Parent:
1:83960ee4d9a2
Child:
3:844fbe607dae
--- a/main.cpp	Fri Jan 13 10:15:08 2012 +0000
+++ b/main.cpp	Mon Jan 23 15:04:58 2012 +0000
@@ -8,7 +8,6 @@
 #include "SDFileSystem.h"
 #include "libT/mbed/tserialbuffer.h"
 #include "BMP085.h"
-#include "SHT25.h"
 #include "SHT2x.h"
 #include "AD7994.h"
 //#include "TextLCD.h"
@@ -17,7 +16,7 @@
 
 using namespace libT;
 
-#define _CO2_TEST
+//#define _CO2_TEST
 //#define _I2C_TEST
 
 #define _USE_FS_NAME "sd"
@@ -34,7 +33,7 @@
 #endif  /* } */
 BMP085 bmp085(p9, p10);
 //SHT25 sht25(p9, p10);
-//SHT2x sht25(p9,p10);
+SHT2x sht25(p9,p10);
 AD7994 ad7994(p9,p10);
 TextLCD_20X4 lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
 
@@ -42,9 +41,7 @@
 
 DigitalOut myled(LED1);
 
-#ifdef  _CO2_TEST
 tSerialBuffer CO2(p13,p14);
-#endif
 
 struct UBXPacket_s UBXPacket;
 
@@ -84,7 +81,6 @@
     fclose(fp);
 }
 
-#ifdef  _CO2_TEST    /* { */
 int CO2_Read(unsigned short *val)
 {
     unsigned char sbuf[] = { 0xFE, 0x04, 0x00, 0x03, 0x00, 0x01, 0xD5, 0xC5 };
@@ -119,7 +115,6 @@
     *val = (*val << 8) | rbuf[4];
     return 0;
 }
-#endif  /* HAVE_CO2 } */
 
 // BMP085 0xee
 // AD9774 0x44
@@ -182,35 +177,39 @@
 }
 
 unsigned char wbuf[1024];
-int widx;
+int widx = 0;
 
 int main() {
     int ret = 0;
     float p, t;
     int temp;
-    int userRegister;
     unsigned short CO2_val;
     unsigned long scanCount = 0;
     FILE *fp;
     char *logname = "/" _USE_FS_NAME "/ENVLOG.TXT";
     char c;
+    unsigned long UBXCount = 0;
  
     debug.format(8,Serial::None,1);
     debug.baud(115200);
-    debug.printf("ENV Logger \"V1\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\n");
+    debug.printf("ENV Logger \"V0.5\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\n");
 
     debug.printf("LCD Display\n");
 
     //lcd.cls();
     lcd.locate(0,0);
-    lcd.printf("ENV Logger \"V1\"");
-#ifdef  _CO2_TEST
+    lcd.printf("ENV Logger \"V0.5\"");
+
+    lcd.locate(0,1);
+    lcd.printf("WAKE UP I/O...");
     wait(5.0);
-#endif
  
     //logFile_Init();
     //FileWriteTest();
 
+    lcd.locate(0,1);
+    lcd.printf("SETTING GPS...");
+
     UBXPacket.cjobst = 0;
 
     gps_pps.rise(gps_pps_rise);
@@ -221,7 +220,6 @@
     wait(0.5);
     gps_reset = 0;
 
-#if 0
     wait(0.5);
     if(1){
         //unsigned char modeStr[] = "PUBX,41,1,0007,0003,115200,0";
@@ -259,7 +257,8 @@
        }
     }
     UBXPacket.cjobst = 0;
-#endif
+    lcd.locate(0,1);
+    lcd.printf("SETTING GPS...Done.");
 
 #if 0
     debug.printf("open(%s) :", logname);
@@ -273,86 +272,67 @@
 
 //  ad7994.Start();
 
-#ifdef  _CO2_TEST
     CO2.format(8,Serial::None,1);
     CO2.baud(9600);
     CO2.recvStart();
-#endif
-
-    //sht25.SHT2x_SoftReset();
-    //sht25.SHT2x_ReadUserRegister(&userRegister);  //get actual user reg
-    //userRegister = (userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_12_14BIT;
-    //sht25.SHT2x_WriteUserRegister(&userRegister); //write changed user reg    
 
     while(1) {
         //lcd.cls();
-        lcd.locate(0,1);
-        lcd.printf("SCAN: %-10ld",scanCount);
+        //lcd.locate(0,0);
+        //lcd.printf("SCAN:%-10ld",scanCount);
 
-#if 0
         while(gps.readable()) {
             c = gps.getc();
             if(UBXPacket_Parse(&UBXPacket,c) == 100){
+                UBXCount++;
+                lcd.locate(0,0);
+                lcd.printf("UBX Recv:%-10ld",UBXCount);
                 debug.printf("%ld : GET UBX Packet (Class=0x%02X,ID=0x%02X,LEN=%d)\n",
                             scanCount,
                             UBXPacket.cls,
                             UBXPacket.id,
                             UBXPacket.len );
                 UBXPacket.cjobst = 0;
-                if(scanCount > 120){
-                    if(widx >= 0){
-                        fwrite(&wbuf,sizeof(wbuf[0]),widx,fp);
-                        widx = 0;
-                    }
-                    fclose(fp);
-                }
             }
-            if(fp != NULL){
-                wbuf[widx] = c;
-                widx++;
-                if(widx >= sizeof(wbuf)){
-                    fwrite(&wbuf,sizeof(wbuf[0]),widx,fp);
-                    widx = 0;
-                }
-            }
+            //if(fp != NULL){
+            //    wbuf[widx] = c;
+            //    widx++;
+            //    if(widx >= sizeof(wbuf)){
+            //        fwrite(&wbuf,sizeof(wbuf[0]),widx,fp);
+            //        widx = 0;
+            //    }
+            //}
         }
-#endif
 
-#if 0
-        bmp085.update();
-        p = bmp085.get_pressure();
-        t = bmp085.get_temperature();
-        lcd.locate(0,2);
-        lcd.printf("%-7.2fhPa %-7.2fC\n", p, t);
-#endif
+        if(1){
+            bmp085.update();
+            p = bmp085.get_pressure();
+            t = bmp085.get_temperature();
+            lcd.locate(0,1);
+            lcd.printf("%-8.2fhPa %-6.2fC", p, t);
+        }
 
-#if 0
-        sht25.SHT2x_MeasurePoll(TEMP,&temp);
-        p = sht25.SHT2x_CalcTemperatureC(temp);
-        sht25.SHT2x_MeasurePoll(HUMIDITY,&temp);
-        t = sht25.SHT2x_CalcRH(temp);
-        debug.printf("SHT25 = p:%6.2f C / t:%6.2f RH\n", p, t);
-        sht25.SHT2x_SoftReset();
-#endif
-
-#if 0
-        sht25.SoftReset();
-        printf("SHT25 = %f\n",sht25.get_temperature());
-#endif
+        if(1){
+            sht25.SHT2x_MeasurePoll(TEMP,&temp);
+            p = sht25.SHT2x_CalcTemperatureC(temp);
+            sht25.SHT2x_MeasurePoll(HUMIDITY,&temp);
+            t = sht25.SHT2x_CalcRH(temp);
+            lcd.locate(0,2);
+            lcd.printf("%-6.2fC %-6.2fRH", p, t);
+            //sht25.SHT2x_SoftReset();
+        }
 
 #ifdef _I2C_TEST /* { */
         i2c_found();
 #endif  /* } */
 
-#ifdef  _CO2_TEST
-        lcd.locate(0,2);
+        lcd.locate(0,3);
         ret = CO2_Read(&CO2_val);
         if(ret == 0){
-            lcd.printf("CO2:%5dppm\n",CO2_val);
+            lcd.printf("CO2:%5d.%1dppm\n",CO2_val/10,CO2_val%10);
         } else {
             lcd.printf("CO2:NG(%d)  \n",ret);
         }
-#endif
 
 #if 0
         ad7994.update();
@@ -370,3 +350,10 @@
         scanCount++;
     }
 }
+
+/*
+ * 2012-1-23 V0.5
+ * U-Blox,気圧センサー,温度センサー,CO2センサーの値を表示するようにした。
+ * U-Blox は受信できたパケット数を表示する。
+ * マイクロSDへの保存機能はまだ(H/W的に動くのは確認済み)
+ */