Skip to content

Commit 5869c80

Browse files
Fix compiler warnings
Update to 4.2.3 to fix some compiler warnings
1 parent 32877c5 commit 5869c80

File tree

10 files changed

+67
-63
lines changed

10 files changed

+67
-63
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.2.3
5+
Update *char to const *char to remove compiler warnings.
6+
Update some examples to remove casting from const *char to *char.
7+
Removed ideosyncratic spellings from examples.
8+
49
4.2.2
510
Updated to 4.2.2 because I messed up the last releases on Github. Needs a whole new release tag to fix.
611

examples/Advanced/CommandTextChange/masterCommands.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ String exHelpStr = "This is the extended help text for this command. It can be c
66
String cmdStr = "test";
77

88
commandList_t masterCommands[] = {
9-
{(char*)cmdStr.c_str(), helloHandler, (char*)helpStr.c_str()},
9+
{cmdStr.c_str(), helloHandler, helpStr.c_str()},
1010
{"set help", setStringHandler, "Set help text for the first command"},
1111
{"set extra help", setExtraStringHandler, "Set extended help for first command"},
1212
{"set command", setCommandHandler, "Set command text for the first command"},
1313
};
1414

1515

16-
char * extraHelp[] = {
16+
const char * extraHelp[] = {
1717
(char*)exHelpStr.c_str(),
1818
"'set help'\tSet the text that will display for the normal help of the first command.\nMake sure you don't exceed Commander buffer size!",
1919
"'set extra help'\tSet the text that will display for the extended help of the first command.\nMake sure you don't exceed Commander buffer size!",
@@ -56,7 +56,7 @@ bool setStringHandler(Commander &Cmdr){
5656
if(Cmdr.hasPayload()){
5757
helpStr = Cmdr.getPayloadString();
5858
//The pointer may have changed so get a new one
59-
masterCommands[0].manualString = (char*)helpStr.c_str();
59+
masterCommands[0].manualString = helpStr.c_str();
6060
Cmdr.print("Help string changed to:");
6161
Cmdr.println(helpStr);
6262
}
@@ -74,7 +74,7 @@ bool setExtraStringHandler(Commander &Cmdr){
7474
if(Cmdr.hasPayload()){
7575
exHelpStr = Cmdr.getPayloadString();
7676
//The pointer may have changed so get a new one
77-
extraHelp[0] = (char*)exHelpStr.c_str();
77+
extraHelp[0] = exHelpStr.c_str();
7878
Cmdr.print("Extended help string changed to:");
7979
Cmdr.println(exHelpStr);
8080
}
@@ -92,7 +92,7 @@ bool setCommandHandler(Commander &Cmdr){
9292
if(Cmdr.hasPayload()){
9393
cmdStr = Cmdr.getPayloadString();
9494
//The pointer may have changed so get a new one
95-
masterCommands[0].commandString = (char*)cmdStr.c_str();
95+
masterCommands[0].commandString = cmdStr.c_str();
9696
Cmdr.print("Command string changed to:");
9797
Cmdr.println(cmdStr);
9898
Cmdr.reloadCommands();

examples/Advanced/FunctionSwap/FunctionSwap.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
#include <Commander.h>
55
Commander cmd;
6-
bool swopstate = 0;
6+
bool swapstate = 0;
77
//User string - this can be anything you want, and is printed when the help and ? commands are used
88
//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.
99
String deviceInfo = "#\t(Start of user string)\n#\tCommander swop function example\n#\tDevice firmware version x.x.x revision x\n#\thttps://github.com/CreativeRobotics/Commander\n#\t(End of user string)";

examples/Advanced/FunctionSwap/masterCommands.ino

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ const char* otherCommand = "bonjour";
1414
const char* otherHelp = "saluer";
1515

1616
commandList_t masterCommands[] = {
17-
{(char*)normalCommand, helloHandler, (char*)normalHelp},
18-
{"swop", swopHandler, "swop the command strings and function handler"},
17+
{normalCommand, helloHandler, normalHelp},
18+
{"swap", swapHandler, "swap the command strings and function handler"},
1919
};
2020

2121
//Extended help text. This is an array of pointers to strings so we can assign one of the char arrays from above, and use the swop function to change the text.
2222
//(There needs to me the same number of elements in this array as in the command list.)
23-
char * extraHelp[] = {
24-
(char*)extendedHelp,
25-
"'swop'\tSwap between two different function handlers for the first command.\nWhen this is called the function handler, command text and help text for the first command in the list will be swapped.",
23+
const char * extraHelp[] = {
24+
extendedHelp,
25+
"'swap'\tSwap between two different function handlers for the first command.\nWhen this is called the function handler, command text and help text for the first command in the list will be swapped.",
2626
};
2727
/* Command handler template
2828
bool myFunc(Commander &Cmdr){
@@ -61,21 +61,21 @@ bool bonjourHandler(Commander &Cmdr){
6161
return 0;
6262
}
6363

64-
bool swopHandler(Commander &Cmdr){
64+
bool swapHandler(Commander &Cmdr){
6565
Cmdr.println("Swapping command handler");
66-
if(swopstate){
66+
if(swapstate){
6767
masterCommands[0].handler = helloHandler;
68-
masterCommands[0].commandString = (char*)normalCommand;
69-
masterCommands[0].manualString = (char*)normalHelp;
70-
extraHelp[0] = (char*)extendedHelp;
68+
masterCommands[0].commandString = normalCommand;
69+
masterCommands[0].manualString = normalHelp;
70+
extraHelp[0] = extendedHelp;
7171
}else{
7272
masterCommands[0].handler = bonjourHandler;
73-
masterCommands[0].commandString = (char*)otherCommand;
74-
masterCommands[0].manualString = (char*)otherHelp;
75-
extraHelp[0] = (char*)otherExtendedHelp;
73+
masterCommands[0].commandString = otherCommand;
74+
masterCommands[0].manualString = otherHelp;
75+
extraHelp[0] = otherExtendedHelp;
7676
}
7777
//ESSENTIAL: You must call this if the command string text is changed otherwide Commander might not be able to recognise the new command
7878
Cmdr.reloadCommands();
79-
swopstate = !swopstate;
79+
swapstate = !swapstate;
8080
return 0;
8181
}

examples/Advanced/customMenu/masterCommands.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ const char* createHelp = "Create a command list (eg 'create 2 4 3')";
2424

2525
const char* revertCommand = "revert";
2626
const char* revertHelp = "revert to the old list";
27-
commandList_t masterCommands[] = {
28-
{(char*)listCommand, listHandler, (char*)listhelp},
29-
{(char*)createCommand, createHandler, (char*)createHelp},
27+
28+
const commandList_t masterCommands[] = {
29+
{listCommand, listHandler, listhelp},
30+
{createCommand, createHandler, createHelp},
3031
};
3132

3233
commandList_t *newCmds;
@@ -136,9 +137,9 @@ bool createHandler(Commander &Cmdr){
136137
newCmds[n].manualString = getHelp(values[n]);
137138
}
138139
//tack the revert option to the end of the array
139-
newCmds[items].commandString = (char*)revertCommand;
140+
newCmds[items].commandString = revertCommand;
140141
newCmds[items].handler = revertHandler;
141-
newCmds[items].manualString = (char*)revertHelp;
142+
newCmds[items].manualString = revertHelp;
142143
//Attach it to commander using the attachCommandArray method
143144
Cmdr.attachCommandArray(newCmds, items+1);
144145
Cmdr.println("New command list created and activated");

examples/Advanced/customMenu_Static/masterCommands.ino

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@ const char* commandList[numberOfCommands] = {
3535

3636

3737
const char* helpList[numberOfCommands] = {
38-
"helpy text for command sprif",
39-
"helpy text for command sprif",
40-
"helpy text for command sprif",
41-
"helpy text for command sprif",
42-
"helpy text for command sprif",
43-
"helpy text for command sprif",
44-
"helpy text for command sprif",
45-
"helpy text for command sprif",
46-
"helpy text for command sprif",
47-
"helpy text for command sprif",
48-
"helpy text for command sprif",
49-
"helpy text for command sprif",
50-
"helpy text for command sprif",
51-
"helpy text for command sprif",
52-
"helpy text for command sprif",
53-
"helpy text for command sprif",
54-
"helpy text for command sprif",
55-
"helpy text for command sprif",
56-
"helpy text for command sprif",
57-
"helpy text for command sprif",
58-
"helpy text for command sprif",
59-
"helpy text for command sprif",
60-
"helpy text for command sprif",
61-
"helpy text for command sprif",
38+
"help text for command cmd0",
39+
"help text for command cmd1",
40+
"help text for command cmd2",
41+
"help text for command cmd3",
42+
"help text for command cmd4",
43+
"help text for command cmd5",
44+
"help text for command cmd6",
45+
"help text for command cmd7",
46+
"help text for command cmd8",
47+
"help text for command cmd9",
48+
"help text for command cmd10",
49+
"help text for command cmd11",
50+
"help text for command cmd12",
51+
"help text for command cmd13",
52+
"help text for command cmd14",
53+
"help text for command cmd15",
54+
"help text for command cmd16",
55+
"help text for command cmd17",
56+
"help text for command cmd18",
57+
"help text for command cmd19",
58+
"help text for command cmd20",
59+
"help text for command cmd21",
60+
"help text for command cmd22",
61+
"help text for command cmd23",
6262
};
6363

6464

@@ -91,15 +91,15 @@ cmdHandler handlers[numberOfCommands] = {
9191
Handler23,
9292
};
9393

94-
commandList_t startupCommands[] = {
94+
const commandList_t startupCommands[] = {
9595
{"add", addHandler, "Add a command (add [handlerNo])"},
9696
{"finish", finishHandler, "Finish adding commands and load the list"},
9797
};
9898

9999
//uninitialised array to be filled
100100
commandList_t myCommands[maxItems];
101101

102-
commandList_t *newCmds;
102+
103103
/* Command handler template
104104
bool myFunc(Commander &Cmdr){
105105
//put your command handler code here
@@ -242,9 +242,9 @@ bool addHandler(Commander &Cmdr){
242242
}
243243
if(Cmdr.getInt(itemID)){
244244
if(itemID > -1 && itemID < numberOfCommands){
245-
myCommands[commandCount].commandString = (char*)commandList[itemID];
245+
myCommands[commandCount].commandString = commandList[itemID];
246246
myCommands[commandCount].handler = handlers[itemID];
247-
myCommands[commandCount].manualString = (char*)helpList[itemID];
247+
myCommands[commandCount].manualString = helpList[itemID];
248248
Cmdr.print("Added the command ");
249249
Cmdr.print(commandList[itemID]);
250250
Cmdr.print(" as menu item ");

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.2.2
2+
version=4.2.3
33
author=Bill Bigge
44
maintainer=Bill Bigge <bbigge@gmail.com>
55
sentence=Command line library for Arduino.

src/Commander.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Commander::Commander(){
55
bufferString.reserve(bufferSize);
66
ports.settings.reg = COMMANDER_DEFAULT_REGISTER_SETTINGS;
77
commandState.reg = COMMANDER_DEFAULT_STATE_SETTINGS;
8-
9-
108
}
119
//==============================================================================================================
1210
Commander::Commander(uint16_t reservedBuffer){

src/Commander.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Commander;
1111

1212
const uint8_t majorVersion = 4;
1313
const uint8_t minorVersion = 2;
14-
const uint8_t subVersion = 2;
14+
const uint8_t subVersion = 3;
1515

1616

1717
//#define BENCHMARKING_ON
@@ -34,9 +34,9 @@ typedef bool (*cmdHandler)(Commander& Cmdr); //command handler function pointer
3434
//Command handler array type - contains command string and function pointer
3535

3636
typedef struct commandList_t{
37-
char* commandString;
37+
const char* commandString;
3838
cmdHandler handler;
39-
char* manualString;
39+
const char* manualString;
4040
} commandList_t;
4141

4242
//extern const commandList_t myCommands[];
@@ -175,7 +175,7 @@ class Commander : public Stream {
175175
Commander& printPassPhrase() {print(*passPhrase); return *this;}
176176
Commander& setUserString(String& str) {userString = &str; return *this;}
177177
Commander& printUserString() {print(*userString); return *this;}
178-
Commander& setExtraHelp(char* ptr[]) {extraHelp = ptr; return *this;}
178+
Commander& setExtraHelp(const char* ptr[]){extraHelp = ptr; return *this;}
179179
Commander& lock() {ports.settings.bit.locked = true; return *this;}
180180
Commander& unlock() {ports.settings.bit.locked = false; return *this;}
181181
Commander& setLockType(bool hlState) {ports.settings.bit.useHardLock = hlState; return *this;}
@@ -216,7 +216,7 @@ class Commander : public Stream {
216216
Commander& setStreamType(streamType_t newType) {ports.settings.bit.streamType = (uint16_t)newType; return *this;}
217217
streamType_t getStreamType() {return (streamType_t)ports.settings.bit.streamType;}
218218

219-
Commander& reloadCommands() {computeLengths(); return *this;}
219+
Commander& reloadCommands() {computeLengths(); return *this;}
220220

221221
int quick(String cmd);
222222
Commander& quickSetHelp();
@@ -490,7 +490,7 @@ class Commander : public Stream {
490490
int16_t commandIndex = -1;
491491
uint8_t* commandLengths;
492492
uint8_t endIndexOfLastCommand = 0;
493-
char** extraHelp;
493+
const char** extraHelp;
494494
uint8_t longestCommand = 0;
495495
char commentCharacter = '#'; //marks a line as a comment - ignored by the command parser
496496
char reloadCommandCharacter = '/'; //send this character to automatically reprocess the old buffer - same as resending the last command from the users POV.

src/utilities/CommandHelpTags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ bool getCommandArgCode(char helpText[], cmdArgs_t commandArguments){
88
int16_t lastBracket = -1;
99
uint8_t idx = 0;
1010
//find the opening and closing brackets
11-
while(helpText[idx] != NULL){
11+
while(helpText[idx] != '\0'){
1212
//step through the help string
1313
if(helpText[idx] == CMD_ARG_START_BRACKET){
1414
if(idx > 1) break; //if the bracket is not in the 1st or 2nd place, exit.

0 commit comments

Comments
 (0)