Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

Committer:
mfwic
Date:
Mon Dec 03 01:03:14 2018 +0000
Revision:
6:39442d493098
Parent:
5:09be5bbb5020
Child:
7:860b3a8275cb
Added data line with periodic refresh.; Added MY12 menu function.; Fixed menu functions MULT, BRDS, MY12 so that commandData is properly assigned, LUT is used, and settings displayed.

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 6:39442d493098 29 #include "Ticker.h"
mfwic 1:9f8583ba2431 30
mfwic 6:39442d493098 31 Ticker drt;
mfwic 6:39442d493098 32
mfwic 6:39442d493098 33 /*******************************************************************************
mfwic 6:39442d493098 34 drtInt - Display Refresh Timer interrupt handler
mfwic 6:39442d493098 35 *******************************************************************************/
mfwic 6:39442d493098 36 // real time clock interrupt to flash the LED
mfwic 6:39442d493098 37 void drtInt(void)
mfwic 6:39442d493098 38 {
mfwic 6:39442d493098 39 updateReady = TRUE;
mfwic 6:39442d493098 40 }
mfwic 6:39442d493098 41
mfwic 6:39442d493098 42 /*******************************************************************************
mfwic 6:39442d493098 43 initDRT - Create Display Refresh Timer interrupt
mfwic 6:39442d493098 44 *******************************************************************************/
mfwic 6:39442d493098 45 // initialize display refresh timer (DRT)
mfwic 6:39442d493098 46 void initDRT(void)
mfwic 6:39442d493098 47 {
mfwic 6:39442d493098 48 drt.attach_us(&drtInt, UPDATE_REFRESH_DELAY_US);
mfwic 6:39442d493098 49 }
mfwic 6:39442d493098 50
mfwic 6:39442d493098 51 /*******************************************************************************
mfwic 6:39442d493098 52 refreshData - Refresh voltage and current readings to the terminal
mfwic 6:39442d493098 53 *******************************************************************************/
mfwic 6:39442d493098 54 void refreshData(void){
mfwic 6:39442d493098 55 //loopTime = masterTimer.read_ms() - loopTime;
mfwic 6:39442d493098 56 sprintf(strbuf, "V48=%d, I48=%d | V24=%d, I24=%d | V12=%d, I12=%d || loop=%d\r\n", v48, i48, v24, i24, v12, i12, loopTime);
mfwic 6:39442d493098 57 sendSerial(strbuf);
mfwic 6:39442d493098 58 //sprintf(strbuf, "thermCode=%d, binCode=%d", thermCode[17], binCode[6]);
mfwic 6:39442d493098 59 sprintf(strbuf, "wr_out_code=%d, en_out_code=%d", wr_out_code, en_out_code);
mfwic 6:39442d493098 60 sendSerial(strbuf);
mfwic 6:39442d493098 61 }
mfwic 6:39442d493098 62
mfwic 6:39442d493098 63 /*******************************************************************************
mfwic 6:39442d493098 64 updateTerminal - Save cursor, write data, restore cursor.
mfwic 6:39442d493098 65 *******************************************************************************/
mfwic 6:39442d493098 66 void updateTerminal(void){
mfwic 6:39442d493098 67 //get cursor pos, store in CUR_POS
mfwic 6:39442d493098 68 sprintf( strbuf, "%c7", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 69 sendSerial(strbuf);
mfwic 6:39442d493098 70 //move cursor to DATA_ROW
mfwic 6:39442d493098 71 sprintf( strbuf, "%c[2;0f", 27 ); // ESC=27, Move cursor position = [line;columnf
mfwic 6:39442d493098 72 sendSerial(strbuf);
mfwic 6:39442d493098 73 //write data
mfwic 6:39442d493098 74 refreshData();
mfwic 6:39442d493098 75 //move cursor to CUR_POS
mfwic 6:39442d493098 76 sprintf( strbuf, "%c8", 27 ); // ESC=27, Save cursor position = [s
mfwic 6:39442d493098 77 sendSerial(strbuf);
mfwic 6:39442d493098 78 }
mfwic 6:39442d493098 79
mfwic 6:39442d493098 80 /*******************************************************************************
mfwic 6:39442d493098 81 clrScrn - clears terminal and moves cursor to upper-left corner
mfwic 6:39442d493098 82 *******************************************************************************/
mfwic 1:9f8583ba2431 83 // clears terminal
mfwic 1:9f8583ba2431 84 void clrScrn(void){
mfwic 1:9f8583ba2431 85 sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
mfwic 1:9f8583ba2431 86 sendSerial(strbuf);
mfwic 1:9f8583ba2431 87 sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
mfwic 1:9f8583ba2431 88 sendSerial(strbuf);
mfwic 1:9f8583ba2431 89 }
mfwic 1:9f8583ba2431 90
mfwic 6:39442d493098 91 /*******************************************************************************
mfwic 6:39442d493098 92 menuRedraw - Write menu to terminal
mfwic 6:39442d493098 93 *******************************************************************************/
mfwic 1:9f8583ba2431 94 // clears terminal and re-draws main menu
mfwic 1:9f8583ba2431 95 void menuRedraw(void){
mfwic 1:9f8583ba2431 96 clrScrn();
mfwic 6:39442d493098 97 sprintf(strbuf, "Agility Power Systems DCM1 Menu 0.3\r\n");
mfwic 1:9f8583ba2431 98 sendSerial(strbuf);
mfwic 6:39442d493098 99
mfwic 6:39442d493098 100 refreshData();
mfwic 6:39442d493098 101
mfwic 1:9f8583ba2431 102 sprintf(strbuf, "\r\nMULT");
mfwic 1:9f8583ba2431 103 sendSerial(strbuf);
mfwic 1:9f8583ba2431 104 sprintf(strbuf, "\r\nBRDS");
mfwic 1:9f8583ba2431 105 sendSerial(strbuf);
mfwic 1:9f8583ba2431 106 sprintf(strbuf, "\r\nALLOFF");
mfwic 1:9f8583ba2431 107 sendSerial(strbuf);
mfwic 1:9f8583ba2431 108 sprintf(strbuf, "\r\nRUN [xx]");
mfwic 1:9f8583ba2431 109 sendSerial(strbuf);
mfwic 1:9f8583ba2431 110 sprintf(strbuf, "\r\nSTOP");
mfwic 1:9f8583ba2431 111 sendSerial(strbuf);
mfwic 3:d8948c5b2951 112
mfwic 3:d8948c5b2951 113 menuPrompt(MENU_DCM1);
mfwic 3:d8948c5b2951 114 }
mfwic 3:d8948c5b2951 115
mfwic 6:39442d493098 116 /*******************************************************************************
mfwic 6:39442d493098 117 menuPrompt - Write menu prompt to terminal
mfwic 6:39442d493098 118 *******************************************************************************/
mfwic 3:d8948c5b2951 119 // sends carriage return and linefeed and prompt character
mfwic 3:d8948c5b2951 120 void menuPrompt(int menuType)
mfwic 3:d8948c5b2951 121 {
mfwic 3:d8948c5b2951 122 char strMenu[30] ={0};
mfwic 3:d8948c5b2951 123
mfwic 3:d8948c5b2951 124 switch(menuType)
mfwic 3:d8948c5b2951 125 {
mfwic 3:d8948c5b2951 126 case MENU_DCM1: strcpy(strMenu,"DCM1"); break;
mfwic 3:d8948c5b2951 127 //case MENU_DIFFERENTIAL: strcpy(strMenu,"DIFF"); break;
mfwic 3:d8948c5b2951 128 //case MENU_SINGLE: strcpy(strMenu,"SINGLE"); break;
mfwic 3:d8948c5b2951 129 //case MENU_DUAL: strcpy(strMenu,"DUAL"); break;
mfwic 3:d8948c5b2951 130 //case MENU_INVERT: strcpy(strMenu,"INVERT"); break;
mfwic 3:d8948c5b2951 131 //case MENU_SETTINGS: strcpy(strMenu,"SET"); break;
mfwic 3:d8948c5b2951 132 //case MENU_SETTINGS_CHAN1: strcpy(strMenu,"SET CHAN1"); break;
mfwic 3:d8948c5b2951 133 //case MENU_SETTINGS_CHAN2: strcpy(strMenu,"SET CHAN2"); break;
mfwic 3:d8948c5b2951 134 //case MENU_SETTINGS_CLOCK: strcpy(strMenu,"SET CLOCK"); break;
mfwic 3:d8948c5b2951 135 case MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
mfwic 3:d8948c5b2951 136 case MENU_TEST: strcpy(strMenu,"TEST"); break;
mfwic 3:d8948c5b2951 137 case MENU_MAIN: strcpy(strMenu,"MAIN"); break;
mfwic 3:d8948c5b2951 138 default: strcpy(strMenu,"UNDF"); break;
mfwic 3:d8948c5b2951 139 }
mfwic 3:d8948c5b2951 140
mfwic 3:d8948c5b2951 141 // append the CR,LF and the ready character
mfwic 3:d8948c5b2951 142 if(serialStatus.computer)
mfwic 3:d8948c5b2951 143 {
mfwic 3:d8948c5b2951 144 sendSerial("\r");
mfwic 3:d8948c5b2951 145 }
mfwic 3:d8948c5b2951 146 else
mfwic 3:d8948c5b2951 147 {
mfwic 3:d8948c5b2951 148 // adds a carrot so you know you are talking in terminal
mfwic 3:d8948c5b2951 149 sprintf(strbuf,"\n\r%s>",strMenu);
mfwic 3:d8948c5b2951 150 sendSerial(strbuf);
mfwic 3:d8948c5b2951 151 // sendSerial("\n\r>");
mfwic 3:d8948c5b2951 152 }
mfwic 1:9f8583ba2431 153 }