Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
include/SerialPrompt.h@5:1afe17a20a5b, 2015-08-13 (annotated)
- Committer:
- overkiller
- Date:
- Thu Aug 13 15:52:19 2015 +0000
- Revision:
- 5:1afe17a20a5b
- Parent:
- 4:cc391b3f3e57
- Child:
- 6:9eb153e1d472
sensor code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| overkiller | 3:def8a92db030 | 1 | #ifndef SERIALPROMPT_H |
| overkiller | 3:def8a92db030 | 2 | #define SERIALPROMPT_H |
| overkiller | 4:cc391b3f3e57 | 3 | #include "EngineDriver.h" |
| overkiller | 4:cc391b3f3e57 | 4 | #include "VoltageGetter.h" |
| overkiller | 3:def8a92db030 | 5 | #include "mbed.h" |
| overkiller | 3:def8a92db030 | 6 | const char* prompt = "$>"; |
| overkiller | 4:cc391b3f3e57 | 7 | const char* help = "h - help d - drive driving unit\n\r v - get input voltage\n\r"; |
| overkiller | 5:1afe17a20a5b | 8 | const char* drivingMode = "Going to driving mode.\n\r Available commands: e - exit from driving mode \n\r"; |
| overkiller | 4:cc391b3f3e57 | 9 | const char* voltage = "Actual voltage: %g \n\r"; |
| overkiller | 4:cc391b3f3e57 | 10 | bool isDriving = false; |
| overkiller | 4:cc391b3f3e57 | 11 | AnalogIn voltagePin(A0); |
| overkiller | 5:1afe17a20a5b | 12 | extern int inState[4]; |
| overkiller | 5:1afe17a20a5b | 13 | extern void applyStates(); |
| overkiller | 3:def8a92db030 | 14 | void displayPrompt(Serial* pcConnection) |
| overkiller | 3:def8a92db030 | 15 | { |
| overkiller | 3:def8a92db030 | 16 | pcConnection->printf(prompt); |
| overkiller | 3:def8a92db030 | 17 | } |
| overkiller | 4:cc391b3f3e57 | 18 | void displayMessage(const char* msg, Serial* pcConnection) |
| overkiller | 4:cc391b3f3e57 | 19 | { |
| overkiller | 4:cc391b3f3e57 | 20 | pcConnection->printf(msg); |
| overkiller | 4:cc391b3f3e57 | 21 | displayPrompt(pcConnection); |
| overkiller | 4:cc391b3f3e57 | 22 | } |
| overkiller | 4:cc391b3f3e57 | 23 | void displayMessage(const char* msg, Serial* pcConnection, float number) |
| overkiller | 4:cc391b3f3e57 | 24 | { |
| overkiller | 4:cc391b3f3e57 | 25 | pcConnection->printf(msg, number); |
| overkiller | 4:cc391b3f3e57 | 26 | displayPrompt(pcConnection); |
| overkiller | 4:cc391b3f3e57 | 27 | } |
| overkiller | 4:cc391b3f3e57 | 28 | /// |
| overkiller | 4:cc391b3f3e57 | 29 | /// 0 - not known command |
| overkiller | 4:cc391b3f3e57 | 30 | /// 2 - drive the driving unit |
| overkiller | 4:cc391b3f3e57 | 31 | int getMenuInput(Serial* pcConnection) |
| overkiller | 3:def8a92db030 | 32 | { |
| overkiller | 3:def8a92db030 | 33 | if(pcConnection->readable()) |
| overkiller | 3:def8a92db030 | 34 | { |
| overkiller | 4:cc391b3f3e57 | 35 | char msg = pcConnection->getc(); |
| overkiller | 4:cc391b3f3e57 | 36 | if(msg == 'h') |
| overkiller | 4:cc391b3f3e57 | 37 | { |
| overkiller | 4:cc391b3f3e57 | 38 | displayMessage(help, pcConnection); |
| overkiller | 4:cc391b3f3e57 | 39 | }else if(msg == 'd') |
| overkiller | 4:cc391b3f3e57 | 40 | { |
| overkiller | 4:cc391b3f3e57 | 41 | displayMessage(drivingMode, pcConnection); |
| overkiller | 5:1afe17a20a5b | 42 | isDriving = true; |
| overkiller | 4:cc391b3f3e57 | 43 | return 2; |
| overkiller | 4:cc391b3f3e57 | 44 | }else if(msg == 'v') |
| overkiller | 4:cc391b3f3e57 | 45 | { |
| overkiller | 4:cc391b3f3e57 | 46 | displayMessage(voltage, pcConnection, getVoltage(&voltagePin)); |
| overkiller | 5:1afe17a20a5b | 47 | return 3; |
| overkiller | 4:cc391b3f3e57 | 48 | } |
| overkiller | 4:cc391b3f3e57 | 49 | } |
| overkiller | 4:cc391b3f3e57 | 50 | return 0; |
| overkiller | 4:cc391b3f3e57 | 51 | } |
| overkiller | 5:1afe17a20a5b | 52 | |
| overkiller | 3:def8a92db030 | 53 | #endif // SERIALPROMPT_H |