Treehouse Mbed Team / Mbed 2 deprecated APS_1U5x

Dependencies:   mbed

Revision:
14:e55ae9bb2a81
Parent:
12:fd1fd1857628
Child:
15:aed8f326c949
--- a/src/main.cpp	Sat Dec 08 02:02:25 2018 +0000
+++ b/src/main.cpp	Sat Dec 08 16:57:27 2018 +0000
@@ -34,6 +34,7 @@
 #include "stdlib.h"
 #include "serial.h"
 #include "adc.h"
+#include "adc_defs.h"
 #include "menu.h"
 #include "boards.h"
 #include "command.h"
@@ -46,7 +47,6 @@
 bool raw = FALSE;
 bool running = FALSE;
 bool testing = FALSE;
-bool buck = TRUE;
 
 Timer masterTimer;
 
@@ -76,9 +76,24 @@
 
    while (1)
    {
+      avals = getADCresults();
+      
       processCommand();
 
-      avals = getADCresults();
+      // Select RUN from menu to activate running mode.
+      // BRDS, MULT activate testing mode. MY12 emulates running mode wthout being in running mode.
+      // CAL and UNCAL do not change state of running or testing.
+      if(running){
+          //The current sensors results are single-ended. Results below the midpoint are for buck mode, above is for boost mode.
+          if((avals.i12 < CURRENT_12_OFFSET) & (avals.i48 < CURRENT_48_OFFSET)){  
+            updateControls(avals.i12);
+          }else{
+            updateControls(-(avals.i48));
+          }
+          //count++;
+      }else if(!testing){
+          updateControls(my12);
+      }
       
       if(updateReady){
          updateReady = FALSE;
@@ -89,17 +104,6 @@
          //sendSerial(strbuf);
          //count=0;
       }
-      
-      if(running){
-          if(buck){
-            updateControls(avals.i12);
-          }else{
-            updateControls(avals.i48);
-          }
-          //count++;
-      }else if(!testing){
-          updateControls(my12);
-      }
    }//end while(1)
 }//end void main(void)