Damian Herman / Mbed 2 deprecated NetrunnerMain

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SerialPrompt.h Source File

SerialPrompt.h

00001 #ifndef SERIALPROMPT_H
00002 #define SERIALPROMPT_H
00003 #include "EngineDriver.h"
00004 #include "VoltageGetter.h"
00005 #include "mbed.h"
00006 const char* prompt = "$>";
00007 const char* help = "h - help  d - drive driving unit\n\r v - get input voltage s - get collision sensor distance \n\r";
00008 const char* drivingMode = "Going to driving mode.\n\r Available commands: e - exit from driving mode \n\r";
00009 const char* voltage = "Actual voltage: %g \n\r";
00010 bool isDriving = false;
00011 AnalogIn voltagePin(A0);
00012 extern int inState[4];
00013 extern void applyStates();
00014 extern const char* distMsg;
00015 extern float actualDistance;
00016 void displayPrompt(Serial* pcConnection)
00017 {
00018     pcConnection->printf(prompt);
00019 }
00020 void displayMessage(const char* msg, Serial* pcConnection)
00021 {
00022     pcConnection->printf(msg);
00023     displayPrompt(pcConnection);
00024 }
00025 void displayMessage(const char* msg, Serial* pcConnection, float number)
00026 {
00027      pcConnection->printf(msg, number);
00028     displayPrompt(pcConnection);
00029 }
00030 ///
00031 /// 0 - not known command
00032 /// 2 - drive the driving unit
00033 int getMenuInput(Serial* pcConnection)
00034 {
00035     if(pcConnection->readable())
00036     {
00037         char msg = pcConnection->getc();
00038         if(msg == 'h')
00039         {
00040             displayMessage(help, pcConnection);
00041         }else if(msg == 'd')
00042         {
00043             displayMessage(drivingMode, pcConnection);
00044             isDriving = true;      
00045             return 2;
00046         }else if(msg == 'v')
00047         {
00048             displayMessage(voltage, pcConnection, getVoltage(&voltagePin));
00049             return 3;
00050         }else if(msg == 's')
00051         {
00052             displayMessage(distMsg, pcConnection, actualDistance);
00053             return 4;
00054         }
00055     }
00056     return 0;
00057 }
00058 
00059 #endif // SERIALPROMPT_H