diff --git a/Changelog.txt b/Changelog.txt index 59cc6ab..6d25d39 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,6 +1,11 @@ Commander changelog (Changelog started at 1.2.3) +4.2.3 +Update *char to const *char to remove compiler warnings. +Update some examples to remove casting from const *char to *char. +Removed ideosyncratic spellings from examples. + 4.2.2 Updated to 4.2.2 because I messed up the last releases on Github. Needs a whole new release tag to fix. diff --git a/examples/Advanced/CommandTextChange/masterCommands.ino b/examples/Advanced/CommandTextChange/masterCommands.ino index a2e722d..10ce977 100644 --- a/examples/Advanced/CommandTextChange/masterCommands.ino +++ b/examples/Advanced/CommandTextChange/masterCommands.ino @@ -6,14 +6,14 @@ String exHelpStr = "This is the extended help text for this command. It can be c String cmdStr = "test"; commandList_t masterCommands[] = { - {(char*)cmdStr.c_str(), helloHandler, (char*)helpStr.c_str()}, + {cmdStr.c_str(), helloHandler, helpStr.c_str()}, {"set help", setStringHandler, "Set help text for the first command"}, {"set extra help", setExtraStringHandler, "Set extended help for first command"}, {"set command", setCommandHandler, "Set command text for the first command"}, }; -char * extraHelp[] = { +const char * extraHelp[] = { (char*)exHelpStr.c_str(), "'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!", "'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){ if(Cmdr.hasPayload()){ helpStr = Cmdr.getPayloadString(); //The pointer may have changed so get a new one - masterCommands[0].manualString = (char*)helpStr.c_str(); + masterCommands[0].manualString = helpStr.c_str(); Cmdr.print("Help string changed to:"); Cmdr.println(helpStr); } @@ -74,7 +74,7 @@ bool setExtraStringHandler(Commander &Cmdr){ if(Cmdr.hasPayload()){ exHelpStr = Cmdr.getPayloadString(); //The pointer may have changed so get a new one - extraHelp[0] = (char*)exHelpStr.c_str(); + extraHelp[0] = exHelpStr.c_str(); Cmdr.print("Extended help string changed to:"); Cmdr.println(exHelpStr); } @@ -92,7 +92,7 @@ bool setCommandHandler(Commander &Cmdr){ if(Cmdr.hasPayload()){ cmdStr = Cmdr.getPayloadString(); //The pointer may have changed so get a new one - masterCommands[0].commandString = (char*)cmdStr.c_str(); + masterCommands[0].commandString = cmdStr.c_str(); Cmdr.print("Command string changed to:"); Cmdr.println(cmdStr); Cmdr.reloadCommands(); diff --git a/examples/Advanced/FunctionSwap/FunctionSwap.ino b/examples/Advanced/FunctionSwap/FunctionSwap.ino index d31b732..4ea0c48 100644 --- a/examples/Advanced/FunctionSwap/FunctionSwap.ino +++ b/examples/Advanced/FunctionSwap/FunctionSwap.ino @@ -3,7 +3,7 @@ */ #include Commander cmd; -bool swopstate = 0; +bool swapstate = 0; //User string - this can be anything you want, and is printed when the help and ? commands are used //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. 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)"; diff --git a/examples/Advanced/FunctionSwap/masterCommands.ino b/examples/Advanced/FunctionSwap/masterCommands.ino index 06394d6..b9a9f77 100644 --- a/examples/Advanced/FunctionSwap/masterCommands.ino +++ b/examples/Advanced/FunctionSwap/masterCommands.ino @@ -14,15 +14,15 @@ const char* otherCommand = "bonjour"; const char* otherHelp = "saluer"; commandList_t masterCommands[] = { - {(char*)normalCommand, helloHandler, (char*)normalHelp}, - {"swop", swopHandler, "swop the command strings and function handler"}, + {normalCommand, helloHandler, normalHelp}, + {"swap", swapHandler, "swap the command strings and function handler"}, }; //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. //(There needs to me the same number of elements in this array as in the command list.) -char * extraHelp[] = { - (char*)extendedHelp, - "'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.", +const char * extraHelp[] = { + extendedHelp, + "'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.", }; /* Command handler template bool myFunc(Commander &Cmdr){ @@ -61,21 +61,21 @@ bool bonjourHandler(Commander &Cmdr){ return 0; } -bool swopHandler(Commander &Cmdr){ +bool swapHandler(Commander &Cmdr){ Cmdr.println("Swapping command handler"); - if(swopstate){ + if(swapstate){ masterCommands[0].handler = helloHandler; - masterCommands[0].commandString = (char*)normalCommand; - masterCommands[0].manualString = (char*)normalHelp; - extraHelp[0] = (char*)extendedHelp; + masterCommands[0].commandString = normalCommand; + masterCommands[0].manualString = normalHelp; + extraHelp[0] = extendedHelp; }else{ masterCommands[0].handler = bonjourHandler; - masterCommands[0].commandString = (char*)otherCommand; - masterCommands[0].manualString = (char*)otherHelp; - extraHelp[0] = (char*)otherExtendedHelp; + masterCommands[0].commandString = otherCommand; + masterCommands[0].manualString = otherHelp; + extraHelp[0] = otherExtendedHelp; } //ESSENTIAL: You must call this if the command string text is changed otherwide Commander might not be able to recognise the new command Cmdr.reloadCommands(); - swopstate = !swopstate; + swapstate = !swapstate; return 0; } diff --git a/examples/Advanced/customMenu/masterCommands.ino b/examples/Advanced/customMenu/masterCommands.ino index c5aec6e..c40a226 100644 --- a/examples/Advanced/customMenu/masterCommands.ino +++ b/examples/Advanced/customMenu/masterCommands.ino @@ -24,9 +24,10 @@ const char* createHelp = "Create a command list (eg 'create 2 4 3')"; const char* revertCommand = "revert"; const char* revertHelp = "revert to the old list"; -commandList_t masterCommands[] = { - {(char*)listCommand, listHandler, (char*)listhelp}, - {(char*)createCommand, createHandler, (char*)createHelp}, + +const commandList_t masterCommands[] = { + {listCommand, listHandler, listhelp}, + {createCommand, createHandler, createHelp}, }; commandList_t *newCmds; @@ -136,9 +137,9 @@ bool createHandler(Commander &Cmdr){ newCmds[n].manualString = getHelp(values[n]); } //tack the revert option to the end of the array - newCmds[items].commandString = (char*)revertCommand; + newCmds[items].commandString = revertCommand; newCmds[items].handler = revertHandler; - newCmds[items].manualString = (char*)revertHelp; + newCmds[items].manualString = revertHelp; //Attach it to commander using the attachCommandArray method Cmdr.attachCommandArray(newCmds, items+1); Cmdr.println("New command list created and activated"); diff --git a/examples/Advanced/customMenu_Static/masterCommands.ino b/examples/Advanced/customMenu_Static/masterCommands.ino index 2691c72..0b93bd6 100644 --- a/examples/Advanced/customMenu_Static/masterCommands.ino +++ b/examples/Advanced/customMenu_Static/masterCommands.ino @@ -35,30 +35,30 @@ const char* commandList[numberOfCommands] = { const char* helpList[numberOfCommands] = { - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", - "helpy text for command sprif", + "help text for command cmd0", + "help text for command cmd1", + "help text for command cmd2", + "help text for command cmd3", + "help text for command cmd4", + "help text for command cmd5", + "help text for command cmd6", + "help text for command cmd7", + "help text for command cmd8", + "help text for command cmd9", + "help text for command cmd10", + "help text for command cmd11", + "help text for command cmd12", + "help text for command cmd13", + "help text for command cmd14", + "help text for command cmd15", + "help text for command cmd16", + "help text for command cmd17", + "help text for command cmd18", + "help text for command cmd19", + "help text for command cmd20", + "help text for command cmd21", + "help text for command cmd22", + "help text for command cmd23", }; @@ -91,7 +91,7 @@ cmdHandler handlers[numberOfCommands] = { Handler23, }; -commandList_t startupCommands[] = { +const commandList_t startupCommands[] = { {"add", addHandler, "Add a command (add [handlerNo])"}, {"finish", finishHandler, "Finish adding commands and load the list"}, }; @@ -99,7 +99,7 @@ commandList_t startupCommands[] = { //uninitialised array to be filled commandList_t myCommands[maxItems]; -commandList_t *newCmds; + /* Command handler template bool myFunc(Commander &Cmdr){ //put your command handler code here @@ -242,9 +242,9 @@ bool addHandler(Commander &Cmdr){ } if(Cmdr.getInt(itemID)){ if(itemID > -1 && itemID < numberOfCommands){ - myCommands[commandCount].commandString = (char*)commandList[itemID]; + myCommands[commandCount].commandString = commandList[itemID]; myCommands[commandCount].handler = handlers[itemID]; - myCommands[commandCount].manualString = (char*)helpList[itemID]; + myCommands[commandCount].manualString = helpList[itemID]; Cmdr.print("Added the command "); Cmdr.print(commandList[itemID]); Cmdr.print(" as menu item "); diff --git a/library.properties b/library.properties index 1fff567..171c991 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Commander -version=4.2.2 +version=4.2.3 author=Bill Bigge maintainer=Bill Bigge sentence=Command line library for Arduino. diff --git a/src/Commander.cpp b/src/Commander.cpp index 15249fe..9d2c100 100644 --- a/src/Commander.cpp +++ b/src/Commander.cpp @@ -5,8 +5,6 @@ Commander::Commander(){ bufferString.reserve(bufferSize); ports.settings.reg = COMMANDER_DEFAULT_REGISTER_SETTINGS; commandState.reg = COMMANDER_DEFAULT_STATE_SETTINGS; - - } //============================================================================================================== Commander::Commander(uint16_t reservedBuffer){ diff --git a/src/Commander.h b/src/Commander.h index 0e534d6..b28141b 100644 --- a/src/Commander.h +++ b/src/Commander.h @@ -11,7 +11,7 @@ class Commander; const uint8_t majorVersion = 4; const uint8_t minorVersion = 2; -const uint8_t subVersion = 2; +const uint8_t subVersion = 3; //#define BENCHMARKING_ON @@ -34,9 +34,9 @@ typedef bool (*cmdHandler)(Commander& Cmdr); //command handler function pointer //Command handler array type - contains command string and function pointer typedef struct commandList_t{ - char* commandString; + const char* commandString; cmdHandler handler; - char* manualString; + const char* manualString; } commandList_t; //extern const commandList_t myCommands[]; @@ -175,7 +175,7 @@ class Commander : public Stream { Commander& printPassPhrase() {print(*passPhrase); return *this;} Commander& setUserString(String& str) {userString = &str; return *this;} Commander& printUserString() {print(*userString); return *this;} - Commander& setExtraHelp(char* ptr[]) {extraHelp = ptr; return *this;} + Commander& setExtraHelp(const char* ptr[]){extraHelp = ptr; return *this;} Commander& lock() {ports.settings.bit.locked = true; return *this;} Commander& unlock() {ports.settings.bit.locked = false; return *this;} Commander& setLockType(bool hlState) {ports.settings.bit.useHardLock = hlState; return *this;} @@ -216,7 +216,7 @@ class Commander : public Stream { Commander& setStreamType(streamType_t newType) {ports.settings.bit.streamType = (uint16_t)newType; return *this;} streamType_t getStreamType() {return (streamType_t)ports.settings.bit.streamType;} - Commander& reloadCommands() {computeLengths(); return *this;} + Commander& reloadCommands() {computeLengths(); return *this;} int quick(String cmd); Commander& quickSetHelp(); @@ -490,7 +490,7 @@ class Commander : public Stream { int16_t commandIndex = -1; uint8_t* commandLengths; uint8_t endIndexOfLastCommand = 0; - char** extraHelp; + const char** extraHelp; uint8_t longestCommand = 0; char commentCharacter = '#'; //marks a line as a comment - ignored by the command parser char reloadCommandCharacter = '/'; //send this character to automatically reprocess the old buffer - same as resending the last command from the users POV. diff --git a/src/utilities/CommandHelpTags.cpp b/src/utilities/CommandHelpTags.cpp index b98a93a..2be5b62 100644 --- a/src/utilities/CommandHelpTags.cpp +++ b/src/utilities/CommandHelpTags.cpp @@ -8,7 +8,7 @@ bool getCommandArgCode(char helpText[], cmdArgs_t commandArguments){ int16_t lastBracket = -1; uint8_t idx = 0; //find the opening and closing brackets - while(helpText[idx] != NULL){ + while(helpText[idx] != '\0'){ //step through the help string if(helpText[idx] == CMD_ARG_START_BRACKET){ if(idx > 1) break; //if the bracket is not in the 1st or 2nd place, exit.