Skip to content

Commit 7c65a0a

Browse files
Update to 4.1.0
Added a userString system so that the user can include a String that is printed in help and query commands. The string can contain a device or product name, firmware version etc ...
1 parent 2f64bbe commit 7c65a0a

File tree

9 files changed

+37
-15
lines changed

9 files changed

+37
-15
lines changed

Changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Commander changelog
22
(Changelog started at 1.2.3)
33

4+
4.1.0
5+
6+
Added setUserString(&String) and printUserString(). A String can be created with user defined information, for example a product name, web URL and firmware version. This String will be printed at the start of the help page and status query page (the '?' command). This allows the user to incorporate their own device or product information into the command system. The string can be formatted however the user wants, including with newlines, tabs etc, and will be printed exactly as is - Other help page items print the comment characterat the start of each line, if the user wants the user String to also appear as comment lines then they need to incorporate the comment characters in the String themselves.
7+
Updated test suite sketch with example use.
8+
49
Commander 4.0.0 - Method act
510

611
Method CHAIN'O'RAMA! All methods that used to return void now return a *this reference allowing them to be chained.

examples/BasicCommands/BasicCommands.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ Commander cmd;
66
//Variables we can set or get
77
int myInt = 0;
88
float myFloat = 0.0;
9+
10+
String deviceInfo = "#\tCommander basic commands example\n#\thttps://github.com/CreativeRobotics/Commander";
911
//SETUP ---------------------------------------------------------------------------
1012
void setup() {
1113
Serial.begin(115200);
1214
initialiseCommander();
1315
while(!Serial){;}
14-
Serial.println("Hello: Type 'help' to get help");
16+
cmd.printUserString();
17+
cmd.println();
18+
Serial.println("Type 'help' to get help");
1519
cmd.printCommandPrompt();
1620
}
1721

examples/BasicCommands/masterCommands.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void initialiseCommander(){
2727
cmd.echo(true); //Echo incoming characters to theoutput port
2828
cmd.errorMessages(ON); //error messages are enabled - it will tell us if we issue any unrecognised commands
2929
cmd.autoChain(ON);
30+
cmd.setUserString(deviceInfo);
3031
}
3132

3233
//These are the command handlers, there needs to be one for each command in the command array myCommands[]

examples/TEST_SUITE1/TEST_SUITE1.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ float myFloat1, myFloat2;
99
float myFloat = 0.0;
1010
String myString1 = "";
1111
String myString2 = "";
12+
//User string - this can be anything you want, and is printed when the help and ? commands are used
13+
//Its a good idea to put the # symbol in front of each line so that if the response to these commands is fet to another commander, they will be interpreted as comments.
14+
String deviceInfo = "#\t(Start of user string)\n#\tCommander test suite\n#\tDevice firmware version 1.0.0 revision x\n#\thttps://github.com/CreativeRobotics/Commander\n#\t(End of user string)";
1215
//SETUP ---------------------------------------------------------------------------
1316
void setup() {
1417
Serial.begin(115200);
1518
while(!Serial){;}
1619
initialiseCommander();
17-
Serial.println("Hello: Type 'help' to get help");
20+
cmd.printUserString();
21+
cmd.println();
22+
Serial.println("Type 'help' to get help");
1823
cmd.printCommandPrompt();
1924
}
2025

examples/TEST_SUITE1/masterCommands.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ bool myFunc(Commander &Cmdr){
2828

2929
//Initialisation function that avoids having to forward declare the command array and a size variable.
3030
void initialiseCommander(){
31-
cmd.begin(&Serial, masterCommands, sizeof(masterCommands));
32-
cmd.commandPrompt(ON); //enable the command prompt
33-
cmd.echo(true); //Echo incoming characters to theoutput port
34-
cmd.errorMessages(ON); //error messages are enabled - it will tell us if we issue any unrecognised commands
35-
cmd.autoChain(ON);
31+
cmd.begin(&Serial, masterCommands, sizeof(masterCommands))
32+
.commandPrompt(ON)
33+
.echo(true)
34+
.errorMessages(ON)
35+
.autoChain(ON)
36+
.setUserString(deviceInfo);
3637
}
3738

3839

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ update KEYWORD2
1515
printCommands KEYWORD2
1616
setPassPhrase KEYWORD2
1717
printPassPhrase KEYWORD2
18+
setUserString KEYWORD2
19+
printUserString KEYWORD2
1820
lock KEYWORD2
1921
unlock KEYWORD2
2022
setLockType KEYWORD2

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Commander
2-
version=4.0.0
2+
version=4.1.0
33
author=Bill Bigge
44
maintainer=Bill Bigge <[email protected]>
55
sentence=Command line library for Arduino.

src/Commander.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,8 @@ bool Commander::isEndOfCommand(char dataByte){
13121312

13131313

13141314
Commander& Commander::printCommandList(){
1315-
//Prints all the commands
1315+
//Prints all the commands, start with the user string if it exists
1316+
if(userString != NULL) println(*userString);
13161317
uint8_t n = 0;
13171318
String cmdLine = String(commentCharacter);
13181319
cmdLine.concat(commanderName);
@@ -1354,7 +1355,8 @@ String Commander::getWhiteSpace(uint8_t spaces){
13541355
//==============================================================================================================
13551356

13561357
Commander& Commander::printCommanderVersion(){
1357-
1358+
//add user string printing. This comes first because the users version number and other info might be more important than Commander ...
1359+
if(userString != NULL) println(*userString);
13581360
write(commentCharacter);
13591361
print(F("\tCommander version "));
13601362
print(majorVersion);

src/Commander.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ typedef union {
9393
// 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
9494
//default is 0b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 0 0
9595
//const String CommanderVersionNumber = "3.0.0";
96-
const uint8_t majorVersion = 3;
97-
const uint8_t minorVersion = 3;
96+
const uint8_t majorVersion = 4;
97+
const uint8_t minorVersion = 1;
9898
const uint8_t subVersion = 0;
9999

100100
typedef enum streamType_t{
@@ -171,6 +171,8 @@ class Commander{
171171
bool update();
172172
Commander& setPassPhrase(String& phrase) {passPhrase = &phrase; return *this;}
173173
Commander& printPassPhrase() {print(*passPhrase); return *this;}
174+
Commander& setUserString(String& str) {userString = &str; return *this;}
175+
Commander& printUserString() {print(*userString); return *this;}
174176
Commander& lock() {ports.settings.bit.locked = true; return *this;}
175177
Commander& unlock() {ports.settings.bit.locked = false; return *this;}
176178
Commander& setLockType(bool hlState) {ports.settings.bit.useHardLock = hlState; return *this;}
@@ -182,7 +184,7 @@ class Commander{
182184
String getPayloadString();
183185
bool feedString(String newString);
184186
Commander& loadString(String newString);
185-
Commander& setPending(bool pState) {commandState.bit.isCommandPending = pState;} //sets the pending command bit - used if manually writing to the buffer
187+
Commander& setPending(bool pState) {commandState.bit.isCommandPending = pState; return *this;} //sets the pending command bit - used if manually writing to the buffer
186188
Commander& write(uint8_t character) {bufferString += character; return *this;}
187189
bool endLine();
188190
Commander& startStreaming() {commandState.bit.dataStreamOn = true; return *this;} //set the streaming function ON
@@ -510,7 +512,7 @@ class Commander{
510512
uint8_t getInternalCmdLength(const char intCmd[]);
511513
//utility to print the buffer contents as integer values
512514
void printBuffer(){
513-
for(int n = 0; n < bufferString.length(); n++){
515+
for(uint32_t n = 0; n < bufferString.length(); n++){
514516
write('[');
515517
print((int)bufferString.charAt(n));
516518
write(']');
@@ -541,7 +543,7 @@ class Commander{
541543
uint16_t dataReadIndex = 0; //for parsing many numbers
542544
const char* internalCommandArray[INTERNAL_COMMAND_ITEMS];
543545
String *passPhrase = NULL;
544-
546+
String *userString = NULL;
545547
uint8_t primntDelayTime = 0; //
546548
};
547549

0 commit comments

Comments
 (0)