Damian Herman / Mbed 2 deprecated NetrunnerMain

Dependencies:   mbed

Revision:
4:cc391b3f3e57
Parent:
3:def8a92db030
Child:
5:1afe17a20a5b
--- a/include/SerialPrompt.h	Wed Jun 24 09:26:07 2015 +0000
+++ b/include/SerialPrompt.h	Tue Aug 04 09:05:16 2015 +0000
@@ -1,16 +1,68 @@
 #ifndef SERIALPROMPT_H
 #define SERIALPROMPT_H
+#include "EngineDriver.h"
+#include "VoltageGetter.h"
 #include "mbed.h"
 const char* prompt = "$>";
+const char* help = "h - help  d - drive driving unit\n\r v - get input voltage\n\r";
+const char* drivingMode = "Going to driving mode.\n\r Available commands: f - forwards\n\r b - backwards\n\r r - right\n\r l - left\n\r e - exit from driving mode ";
+const char* voltage = "Actual voltage: %g \n\r";
+bool isDriving = false;
+AnalogIn voltagePin(A0);
 void displayPrompt(Serial* pcConnection)
 {
     pcConnection->printf(prompt);
 }
-int getInput(Serial* pcConnection)
+void displayMessage(const char* msg, Serial* pcConnection)
+{
+    pcConnection->printf(msg);
+    displayPrompt(pcConnection);
+}
+void displayMessage(const char* msg, Serial* pcConnection, float number)
+{
+     pcConnection->printf(msg, number);
+    displayPrompt(pcConnection);
+}
+///
+/// 0 - not known command
+/// 2 - drive the driving unit
+int getMenuInput(Serial* pcConnection)
 {
     if(pcConnection->readable())
     {
-        pcConnection->printf(pcConnection->getc());
+        char msg = pcConnection->getc();
+        if(msg == 'h')
+        {
+            displayMessage(help, pcConnection);
+        }else if(msg == 'd')
+        {
+            displayMessage(drivingMode, pcConnection);
+            isDriving = true;
+            return 2;
+        }else if(msg == 'v')
+        {
+            displayMessage(voltage, pcConnection, getVoltage(&voltagePin));
+        }
+    }
+    return 0;
+}
+void getDrivingModeInput(Serial* pcConnection)
+{
+    if(pcConnection->readable() && isDriving)
+    {
+        while(isDriving)
+        {
+            char msg = pcConnection->getc();
+            if(msg == 'f')
+            {
+                
+            }else if(msg == 'e')
+            {
+                isDriving = false;
+                break;
+                displayPrompt(pcConnection);
+            }
+        }
     }
 }
 #endif // SERIALPROMPT_H
\ No newline at end of file