skm
Fork of Hello_FXOS8700Q by
cli.cpp@7:4c834e4dad1f, 2015-06-18 (annotated)
- Committer:
- marcus255
- Date:
- Thu Jun 18 16:25:26 2015 +0000
- Revision:
- 7:4c834e4dad1f
skm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcus255 | 7:4c834e4dad1f | 1 | #include "cli.h" |
marcus255 | 7:4c834e4dad1f | 2 | |
marcus255 | 7:4c834e4dad1f | 3 | void commandService (command *commandStruct){ |
marcus255 | 7:4c834e4dad1f | 4 | int space = 0; |
marcus255 | 7:4c834e4dad1f | 5 | char c; |
marcus255 | 7:4c834e4dad1f | 6 | while ((c = getchar()) != char(13)){ // reads chars until you hit enter |
marcus255 | 7:4c834e4dad1f | 7 | putchar(c); // prints received chars to make echo on console |
marcus255 | 7:4c834e4dad1f | 8 | if (c == ' ') { c = getchar(); putchar(c); space++; } |
marcus255 | 7:4c834e4dad1f | 9 | if (space == 0) { commandStruct->commandName += c; } // if no space occured, place chars in commandName field |
marcus255 | 7:4c834e4dad1f | 10 | else if (space == 1){ commandStruct->commandArg += c; } // if one space occured, place chars in commandArg field |
marcus255 | 7:4c834e4dad1f | 11 | else { commandStruct->commandValue += c; } // if two spaces occured, place chars in commandValue field |
marcus255 | 7:4c834e4dad1f | 12 | } |
marcus255 | 7:4c834e4dad1f | 13 | } |
marcus255 | 7:4c834e4dad1f | 14 | |
marcus255 | 7:4c834e4dad1f | 15 | void commandValidate(command *commandStruct){ |
marcus255 | 7:4c834e4dad1f | 16 | int val; |
marcus255 | 7:4c834e4dad1f | 17 | if (commandStruct->commandName == "accel"){ |
marcus255 | 7:4c834e4dad1f | 18 | if (commandStruct->commandArg == "threshold"){ |
marcus255 | 7:4c834e4dad1f | 19 | val = atoi((commandStruct->commandValue).c_str()); |
marcus255 | 7:4c834e4dad1f | 20 | if (val > 0 && val < 8000){ |
marcus255 | 7:4c834e4dad1f | 21 | threshold = val; |
marcus255 | 7:4c834e4dad1f | 22 | pc.printf("\rthreshold set to %s mg",commandStruct->commandValue); |
marcus255 | 7:4c834e4dad1f | 23 | } |
marcus255 | 7:4c834e4dad1f | 24 | else { pc.printf("\rInvalid value \'%s\'. Valid value range: <1-7999>",commandStruct->commandValue); } |
marcus255 | 7:4c834e4dad1f | 25 | } |
marcus255 | 7:4c834e4dad1f | 26 | else if (commandStruct->commandArg == "help") { pc.printf("\rAvailable arguments for %s are: threshold [value]",commandStruct->commandName); } |
marcus255 | 7:4c834e4dad1f | 27 | else { pc.printf("\rUnrecognized argument \'%s\'",commandStruct->commandArg); } |
marcus255 | 7:4c834e4dad1f | 28 | } |
marcus255 | 7:4c834e4dad1f | 29 | else if (commandStruct->commandName == "delay"){ |
marcus255 | 7:4c834e4dad1f | 30 | if (commandStruct->commandArg == "set"){ |
marcus255 | 7:4c834e4dad1f | 31 | val = atoi((commandStruct->commandValue).c_str()); |
marcus255 | 7:4c834e4dad1f | 32 | if (val > 0 && val < 2001){ |
marcus255 | 7:4c834e4dad1f | 33 | msDelay = val; |
marcus255 | 7:4c834e4dad1f | 34 | pc.printf("\rMeasurement delay set to %d ms", val); |
marcus255 | 7:4c834e4dad1f | 35 | } |
marcus255 | 7:4c834e4dad1f | 36 | else { pc.printf("\rInvalid value \'%s\'. Valid values are <1-2000>", commandStruct->commandValue); } |
marcus255 | 7:4c834e4dad1f | 37 | } |
marcus255 | 7:4c834e4dad1f | 38 | else if (commandStruct->commandArg == "help") { pc.printf("\rAvailable arguments for %s are: set [value]",commandStruct->commandName); } |
marcus255 | 7:4c834e4dad1f | 39 | else { pc.printf("\rUnrecognized argument \'%s\'",commandStruct->commandArg); } |
marcus255 | 7:4c834e4dad1f | 40 | } |
marcus255 | 7:4c834e4dad1f | 41 | else if (commandStruct->commandName == "help"){ pc.printf("\rAvailable commands: accel, delay"); } |
marcus255 | 7:4c834e4dad1f | 42 | else { pc.printf("\rUnrecognized command \'%s\'",commandStruct->commandName); } |
marcus255 | 7:4c834e4dad1f | 43 | } |
marcus255 | 7:4c834e4dad1f | 44 | |
marcus255 | 7:4c834e4dad1f | 45 | void clearConsole(void){ |
marcus255 | 7:4c834e4dad1f | 46 | printf("\r"); |
marcus255 | 7:4c834e4dad1f | 47 | for (int i = 0; i < 64; i++) { printf(" "); } |
marcus255 | 7:4c834e4dad1f | 48 | printf("\r"); |
marcus255 | 7:4c834e4dad1f | 49 | } |