Treehouse Mbed Team / Mbed 2 deprecated APS_DCM1SL

Dependencies:   mbed

src/menu.cpp

Committer:
mfwic
Date:
2018-12-01
Revision:
5:09be5bbb5020
Parent:
3:d8948c5b2951
Child:
6:39442d493098

File content as of revision 5:09be5bbb5020:

//-------------------------------------------------------------------------------
// 
//  Treehouse Inc.
//  Colorado Springs, Colorado
// 
//  Copyright (c) 2016 by Treehouse Designs Inc. 
// 
//  This code is the property of Treehouse, Inc. (Treehouse) and may not be redistributed
//  in any form without prior written permission from the copyright holder, Treehouse.
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//   
//-------------------------------------------------------------------------------
// 
//  REVISION HISTORY:
//  
//   $Author: $
//   $Rev: $
//   $Date: $
//   $URL: $
// 
//-------------------------------------------------------------------------------

#include "mbed.h"
#include "serial.h"
#include "menu.h"

// clears terminal
void clrScrn(void){
    sprintf( strbuf, "%c[2J", 27 ); // ESC=27, Clear screen = [2J
    sendSerial(strbuf);
    sprintf( strbuf, "%c[f", 27 ); // ESC=27, Move cursor to upper-left corner = [f
    sendSerial(strbuf);
}

// clears terminal and re-draws main menu
void menuRedraw(void){
    clrScrn();
    sprintf(strbuf, "Agility Power Systems DCM1 Menu 0.3");
    sendSerial(strbuf);
    sprintf(strbuf, "\r\nMULT");
    sendSerial(strbuf);
    sprintf(strbuf, "\r\nBRDS");
    sendSerial(strbuf);
    sprintf(strbuf, "\r\nALLOFF");
    sendSerial(strbuf);
    sprintf(strbuf, "\r\nRUN [xx]");
    sendSerial(strbuf);
    sprintf(strbuf, "\r\nSTOP");
    sendSerial(strbuf);
    
    menuPrompt(MENU_DCM1);
}

// sends carriage return and linefeed and prompt character
void menuPrompt(int menuType)
{
 char strMenu[30] ={0};

    switch(menuType)
    {
      case  MENU_DCM1: strcpy(strMenu,"DCM1"); break;
      //case  MENU_DIFFERENTIAL: strcpy(strMenu,"DIFF"); break;
      //case  MENU_SINGLE: strcpy(strMenu,"SINGLE"); break;
      //case  MENU_DUAL: strcpy(strMenu,"DUAL"); break;
      //case  MENU_INVERT: strcpy(strMenu,"INVERT"); break;
      //case  MENU_SETTINGS: strcpy(strMenu,"SET"); break;
      //case  MENU_SETTINGS_CHAN1: strcpy(strMenu,"SET CHAN1"); break;
      //case  MENU_SETTINGS_CHAN2: strcpy(strMenu,"SET CHAN2"); break;
      //case  MENU_SETTINGS_CLOCK: strcpy(strMenu,"SET CLOCK"); break;
      case  MENU_CALIBRATE: strcpy(strMenu,"CAL"); break;
      case  MENU_TEST: strcpy(strMenu,"TEST"); break;
      case  MENU_MAIN: strcpy(strMenu,"MAIN"); break;
      default: strcpy(strMenu,"UNDF"); break;
    }

    // append the CR,LF and the ready character
     if(serialStatus.computer)
     {
         sendSerial("\r");
     }
     else
     {
        // adds a carrot so you know you are talking in terminal
        sprintf(strbuf,"\n\r%s>",strMenu);
        sendSerial(strbuf);
        // sendSerial("\n\r>");
     }
}