-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelp.cpp
84 lines (82 loc) · 2.86 KB
/
help.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "arduino_cli.h"
/**
* Display general or command-specific help
*/
void help(String *cmdPtr) {
if(cmdPtr == NULL) {
// CONDITION: Command name isn't specified
Serial.println("Available Commands:");
Serial.println("get ----- Get input from a digital/analog pin");
Serial.println("set ----- Set output to a digital/analog pin");
Serial.println("tail ---- Keep reading input from digital/analog pin");
#ifdef HAVE_HWSERIAL1
// Only for boards with multiple Serial HW
Serial.println("send ---- Send data to another Serial Port");
Serial.println("listen -- Listen for another Serial Port");
#endif
Serial.println("help ---- Show information about available commands");
Serial.println("");
Serial.println("Run this command for details: help <command_name>");
Serial.println("");
} else {
// CONDITION: Command name specified
// Get only command name
String cmd = "";
for(int i = 0; i < cmdPtr->length(); i++) {
char eachChar = cmdPtr->charAt(i);
if(eachChar == ' ') break;
cmd += eachChar;
}
// Parse command name
if(cmd == "get") {
Serial.println("USAGE: get <pin_ID>");
Serial.println("");
} else if(cmd == "set") {
Serial.println("USAGE: set <pin_ID> <on|off|number_values>");
Serial.println("");
} else if(cmd == "tail") {
Serial.println("USAGE: tail <pin_ID> [interval_ms]");
Serial.println("");
Serial.println("Default:");
Serial.println(" interval_ms = 500");
Serial.println("");
Serial.println("NOTE: Hit enter to stop listening");
Serial.println("");
}
#ifdef HAVE_HWSERIAL1
// Only for boards with multiple Serial HW
else if(cmd == "send") {
Serial.println("USAGE: send <message> [baudrate]");
Serial.println("");
Serial.println("Default:");
Serial.println(" baudrate = 115200");
Serial.println("");
Serial.println("Examples:");
Serial.println(" send hello");
Serial.println(" send \"hello, world!\"");
Serial.println(" send \"first line\\nsecond line\"");
Serial.println(" send 132");
Serial.println(" send 0b10011011");
Serial.println(" send 0x7f");
Serial.println(" send hello 9600");
Serial.println(" send \"hello, world!\" 9600");
Serial.println("");
} else if(cmd == "listen") {
Serial.println("USAGE: listen [baudrate]");
Serial.println("");
Serial.println("Default:");
Serial.println(" baudrate = 115200");
Serial.println("");
Serial.println("NOTE: Hit enter to stop listening");
Serial.println("");
}
#endif
else if(cmd == "help") {
help();
} else {
Serial.println("Command \"" + cmd + "\" not found");
Serial.println("");
help();
}
}
}