4180 weather balloon logging and cutdown system

Dependencies:   GPS MPL3115A2 SDFileSystem mbed-rtos mbed

Fork of WeatherBalloon4180 by Chad Miller

Files at this revision

API Documentation at this revision

Comitter:
cmiller86
Date:
Tue Nov 17 06:59:00 2015 +0000
Parent:
1:2c4f640a8104
Child:
3:b490294520d5
Commit message:
Refactored and added SD logging

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Tue Nov 17 06:59:00 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
--- a/main.cpp	Mon Nov 16 22:10:27 2015 +0000
+++ b/main.cpp	Tue Nov 17 06:59:00 2015 +0000
@@ -1,59 +1,94 @@
 #include "mbed.h"
+#include "rtos.h"
+
 #include "GPS.h"
+#include "SDFileSystem.h"
 
 Serial pc(USBTX, USBRX);
+SDFileSystem sd(p5, p6, p7, p8, "sd");
 GPS gps(p9, p10);
+
+AnalogIn temp1(p18);
+AnalogIn temp2(p19);
+AnalogIn temp3(p20);
+
+DigitalIn dtmf(p11);
+
 DigitalOut led1(LED1);
-Timer T;
-bool cutdown=0;
 DigitalOut relay(p8);
-bool attempted=0;
-DigitalIn DTMF(p11);
-AnalogIn Temp1(p18);
-AnalogIn Temp2(p19);
-AnalogIn Temp3(p20);
+
+Timer t;
+
+bool attempted = false;
+bool cutdown = false;
+
+FILE *sdout;
 
-int main() {
-    T.start();
-    relay=0;
+void init()
+{
+    t.start();
+    relay = 0;
+    
+    mkdir("/sd/weather_balloon", 0777);
+    sdout = fopen("/sd/weather_balloon/log.txt", "w");
+}
+
+int main()
+{
     float tempC1, tempF1, tempC2, tempF2, tempC3, tempF3;
-    while(1) {
+    
+    while(1)
+    {
+        pc.printf("----- %f -----\n\r", t.read());
+        fprintf(sdout, "----- %f -----\n\r", t.read());
         
-        pc.printf("----- %f -----\n\r",T.read());
-            if(T.read()>= 20){
-                cutdown=1;
-                }
+        if(t.read() >= 20)
+            cutdown = true;
                 
         gps.sample();
+        
         pc.printf("Long = %f\n\rLati = %f\n\r", gps.longitude, gps.latitude);
-        if(gps.longitude != 0){
-                led1=1;
-        }
+        fprintf(sdout, "Long = %f\n\rLati = %f\n\r", gps.longitude, gps.latitude);
+        
+        if(!gps.longitude)
+            led1 = 1;
         
-        tempC1 = ((Temp1*3.3)-0.600)*100.0;
-        tempC2 = ((Temp2*3.3)-0.600)*100.0;
-        tempC3 = ((Temp3*3.3)-0.600)*100.0;
-        tempF1 = (9.0*tempC1)/5.0 + 32;
-        tempF2 = (9.0*tempC2)/5.0 + 32;
-        tempF3 = (9.0*tempC3)/5.0 + 32;
-        pc.printf("Temp1 = %f\n\rTemp2 = %f\n\rTemp3 = %f\n\r",tempF1, tempF2, tempF3);
+        tempC1 = ((temp1 * 3.3) - 0.600) * 100.0;
+        tempC2 = ((temp2 * 3.3) - 0.600) * 100.0;
+        tempC3 = ((temp3 * 3.3) - 0.600) * 100.0;
+        tempF1 = (9.0 * tempC1) / 5.0 + 32;
+        tempF2 = (9.0 * tempC2) / 5.0 + 32;
+        tempF3 = (9.0 * tempC3) / 5.0 + 32;
         
-        if (DTMF){
+        pc.printf("Temp1 = %f\n\rTemp2 = %f\n\rTemp3 = %f\n\r", tempF1, tempF2, tempF3);
+        fprintf(sdout, "Temp1 = %f\n\rTemp2 = %f\n\rTemp3 = %f\n\r", tempF1, tempF2, tempF3);
+        
+        if(dtmf)
+        {
             pc.printf("DTMF = True\n\r");
-            cutdown=1;
-            } else {
-                pc.printf("DTMF = False\n\r");
-                }
+            fprintf(sdout, "DTMF = True\n\r");
+            
+            cutdown = true;
+        }
+        else
+        {
+            pc.printf("DTMF = False\n\r");
+            fprintf(sdout, "DTMF = False\n\r");
+        }
 
-if (cutdown==1 && attempted != 1){
-        pc.printf("Cutdown Started = %f\n\r",T.read());
-        relay=1;
-        wait(20);
-        relay=0;
-        pc.printf("Cutdown Ended = %f\n\r",T.read());
-        attempted=1;
-        }
-        
+        if(cutdown && !attempted)
+        {
+            pc.printf("Cutdown Started = %f\n\r", t.read());
+            fprintf(sdout, "Cutdown Started = %f\n\r", t.read());
+            
+            relay = 1;
+            wait(20);
+            relay = 0;
+            
+            pc.printf("Cutdown Ended = %f\n\r", t.read());
+            fprintf(sdout, "Cutdown Ended = %f\n\r", t.read());
+            
+            attempted = true;
         }
     }
-
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Nov 17 06:59:00 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#6d90423c236e
--- a/mbed.bld	Mon Nov 16 22:10:27 2015 +0000
+++ b/mbed.bld	Tue Nov 17 06:59:00 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/029aa53d7323
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file