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:
34:9b66c5188051
Parent:
32:f2f8ae34aadc
Child:
35:2f66ea4863d5
--- a/main.cpp	Wed Dec 20 13:52:50 2017 +0000
+++ b/main.cpp	Wed Dec 20 20:24:15 2017 +0000
@@ -65,8 +65,10 @@
     Modified 2017-12-19 revA by Troy
         - Fixed OpenLog printing to include states and variable names.  Currently logs to LOG#####.TXT files
             1) Note: The OpenLog only starts a new log when it is power-cycled (with the MBED)
-    Modified 2017-12-20 rev A by Troy
+    Modified 2017-12-20 revA by Troy
         - Modified code to log every 1 second in current iteration
+    Modified 2017-12-20 revB by Troy
+        - Fixed bug where Dive depth was resetting to rise depth
 */
  
 #include "mbed.h"
@@ -74,16 +76,17 @@
  
 // loop rate used to determine how fast events trigger in the while loop
 Ticker loop_rate_ticker;
+Ticker log_loop_rate_ticker;
 
 volatile bool loop = false; //used so the compiler does not optimize this variable (load from memory, do not assume state of variable)
+volatile bool log_loop = false; //used so the compiler does not optimize this variable (load from memory, do not assume state of variable)
 
 void loop_trigger() { loop = true;} // loop trigger (used in while loop)
-//void log_loop_trigger() { log_loop = true;} // log loop trigger (used in while loop)
-
+void log_loop_trigger() { log_loop = true;} // log loop trigger (used in while loop)
 
 void setup() {
     pc().baud(57600);
-    pc().printf("\n\n\rFSG POOL TEST 2017-12-20 revA (DESKTOP SAVE TEST)\n\n\r");
+    pc().printf("\n\n\rFSG POOL TEST 2017-12-20 revB (DESKTOP SAVE TEST)\n\n\r");
     
     //setup data logger baud rate and write the start of the program (every time you reset)
     datalogger().baud(57600);
@@ -145,7 +148,7 @@
     loop_rate_ticker.attach(&loop_trigger, 0.1); // fires the ticker at 10 Hz rate
     
     // setup the data logger rate
-//    loop_log_rate_ticker.attach(&loop_log_trigger, 5.0); // fires the ticker at 0.2 Hz rate (every 5 seconds)
+    log_loop_rate_ticker.attach(&log_loop_trigger, 1.0); // fires the ticker at 1 Hz rate (every second)
 
 } 
  
@@ -153,17 +156,27 @@
     setup();
     
     while(1) {
+        static int current_state = 0;
         // runs at 10 hz
         if(loop) {
             led1() = !led1(); // blink led 1
-            stateMachine().runStateMachine();
+            
+            //running State Machine. Returns 0 if sitting idle (SIT_IDLE state).
+            current_state = stateMachine().runStateMachine();
+            
             loop = false; // wait until the loop rate timer fires again
         }
         
-//        if (log_loop) {
-//            led3() = !led3(); // blink led 3
-//            datalogger().printf("");
-//            log_loop = false;   // wait until the loop rate timer fires again
-//        }
+        //runs at 1 hz
+        if (log_loop) {
+            led3() = !led3(); // blink led 3
+            
+            //when the state machine is not in SIT_IDLE state
+            if(current_state != 0) {
+                OpenLog().recordData(current_state);   //start recording   
+            }
+            
+            log_loop = false;   // wait until the loop rate timer fires again
+        }
     }
 }
\ No newline at end of file