Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Wed Dec 12 00:10:03 2018 +0000
Revision:
16:5791665200cb
Parent:
15:aed8f326c949
Child:
18:78e982f31c6b
Added banner and fixed status display to clear old status properly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfwic 1:9f8583ba2431 1 //-------------------------------------------------------------------------------
mfwic 1:9f8583ba2431 2 //
mfwic 1:9f8583ba2431 3 // Treehouse Inc.
mfwic 1:9f8583ba2431 4 // Colorado Springs, Colorado
mfwic 1:9f8583ba2431 5 //
mfwic 1:9f8583ba2431 6 // Copyright (c) 2016 by Treehouse Designs Inc.
mfwic 1:9f8583ba2431 7 //
mfwic 1:9f8583ba2431 8 // This code is the property of Treehouse, Inc. (Treehouse) and may not be redistributed
mfwic 1:9f8583ba2431 9 // in any form without prior written permission from the copyright holder, Treehouse.
mfwic 1:9f8583ba2431 10 //
mfwic 1:9f8583ba2431 11 // The above copyright notice and this permission notice shall be included in
mfwic 1:9f8583ba2431 12 // all copies or substantial portions of the Software.
mfwic 1:9f8583ba2431 13 //
mfwic 1:9f8583ba2431 14 //-------------------------------------------------------------------------------
mfwic 1:9f8583ba2431 15 //
mfwic 1:9f8583ba2431 16 // REVISION HISTORY:
mfwic 1:9f8583ba2431 17 //
mfwic 1:9f8583ba2431 18 // $Author: $
mfwic 1:9f8583ba2431 19 // $Rev: $
mfwic 1:9f8583ba2431 20 // $Date: $
mfwic 1:9f8583ba2431 21 // $URL: $
mfwic 1:9f8583ba2431 22 //
mfwic 1:9f8583ba2431 23 //-------------------------------------------------------------------------------
mfwic 1:9f8583ba2431 24
mfwic 1:9f8583ba2431 25 #include "mbed.h"
mfwic 6:39442d493098 26 #include "globals.h"
mfwic 1:9f8583ba2431 27 #include "serial.h"
mfwic 1:9f8583ba2431 28 #include "menu.h"
mfwic 11:01dcfb29fbc4 29 #include "adc.h"
mfwic 15:aed8f326c949 30 #include "boards.h"
mfwic 6:39442d493098 31 #include "Ticker.h"
mfwic 15:aed8f326c949 32 #include "stdlib.h"
mfwic 1:9f8583ba2431 33
mfwic 6:39442d493098 34 Ticker drt;
mfwic 7:860b3a8275cb 35 unsigned int oldTime=0;
mfwic 6:39442d493098 36
mfwic 6:39442d493098 37 /*******************************************************************************
mfwic 6:39442d493098 38 drtInt - Display Refresh Timer interrupt handler
mfwic 6:39442d493098 39 *******************************************************************************/
mfwic 6:39442d493098 40 // real time clock interrupt to flash the LED
mfwic 6:39442d493098 41 void drtInt(void)
mfwic 6:39442d493098 42 {
mfwic 6:39442d493098 43 updateReady = TRUE;
mfwic 6:39442d493098 44 }
mfwic 6:39442d493098 45
mfwic 6:39442d493098 46 /*******************************************************************************
mfwic 6:39442d493098 47 initDRT - Create Display Refresh Timer interrupt
mfwic 6:39442d493098 48 *******************************************************************************/
mfwic 6:39442d493098 49 // initialize display refresh timer (DRT)
mfwic 6:39442d493098 50 void initDRT(void)
mfwic 6:39442d493098 51 {
mfwic 6:39442d493098 52 drt.attach_us(&drtInt, UPDATE_REFRESH_DELAY_US);
mfwic 6:39442d493098 53 }
mfwic 6:39442d493098 54
mfwic 6:39442d493098 55 /*******************************************************************************
mfwic 15:aed8f326c949 56 refreshStatus - Refresh status info to the terminal
mfwic 15:aed8f326c949 57 *******************************************************************************/
mfwic 15:aed8f326c949 58 void refreshStatus(struct statusValues statVals){
mfwic 15:aed8f326c949 59
mfwic 16:5791665200cb 60 char strbuf_mode[15] = {0};
mfwic 16:5791665200cb 61 char strbuf_running[16] = {0};
mfwic 16:5791665200cb 62 char strbuf_v48[15] = {0};
mfwic 16:5791665200cb 63 char strbuf_v24[15] = {0};
mfwic 16:5791665200cb 64 char strbuf_v12[15] = {0};
mfwic 16:5791665200cb 65 char strbuf_blank[50] = {0};
mfwic 16:5791665200cb 66
mfwic 15:aed8f326c949 67 if(buck){
mfwic 16:5791665200cb 68 sprintf(strbuf_mode, "Buck Mode | ");
mfwic 15:aed8f326c949 69 }else{
mfwic 16:5791665200cb 70 sprintf(strbuf_mode, "Boost Mode | ");
mfwic 15:aed8f326c949 71 }
mfwic 16:5791665200cb 72 //sendSerial(strbuf);
mfwic 16:5791665200cb 73
mfwic 16:5791665200cb 74 if(running){
mfwic 16:5791665200cb 75 sprintf(strbuf_running, "Running | ");
mfwic 16:5791665200cb 76 }else{
mfwic 16:5791665200cb 77 sprintf(strbuf_running, "NOT Running | ");
mfwic 16:5791665200cb 78 }
mfwic 16:5791665200cb 79 //sendSerial(strbuf);
mfwic 15:aed8f326c949 80
mfwic 15:aed8f326c949 81 if(statVals.V48_IS_HI){
mfwic 16:5791665200cb 82 sprintf(strbuf_v48, "V48 HIGH | ");
mfwic 15:aed8f326c949 83 }else if(statVals.V48_IS_LO){
mfwic 16:5791665200cb 84 sprintf(strbuf_v48, "V48 LOW | ");
mfwic 15:aed8f326c949 85 }else{
mfwic 16:5791665200cb 86 // sprintf(strbuf, "V48 OK | ");
mfwic 16:5791665200cb 87 sprintf(strbuf_v48, "");
mfwic 16:5791665200cb 88 sprintf(strbuf_blank, " ");
mfwic 15:aed8f326c949 89 }
mfwic 16:5791665200cb 90 //sendSerial(strbuf);
mfwic 15:aed8f326c949 91
mfwic 15:aed8f326c949 92 if(statVals.V24_IS_HI){
mfwic 16:5791665200cb 93 sprintf(strbuf_v24, "V24 HIGH | ");
mfwic 15:aed8f326c949 94 }else if(statVals.V24_IS_LO){
mfwic 16:5791665200cb 95 sprintf(strbuf_v24, "V24 LOW | ");
mfwic 15:aed8f326c949 96 }else{
mfwic 16:5791665200cb 97 // sprintf(strbuf, "V24 OK | ");
mfwic 16:5791665200cb 98 sprintf(strbuf_v24, "");
mfwic 16:5791665200cb 99 sprintf(strbuf_blank, strcat(strbuf_blank, " "));
mfwic 15:aed8f326c949 100 }
mfwic 16:5791665200cb 101 //sendSerial(strbuf);
mfwic 15:aed8f326c949 102
mfwic 15:aed8f326c949 103 if(statVals.V12_IS_HI){
mfwic 16:5791665200cb 104 sprintf(strbuf_v12, "V12 HIGH ");
mfwic 15:aed8f326c949 105 }else if(statVals.V24_IS_LO){
mfwic 16:5791665200cb 106 sprintf(strbuf_v12, "V12 LOW ");
mfwic 15:aed8f326c949 107 }else{
mfwic 16:5791665200cb 108 // sprintf(strbuf, "V12 OK | ");
mfwic 16:5791665200cb 109 sprintf(strbuf_v12, "");
mfwic 16:5791665200cb 110 sprintf(strbuf_blank, strcat(strbuf_blank, " "));
mfwic 15:aed8f326c949 111 }
mfwic 16:5791665200cb 112 //sendSerial(strbuf);
mfwic 15:aed8f326c949 113
mfwic 16:5791665200cb 114 //move cursor to STATUS_ROW and write status info
mfwic 16:5791665200cb 115 //char row = STATUS_ROW + '0';
mfwic 16:5791665200cb 116 sprintf( strbuf, "%c[9;0f", 27); // ESC=27, Move cursor position = [line;columnf
mfwic 16:5791665200cb 117 sendSerial(strbuf);
mfwic 15:aed8f326c949 118
mfwic 16:5791665200cb 119 sprintf(strbuf, "Status: %s%s%s%s%s%s\r\n\r\n", strbuf_mode, strbuf_running, strbuf_v48, strbuf_v24, strbuf_v12, strbuf_blank);
mfwic 15:aed8f326c949 120 sendSerial(strbuf);
mfwic 15:aed8f326c949 121
mfwic 15:aed8f326c949 122 }
mfwic 15:aed8f326c949 123
mfwic 15:aed8f326c949 124 /*******************************************************************************
mfwic 6:39442d493098 125 refreshData - Refresh voltage and current readings to the terminal
mfwic 6:39442d493098 126 *******************************************************************************/
mfwic 15:aed8f326c949 127 void refreshData(struct adcValues adcVals){
mfwic 8:d3d7dca419b3 128 //loopTime = masterTimer.read_ms() - oldTime;
mfwic 8:d3d7dca419b3 129 //oldTime = masterTimer.read_ms();
mfwic 8:d3d7dca419b3 130
mfwic 15:aed8f326c949 131 struct displayValues dvals = calcDisplayValues(adcVals);
mfwic 7:860b3a8275cb 132
mfwic 11:01dcfb29fbc4 133 double pwr_out=dvals.v12f*dvals.i12f;
mfwic 12:fd1fd1857628 134 double pwr_in=dvals.v48f*(dvals.i48f);
mfwic 7:860b3a8275cb 135 double pwr_eff=100*pwr_out/pwr_in;
mfwic 7:860b3a8275cb 136
mfwic 16:5791665200cb 137 //move cursor to DATA_ROW and write data
mfwic 16:5791665200cb 138 //row = DATA_ROW + '0';
mfwic 16:5791665200cb 139 sprintf( strbuf, "%c[10;0f", 27); // ESC=27, Move cursor position = [line;columnf
mfwic 16:5791665200cb 140 sendSerial(strbuf);
mfwic 16:5791665200cb 141
mfwic 11:01dcfb29fbc4 142 sprintf(strbuf, "V48=%2.1f, I48=%3.1f | V24=%2.1f, I24=%3.1f | V12=%2.1f, I12=%3.1f \r\n", dvals.v48f, dvals.i48f, dvals.v24f, dvals.i24f, dvals.v12f, dvals.i12f);
mfwic 8:d3d7dca419b3 143 //sprintf(strbuf, "V48=%2.1f, I48=%2.2f | V24=%2.1f, I24=%2.2f | V12=%2.1f, I12=%2.2f || loop=%d \r\n", v48f, i48f, v24f, i24f, v12f, i12f, loopTime);
mfwic 7:860b3a8275cb 144 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 145 sprintf(strbuf, "Power Out = %4.1f W, Power In = %4.1f W \r\n", pwr_out, pwr_in);
mfwic 7:860b3a8275cb 146 sendSerial(strbuf);
mfwic 7:860b3a8275cb 147 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 148 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 149 sprintf(strbuf, "Power Efficiency = %2.2f percent \r\n\r\n", pwr_eff);
mfwic 7:860b3a8275cb 150 sendSerial(strbuf);
mfwic 7:860b3a8275cb 151 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 6:39442d493098 152 sendSerial(strbuf);
mfwic 16:5791665200cb 153 sprintf(strbuf, "wr_out_code=%d, en_out_code=%d \r\n", wr_out_code, en_out_code);
mfwic 6:39442d493098 154 sendSerial(strbuf);
mfwic 6:39442d493098 155 }
mfwic 6:39442d493098 156
mfwic 6:39442d493098 157 /*******************************************************************************
mfwic 6:39442d493098 158 updateTerminal - Save cursor, write data, restore cursor.
mfwic 6:39442d493098 159 *******************************************************************************/
mfwic 15:aed8f326c949 160 void updateTerminal(struct adcValues adcVals, struct statusValues statVals){
mfwic 6:39442d493098 161 //get cursor pos, store in CUR_POS
mfwic 6:39442d493098 162 sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 163 sendSerial(strbuf);
mfwic 15:aed8f326c949 164
mfwic 15:aed8f326c949 165 refreshStatus(statVals);
mfwic 15:aed8f326c949 166 refreshData(adcVals);
mfwic 15:aed8f326c949 167
mfwic 6:39442d493098 168 //move cursor to CUR_POS
mfwic 6:39442d493098 169 sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 170 sendSerial(strbuf);
mfwic 6:39442d493098 171 }
mfwic 6:39442d493098 172
mfwic 6:39442d493098 173 /*******************************************************************************
mfwic 6:39442d493098 174 clrScrn - clears terminal and moves cursor to upper-left corner
mfwic 6:39442d493098 175 *******************************************************************************/
mfwic 1:9f8583ba2431 176 // clears terminal
mfwic 1:9f8583ba2431 177 void clrScrn(void){
mfwic 1:9f8583ba2431 178 sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
mfwic 1:9f8583ba2431 179 sendSerial(strbuf);
mfwic 1:9f8583ba2431 180 sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
mfwic 1:9f8583ba2431 181 sendSerial(strbuf);
mfwic 1:9f8583ba2431 182 }
mfwic 1:9f8583ba2431 183
mfwic 6:39442d493098 184 /*******************************************************************************
mfwic 6:39442d493098 185 menuRedraw - Write menu to terminal
mfwic 6:39442d493098 186 *******************************************************************************/
mfwic 1:9f8583ba2431 187 // clears terminal and re-draws main menu
mfwic 8:d3d7dca419b3 188 void menuRedraw(bool prompt){
mfwic 1:9f8583ba2431 189 clrScrn();
mfwic 16:5791665200cb 190 menu_banner();
mfwic 7:860b3a8275cb 191
mfwic 7:860b3a8275cb 192 sprintf( strbuf, "%c[34m", 27 ); // ESC=27, Blue Text
mfwic 7:860b3a8275cb 193 sendSerial(strbuf);
mfwic 7:860b3a8275cb 194
mfwic 16:5791665200cb 195 sprintf(strbuf, " Agility Power Systems DCM1 0.7\r\n\r\n");
mfwic 7:860b3a8275cb 196 sendSerial(strbuf);
mfwic 7:860b3a8275cb 197
mfwic 7:860b3a8275cb 198 sprintf( strbuf, "%c[0m", 27 ); // ESC=27, Normal
mfwic 7:860b3a8275cb 199 sendSerial(strbuf);
mfwic 7:860b3a8275cb 200 sprintf( strbuf, "%c[30m", 27 ); // ESC=27, White Text
mfwic 1:9f8583ba2431 201 sendSerial(strbuf);
mfwic 6:39442d493098 202
mfwic 15:aed8f326c949 203 struct adcValues adcVals = getADCresults();
mfwic 15:aed8f326c949 204 struct statusValues statVals = checkLevels(adcVals);
mfwic 15:aed8f326c949 205 refreshStatus(statVals);
mfwic 15:aed8f326c949 206 refreshData(adcVals);
mfwic 6:39442d493098 207
mfwic 16:5791665200cb 208 sprintf(strbuf, "\r\nCommands: (Not Case-Sensitive)");
mfwic 16:5791665200cb 209 sendSerial(strbuf);
mfwic 12:fd1fd1857628 210 sprintf(strbuf, "\r\n BRDS");
mfwic 1:9f8583ba2431 211 sendSerial(strbuf);
mfwic 12:fd1fd1857628 212 sprintf(strbuf, "\r\n MULT");
mfwic 1:9f8583ba2431 213 sendSerial(strbuf);
mfwic 8:d3d7dca419b3 214 sprintf(strbuf, "\r\n ALLOFF");
mfwic 1:9f8583ba2431 215 sendSerial(strbuf);
mfwic 16:5791665200cb 216 sprintf(strbuf, "\r\n RUN");
mfwic 16:5791665200cb 217 sendSerial(strbuf);
mfwic 16:5791665200cb 218 sprintf(strbuf, "\r\n STOP\r\n");
mfwic 16:5791665200cb 219 sendSerial(strbuf);
mfwic 16:5791665200cb 220 sprintf(strbuf, "\r\n Type \'=number\' after BRDS or MULT to enter value.");
mfwic 1:9f8583ba2431 221 sendSerial(strbuf);
mfwic 16:5791665200cb 222 sprintf(strbuf, "\r\n e.g. BRDS=8191 will enable all boards.\r\n");
mfwic 16:5791665200cb 223 sendSerial(strbuf);
mfwic 16:5791665200cb 224 sprintf(strbuf, "\r\n Type \'?\' at end of BRDS or MULT to get status.");
mfwic 16:5791665200cb 225 sendSerial(strbuf);
mfwic 16:5791665200cb 226 sprintf(strbuf, "\r\n e.g. BRDS? will print value of BRDS.\r\n");
mfwic 1:9f8583ba2431 227 sendSerial(strbuf);
mfwic 3:d8948c5b2951 228
mfwic 8:d3d7dca419b3 229 if(prompt){
mfwic 8:d3d7dca419b3 230 menuPrompt(MENU_DCM1);
mfwic 8:d3d7dca419b3 231 }
mfwic 3:d8948c5b2951 232 }
mfwic 3:d8948c5b2951 233
mfwic 6:39442d493098 234 /*******************************************************************************
mfwic 15:aed8f326c949 235 sendLevelsWarning
mfwic 15:aed8f326c949 236 *******************************************************************************/
mfwic 15:aed8f326c949 237 void sendLevelsWarning(void){
mfwic 15:aed8f326c949 238 sprintf(strbuf, "\r\nSome voltage levels are out of range. I would look into it if I were you.\r\n");
mfwic 15:aed8f326c949 239 sendSerial(strbuf);
mfwic 15:aed8f326c949 240 }
mfwic 15:aed8f326c949 241
mfwic 15:aed8f326c949 242 /*******************************************************************************
mfwic 6:39442d493098 243 menuPrompt - Write menu prompt to terminal
mfwic 6:39442d493098 244 *******************************************************************************/
mfwic 3:d8948c5b2951 245 // sends carriage return and linefeed and prompt character
mfwic 3:d8948c5b2951 246 void menuPrompt(int menuType)
mfwic 3:d8948c5b2951 247 {
mfwic 3:d8948c5b2951 248 char strMenu[30] ={0};
mfwic 3:d8948c5b2951 249
mfwic 3:d8948c5b2951 250 switch(menuType)
mfwic 3:d8948c5b2951 251 {
mfwic 3:d8948c5b2951 252 case MENU_DCM1: strcpy(strMenu,"DCM1"); break;
mfwic 3:d8948c5b2951 253 case MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
mfwic 3:d8948c5b2951 254 case MENU_TEST: strcpy(strMenu,"TEST"); break;
mfwic 3:d8948c5b2951 255 case MENU_MAIN: strcpy(strMenu,"MAIN"); break;
mfwic 3:d8948c5b2951 256 default: strcpy(strMenu,"UNDF"); break;
mfwic 3:d8948c5b2951 257 }
mfwic 3:d8948c5b2951 258
mfwic 3:d8948c5b2951 259 // append the CR,LF and the ready character
mfwic 3:d8948c5b2951 260 if(serialStatus.computer)
mfwic 3:d8948c5b2951 261 {
mfwic 3:d8948c5b2951 262 sendSerial("\r");
mfwic 3:d8948c5b2951 263 }
mfwic 3:d8948c5b2951 264 else
mfwic 3:d8948c5b2951 265 {
mfwic 3:d8948c5b2951 266 // adds a carrot so you know you are talking in terminal
mfwic 3:d8948c5b2951 267 sprintf(strbuf,"\n\r%s>",strMenu);
mfwic 3:d8948c5b2951 268 sendSerial(strbuf);
mfwic 3:d8948c5b2951 269 // sendSerial("\n\r>");
mfwic 3:d8948c5b2951 270 }
mfwic 8:d3d7dca419b3 271 }
mfwic 8:d3d7dca419b3 272
mfwic 16:5791665200cb 273 void menu_banner(void)
mfwic 8:d3d7dca419b3 274 {
mfwic 8:d3d7dca419b3 275 clrScrn();
mfwic 8:d3d7dca419b3 276 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 277 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \\____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 278 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \\ | /| / / _ \\/ ___/ \\__ \\/ / / / ___/ __/ _ \\/ __ `__ \\/ ___/\r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 279 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 280 sprintf(strbuf,"/_/ |_\\__, /_/_/_/\\__/\\__, / /_/ \\____/|__/|__/\\___/_/ /____/\\__, /____/\\__/\\___/_/ /_/ /_/____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 281 sprintf(strbuf," /____/ /____/ /____/ \r\n");sendSerial(strbuf);
mfwic 8:d3d7dca419b3 282 }
mfwic 8:d3d7dca419b3 283 /*
mfwic 8:d3d7dca419b3 284 sprintf(strbuf," ___ _ ___ __ ____ _____ __ \r\n");
mfwic 8:d3d7dca419b3 285 sprintf(strbuf," / | ____ _(_) (_) /___ __ / __ \____ _ _____ _____ / ___/__ _______/ /____ ____ ___ _____\r\n");
mfwic 8:d3d7dca419b3 286 sprintf(strbuf," / /| |/ __ `/ / / / __/ / / / / /_/ / __ \ | /| / / _ \/ ___/ \__ \/ / / / ___/ __/ _ \/ __ `__ \/ ___/\r\n");
mfwic 8:d3d7dca419b3 287 sprintf(strbuf," / ___ / /_/ / / / / /_/ /_/ / / ____/ /_/ / |/ |/ / __/ / ___/ / /_/ (__ ) /_/ __/ / / / / (__ ) \r\n");
mfwic 8:d3d7dca419b3 288 sprintf(strbuf,"/_/ |_\__, /_/_/_/\__/\__, / /_/ \____/|__/|__/\___/_/ /____/\__, /____/\__/\___/_/ /_/ /_/____/ \r\n");
mfwic 8:d3d7dca419b3 289 sprintf(strbuf," /____/ /____/ /____/ \r\n");
mfwic 8:d3d7dca419b3 290 */