most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Revision:
36:966a86937e17
Parent:
35:2f66ea4863d5
Child:
37:357e98a929cc
diff -r 2f66ea4863d5 -r 966a86937e17 main.cpp
--- a/main.cpp	Wed Dec 20 22:44:02 2017 +0000
+++ b/main.cpp	Wed Dec 20 23:21:15 2017 +0000
@@ -151,7 +151,7 @@
     log_loop_rate_ticker.attach(&log_loop_trigger, 1.0); // fires the ticker at 1 Hz rate (every second)
 
     //create the MBED log file (current log file)
-    mbedLogger().openFile();
+    //mbedLogger().openFile();
 } 
  
 int main() {
@@ -159,6 +159,9 @@
     
     while(1) {
         static int current_state = 0;
+        
+        static bool file_opened = false;
+        
         // runs at 10 hz
         if(loop) {
             led1() = !led1(); // blink led 1
@@ -173,9 +176,37 @@
         if (log_loop) {
             led3() = !led3(); // blink led 3
             
+            //pc().printf("led 3 blinking once a second?\n\r"); //confirmed
+            
             //when the state machine is not in SIT_IDLE state
             if(current_state != 0) {
-                OpenLog().recordData(current_state);   //start recording   
+                //pc().printf("\n\rDEBUG: trying to record data \n\r");    
+
+               //if file is not open, open it
+                if (!file_opened) { 
+                    mbedLogger().openFile();    //open MBED file once                    
+                    file_opened = true;         //stops it from continuing to open it
+                    
+                    pc().printf(">>>>>>>> Recording. Log file opened. <<<<<<<<\n\r");
+                }
+                
+                //record to OpenLog hardware
+               OpenLog().recordData(current_state);   //start recording   
+                
+                //record to Mbed
+                //mbedLogger().saveDataToFile(string_state,current_state,stateMachine().dataArray());
+                mbedLogger().saveDataToFile(current_state,stateMachine().dataArray());                
+            }
+            
+            //when the current state is zero, reset the file
+            else {
+                //this can only happen once
+                if (file_opened) {
+                    mbedLogger().closeFile();
+                    file_opened = false;
+                }
+                //else
+//                    file_opened = false;
             }
             
             log_loop = false;   // wait until the loop rate timer fires again