Toma de foto y descomprimir en HEX

Dependencies:   JPEGCamera SDFileSystem mbed

Fork of SaibiCansat2014 by Takashi SASAKI

Revision:
12:495d513bb022
Parent:
11:3b13ec465f0f
Child:
13:aa50109c4cae
--- a/main.cpp	Fri Jul 18 09:54:25 2014 +0000
+++ b/main.cpp	Sun Jul 20 12:54:23 2014 +0000
@@ -13,8 +13,10 @@
 Serial pc(USBTX, USBRX);
 Serial xbee(p13, p14);
 
+Timer timer;
+
 AnalogIn ain_CDS(p15);
-AnalogIn ain_Humedity(p16);
+AnalogIn ain_Humidity(p16);
 AnalogIn ain_LM35DZ(p20);
 
 
@@ -37,6 +39,7 @@
 
 
 int main() {
+    timer.start();
     pc.printf("main() started. pc.baud is 9600 at this time.");
     //pc.baud(9600);
     xbee.baud(115200);
@@ -82,19 +85,32 @@
     int loop_count = 0;
     
     while (1) { 
+
         FILE *fp = fopen("/sd/sensor.csv", "a");
         loop_count += 1;
         
+        char buf[100];
+
+        sprintf(buf, "C %d ", loop_count);
+        pc.printf(buf);
+        fwrite(buf, strlen(buf), 1, fp);
+        xbee.printf(buf);
+
+        float seconds = timer.read();
+        sprintf(buf, "S %.3f ", seconds);
+        pc.printf(buf);
+        fwrite(buf, strlen(buf), 1, fp);
+        xbee.printf(buf);
+
         //wait(1.5);
         
         //BOSH BMP085 Barometric pressure,temperature measurement
         accelerometer.getOutput(readings);
         //pc.printf("ADXL345 ------------------------\n");
-        char buf[100];
-        sprintf(buf, "X %+4.2f Y %+4.2f Z %+4.2f ", 
-            (float((int16_t)readings[0]+18)/256), 
-            (float((int16_t)readings[1]-4 )/256), 
-            (float((int16_t)readings[2]+22)/256));
+        sprintf(buf, "X %+4.3f Y %+4.3f Z %+4.3f ", 
+            (float((int16_t)readings[0]+18)/256 - 0.12), 
+            (float((int16_t)readings[1]-4 )/256 - 0.03), 
+            (float((int16_t)readings[2]+22)/256 + 0.12));
         pc.printf(buf);
         fwrite(buf, strlen(buf), 1, fp);
         xbee.printf(buf);
@@ -103,7 +119,9 @@
         
         //ADXL 345 Acceleration measurement
         //pc.printf("\nBOSH BMP085 --------------------\n");
-        sprintf(buf, "P %6.2f T %6.2f ", bmp085.get_pressure(), bmp085.get_temperature());
+        const float P = bmp085.get_pressure();
+        const float T = bmp085.get_temperature();
+        sprintf(buf, "P %6.2f T %6.2f ", P, T);
         pc.printf(buf);
         fwrite(buf, strlen(buf), 1, fp);
         xbee.printf(buf);
@@ -115,13 +133,18 @@
         xbee.printf(buf);
         
         //Humidity measurement P16 analog-in2
-        sprintf(buf, "H %f ",ain_Humedity*100);
+        const float SRH = ( ( ain_Humidity / 5.0 ) - 0.16 ) / 0.0062;
+        const float TRH = SRH / ( 1.0546 - 0.00216 * T);
+        
+        sprintf(buf, "H %f ", TRH / 10.0); // maybe wrong, dirty workaround
+
         pc.printf(buf);
         fwrite(buf, strlen(buf), 1, fp);
         fwrite("\r\n", 2, 1, fp);
         fclose(fp);
-        
+
         xbee.printf(buf);
+        xbee.printf("\n");
         
         //LM35DZ Temperature measurement P20 analog-in6
         //this sensor does not work for now. disabled.
@@ -129,6 +152,8 @@
         
         //take picture
         //main_camera(loop_count);
+        xbee.printf("--JFIF_BOUNDARY\n");
         fast_jpeg_camera.shoot(loop_count);
+        xbee.printf("--JFIF_BOUNDARY--\n");
     }
 }
\ No newline at end of file