Treehouse Mbed Team / Mbed 2 deprecated APS_1U5x

Dependencies:   mbed

Revision:
15:aed8f326c949
Parent:
14:e55ae9bb2a81
Child:
16:5791665200cb
--- a/src/main.cpp	Sat Dec 08 16:57:27 2018 +0000
+++ b/src/main.cpp	Tue Dec 11 16:59:21 2018 +0000
@@ -47,6 +47,7 @@
 bool raw = FALSE;
 bool running = FALSE;
 bool testing = FALSE;
+bool buck = TRUE;
 
 Timer masterTimer;
 
@@ -64,9 +65,11 @@
    
    initADC();
 
-   struct adcValues avals = getADCresults();
+   struct adcValues adcVals = getADCresults();
+   struct statusValues statVals = checkLevels(adcVals);
    
    splash_screen();
+   //initBoards(adcVals);
    sprintf(strbuf, "\r\nPress Enter to continue");
    sendSerial(strbuf);
    while(waitCommand()){ // Wait for user to press Enter
@@ -76,7 +79,9 @@
 
    while (1)
    {
-      avals = getADCresults();
+      adcVals = getADCresults();
+      
+      statVals = checkLevels(adcVals);
       
       processCommand();
 
@@ -85,10 +90,12 @@
       // 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);
+          if(adcVals.i12 < CURRENT_12_OFFSET){  
+            updateControls(adcVals.i12);
+            buck = TRUE;
           }else{
-            updateControls(-(avals.i48));
+            updateControls(adcVals.i12-CURRENT_12_OFFSET);
+            buck = FALSE;
           }
           //count++;
       }else if(!testing){
@@ -97,7 +104,7 @@
       
       if(updateReady){
          updateReady = FALSE;
-         updateTerminal(avals);  // May want to gate this call when we run a headless system.
+         updateTerminal(adcVals, statVals);  // May want to gate this call when we run a headless system.
          //loopTime = masterTimer.read_ms();// - loopTime;
          myled = !myled;
          //sprintf(strbuf, "\r\nupdateControls ran %d times.\r\n", count);