Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
Update to 4.2.3 to fix some compiler warnings
  • Loading branch information
CreativeRobotics committed Jul 21, 2021
1 parent 32877c5 commit 5869c80
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 63 deletions.
5 changes: 5 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 5 additions & 5 deletions examples/Advanced/CommandTextChange/masterCommands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/Advanced/FunctionSwap/FunctionSwap.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
#include <Commander.h>
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)";
Expand Down
28 changes: 14 additions & 14 deletions examples/Advanced/FunctionSwap/masterCommands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
}
11 changes: 6 additions & 5 deletions examples/Advanced/customMenu/masterCommands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
56 changes: 28 additions & 28 deletions examples/Advanced/customMenu_Static/masterCommands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};


Expand Down Expand Up @@ -91,15 +91,15 @@ 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"},
};

//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
Expand Down Expand Up @@ -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 ");
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Commander
version=4.2.2
version=4.2.3
author=Bill Bigge
maintainer=Bill Bigge <bbigge@gmail.com>
sentence=Command line library for Arduino.
Expand Down
2 changes: 0 additions & 2 deletions src/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
12 changes: 6 additions & 6 deletions src/Commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[];
Expand Down Expand Up @@ -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;}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/CommandHelpTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5869c80

Please sign in to comment.