Added second version of SpanUserCommand() that takes a void *arg
Useful for passing a pointer to a Service that can be used in the CLI command.
This commit is contained in:
parent
ea09e5c8f3
commit
bf2e1354b1
|
|
@ -982,7 +982,10 @@ void Span::processSerialCommand(const char *c){
|
||||||
auto uCom=UserCommands.find(c[1]);
|
auto uCom=UserCommands.find(c[1]);
|
||||||
|
|
||||||
if(uCom!=UserCommands.end()){
|
if(uCom!=UserCommands.end()){
|
||||||
uCom->second->userFunction(c+1);
|
if(uCom->second->userFunction1)
|
||||||
|
uCom->second->userFunction1(c+1);
|
||||||
|
else
|
||||||
|
uCom->second->userFunction2(c+1,uCom->second->userArg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1893,9 +1896,19 @@ SpanButton::SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t
|
||||||
// SpanUserCommand //
|
// SpanUserCommand //
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
SpanUserCommand::SpanUserCommand(char c, const char *s, void (*f)(const char *v)){
|
SpanUserCommand::SpanUserCommand(char c, const char *s, void (*f)(const char *)){
|
||||||
this->s=s;
|
this->s=s;
|
||||||
userFunction=f;
|
userFunction1=f;
|
||||||
|
|
||||||
|
homeSpan.UserCommands[c]=this;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
|
SpanUserCommand::SpanUserCommand(char c, const char *s, void (*f)(const char *, void *), void *arg){
|
||||||
|
this->s=s;
|
||||||
|
userFunction2=f;
|
||||||
|
userArg=arg;
|
||||||
|
|
||||||
homeSpan.UserCommands[c]=this;
|
homeSpan.UserCommands[c]=this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -657,10 +657,13 @@ struct SpanButton{
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
struct SpanUserCommand {
|
struct SpanUserCommand {
|
||||||
const char *s; // description of command
|
const char *s; // description of command
|
||||||
void (*userFunction)(const char *v); // user-defined function to call
|
void (*userFunction1)(const char *v)=NULL; // user-defined function to call
|
||||||
|
void (*userFunction2)(const char *v, void *arg)=NULL; // user-defined function to call with user-defined arg
|
||||||
|
void *userArg;
|
||||||
|
|
||||||
SpanUserCommand(char c, const char *s, void (*f)(const char *v));
|
SpanUserCommand(char c, const char *s, void (*f)(const char *));
|
||||||
|
SpanUserCommand(char c, const char *s, void (*f)(const char *, void *), void *arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue