Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
Slord2142
Date:
Wed Mar 06 22:32:31 2019 +0000
Revision:
30:d8721a46ee03
Parent:
26:55e8e1a9cc84
Child:
33:6c7364ea360f
Removed extraneous comments from all files

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