Skip to content

Commit 42017ff

Browse files
committed
Parent option added for API functions
1 parent 6f65bc8 commit 42017ff

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

src/Commander-API.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void Commander::recursive_optimizer( int32_t start_index, int32_t stop_index ){
282282

283283
}
284284

285-
void Commander::executeCommand( char *cmd ){
285+
void Commander::executeCommand( char *cmd, void* parent ){
286286

287287
// The beginning of the argument list will be stored in this pointer
288288
char *arg;
@@ -447,14 +447,14 @@ void Commander::executeCommand( char *cmd ){
447447
if( pipePos > 0 ){
448448

449449
// Execute commands function and redirect the output to pipe.
450-
(commandData_ptr -> func)( arg, &pipeChannel );
450+
(commandData_ptr -> func)( arg, &pipeChannel, parent );
451451

452452
}
453453

454454
else{
455455

456456
// Execute command function.
457-
(commandData_ptr -> func)( arg, response );
457+
(commandData_ptr -> func)( arg, response, parent );
458458

459459
}
460460

@@ -570,6 +570,24 @@ void Commander::execute( const char *cmd, Stream *resp ){
570570

571571
}
572572

573+
void Commander::execute( char *cmd, Stream *resp, void* parent ){
574+
575+
response = resp;
576+
577+
// Execute the command.
578+
executeCommand( cmd, parent );
579+
580+
}
581+
582+
void Commander::execute( const char *cmd, Stream *resp, void* parent ){
583+
584+
response = resp;
585+
586+
// Execute the command.
587+
executeCommand( (char*)cmd, parent );
588+
589+
}
590+
573591
void Commander::attachDebugChannel( Stream *resp ){
574592

575593
dbgResponse = resp;
@@ -814,9 +832,9 @@ int32_t Commander::hasChar( char* str, char c ){
814832

815833
}
816834

817-
void Commander::printHelp( Stream* out ){
835+
void Commander::printHelp( Stream* out, bool style ){
818836

819-
helpFunction( true, out, true );
837+
helpFunction( true, out, style );
820838

821839
}
822840

src/Commander-API.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Commander{
114114
const char *name; // Name of the command
115115
const char *desc; // Description of the command
116116

117-
void(*func)( char*, Stream *response ); // Function pointer to the command function
117+
void(*func)( char*, Stream *response, void* parent ); // Function pointer to the command function
118118

119119
#ifdef __AVR__
120120
__FlashStringHelper *name_P; // Name of the command( stored in PROGMEM )
@@ -184,25 +184,28 @@ class Commander{
184184
/// be visible.
185185
void execute( const char *cmd );
186186

187-
/// Execution function for Serial response.
187+
/// Execution function for Stream response.
188188
///
189189
/// This function tries to execute a command.
190-
/// It uses the Serial response channel, so
190+
/// It uses the Stream response channel, so
191191
/// the messages from the command handler
192-
/// will be passed to the selected Serial
192+
/// will be passed to the selected Stream
193193
/// object.
194194
void execute( char *cmd, Stream *resp );
195195

196-
/// Execution function for Serial response.
196+
/// Execution function for Stream response.
197197
///
198198
/// This function tries to execute a command.
199-
/// It uses the Serial response channel, so
199+
/// It uses the Stream response channel, so
200200
/// the messages from the command handler
201-
/// will be passed to the selected Serial
201+
/// will be passed to the selected Stream
202202
/// object.
203203
void execute( const char *cmd, Stream *resp );
204204

205-
/// Debug channel for Serial.
205+
void execute( char *cmd, Stream *resp, void* parent );
206+
void execute( const char *cmd, Stream *resp, void* parent );
207+
208+
/// Debug channel for Stream.
206209
///
207210
/// This function attaches a Serial channel
208211
/// for debug messages. It also enables
@@ -217,7 +220,7 @@ class Commander{
217220

218221
/// Prints out the help string to the specified Stream.
219222
/// @param out The help information will be printed to this Stream.
220-
void printHelp( Stream* out );
223+
void printHelp( Stream* out, bool style = false );
221224

222225
private:
223226

@@ -326,7 +329,7 @@ class Commander{
326329
/// This function executes a command. Before calling this
327330
/// function, the response pointer and it's channel has to
328331
/// be configured correctly.
329-
void executeCommand( char *cmd );
332+
void executeCommand( char *cmd, void* parent = NULL );
330333

331334
/// Help function
332335
///

0 commit comments

Comments
 (0)