Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Revision:
15:aed8f326c949
Parent:
12:fd1fd1857628
Child:
16:5791665200cb
--- a/src/menu.cpp	Sat Dec 08 16:57:27 2018 +0000
+++ b/src/menu.cpp	Tue Dec 11 16:59:21 2018 +0000
@@ -27,7 +27,9 @@
 #include "serial.h"
 #include "menu.h"
 #include "adc.h"
+#include "boards.h"
 #include "Ticker.h"
+#include "stdlib.h"
 
 Ticker drt;
 unsigned int oldTime=0;
@@ -51,13 +53,71 @@
 }
 
 /*******************************************************************************
+ refreshStatus - Refresh status info to the terminal
+*******************************************************************************/
+void refreshStatus(struct statusValues statVals){
+    
+    if(buck){
+        sprintf(strbuf, "Buck Mode  | ");
+    }else{
+        sprintf(strbuf, "Boost Mode | ");
+    }
+    sendSerial(strbuf);
+    
+    if(statVals.V48_IS_HI){
+        sprintf(strbuf, "V48 HIGH | ");
+        sendSerial(strbuf);
+    }else if(statVals.V48_IS_LO){
+        sprintf(strbuf, "V48 LOW  | ");
+        sendSerial(strbuf);
+    }else{
+        sprintf(strbuf, "V48 OK   | ");
+        sendSerial(strbuf);
+    }
+    
+    if(statVals.V24_IS_HI){
+        sprintf(strbuf, "V24 HIGH | ");
+        sendSerial(strbuf);
+    }else if(statVals.V24_IS_LO){
+        sprintf(strbuf, "V24 LOW  | ");
+        sendSerial(strbuf);
+    }else{
+        sprintf(strbuf, "V24 OK   | ");
+        sendSerial(strbuf);
+    }
+    
+    if(statVals.V12_IS_HI){
+        sprintf(strbuf, "V12 HIGH | ");
+        sendSerial(strbuf);
+    }else if(statVals.V24_IS_LO){
+        sprintf(strbuf, "V12 LOW  | ");
+        sendSerial(strbuf);
+    }else{
+        sprintf(strbuf, "V12 OK   | ");
+        sendSerial(strbuf);
+    }
+    
+    if(running){
+        sprintf(strbuf, "Running    ");
+        sendSerial(strbuf);
+    }else{
+        sprintf(strbuf, "NOT Running");
+        sendSerial(strbuf);
+    }
+    
+    sprintf(strbuf, "\r\n");
+    sendSerial(strbuf);
+    
+}
+
+/*******************************************************************************
  refreshData - Refresh voltage and current readings to the terminal
 *******************************************************************************/
-void refreshData(struct adcValues avals){
+void refreshData(struct adcValues adcVals){
     //loopTime = masterTimer.read_ms() - oldTime;
     //oldTime = masterTimer.read_ms();
     
-    struct displayValues dvals = calcDisplayValues(avals);
+    struct displayValues dvals = calcDisplayValues(adcVals);
     
     double pwr_out=dvals.v12f*dvals.i12f;
     double pwr_in=dvals.v48f*(dvals.i48f);
@@ -81,15 +141,23 @@
 /*******************************************************************************
  updateTerminal - Save cursor, write data, restore cursor.
 *******************************************************************************/
-void updateTerminal(struct adcValues avals){
+void updateTerminal(struct adcValues adcVals, struct statusValues statVals){
     //get cursor pos, store in CUR_POS
     sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
     sendSerial(strbuf);
-    //move cursor to DATA_ROW
-    sprintf( strbuf, "%c[3;0f", 27 ); // ESC=27, Move cursor position = [line;columnf
+    
+    //move cursor to STATUS_ROW and write status info
+    char row = STATUS_ROW + '0';
+    sprintf( strbuf, "%c[%c;0f", 27, row); // ESC=27, Move cursor position = [line;columnf
     sendSerial(strbuf);
-    //write data
-    refreshData(avals);
+    refreshStatus(statVals);
+    
+    //move cursor to DATA_ROW and write data
+    row = DATA_ROW + '0';
+    sprintf( strbuf, "%c[%c;0f", 27, row); // ESC=27, Move cursor position = [line;columnf
+    sendSerial(strbuf);
+    refreshData(adcVals);
+    
     //move cursor to CUR_POS
     sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
     sendSerial(strbuf);
@@ -116,7 +184,7 @@
     sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
     sendSerial(strbuf);
     
-    sprintf(strbuf, "                     Agility Power Systems DCM1 0.5\r\n\r\n");
+    sprintf(strbuf, "                     Agility Power Systems DCM1 0.6\r\n\r\n");
     sendSerial(strbuf);
     
     sprintf( strbuf, "%c[0m", 27 ); // ESC=27, Normal
@@ -124,8 +192,10 @@
     sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
     sendSerial(strbuf);
     
-    struct adcValues avals = getADCresults();
-    refreshData(avals);
+    struct adcValues adcVals = getADCresults();
+    struct statusValues statVals = checkLevels(adcVals);
+    refreshStatus(statVals);
+    refreshData(adcVals);
     
     sprintf(strbuf, "\r\n BRDS");
     sendSerial(strbuf);
@@ -144,6 +214,14 @@
 }
 
 /*******************************************************************************
+ sendLevelsWarning
+*******************************************************************************/
+void sendLevelsWarning(void){
+    sprintf(strbuf, "\r\nSome voltage levels are out of range. I would look into it if I were you.\r\n");
+    sendSerial(strbuf);
+}
+
+/*******************************************************************************
  menuPrompt - Write menu prompt to terminal
 *******************************************************************************/
 // sends carriage return and linefeed and prompt character