AceUtils  0.3
Useful Arduino utilties which are too small as separate libraries, but complex enough to have external dependencies to other libraries.
Public Member Functions | List of all members
cli::CommandManager< BUF_SIZE, ARGV_SIZE > Class Template Reference

A convenience wrapper around a CommandDispatcher that hides complexity of creating, initializing and injecting the resources needed by the CommandDispatcher. More...

#include <CommandManager.h>

Inheritance diagram for cli::CommandManager< BUF_SIZE, ARGV_SIZE >:
Inheritance graph
[legend]
Collaboration diagram for cli::CommandManager< BUF_SIZE, ARGV_SIZE >:
Collaboration graph
[legend]

Public Member Functions

 CommandManager (const CommandHandler *const *commands, uint8_t numCommands, Stream &serial, const char *prompt=nullptr)
 Constructor. More...
 
int runCoroutine () override
 
const CommandDispatchergetDispatcher () const
 Return the CommandDispatcher. More...
 

Detailed Description

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
class cli::CommandManager< BUF_SIZE, ARGV_SIZE >

A convenience wrapper around a CommandDispatcher that hides complexity of creating, initializing and injecting the resources needed by the CommandDispatcher.

It is not strictly necessary to use this, but the setup is much easier using this class.

This is a subclass of Coroutine, just like CommandDispatcher. The runCoroutine() method simply delegates to the underlying CommandDispatcher, so this class can be used as a substitute for CommandDispatcher. The setupCoroutine() method should be called to initialize the name of the coroutine and insert it into the CoroutineScheduler.

Example usage:

class CommandA: public CommandHandler {
...
};
class CommandB: public CommandHandler {
...
};
CommandA commandA;
CommandB commandB;
static const CommandHandler* COMMANDS[] = {
};
const uint8_t BUF_SIZE = 64;
const uint8_t ARGV_SIZE = 5;
const char PROMPT[] = "$ ";
CommandManager<BUF_SIZE, ARGV_SIZE> commandManager(
COMMANDS, NUM_COMMANDS, Serial, PROMPT);
void setup() {
...
commandManager.setupCoroutine("commandManager");
CoroutineScheduler::setup();
}
Parameters
BUF_SIZESize of the input line buffer.
ARGV_SIZESize of the command line argv token list.

Definition at line 81 of file CommandManager.h.

Constructor & Destructor Documentation

◆ CommandManager()

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
cli::CommandManager< BUF_SIZE, ARGV_SIZE >::CommandManager ( const CommandHandler *const *  commands,
uint8_t  numCommands,
Stream &  serial,
const char *  prompt = nullptr 
)
inline

Constructor.

Parameters
commandsArray of (CommandHandler*).
numCommandsNumber of commands in 'commands'.
serialThe serial port used to read commands and send output, will normally be 'Serial', but can be set to something else.
promptIf not null, print a prompt and echo the command entered by the user. If null, don't print the prompt and don't echo the input from the user.

Definition at line 95 of file CommandManager.h.

Member Function Documentation

◆ getDispatcher()

template<uint8_t BUF_SIZE, uint8_t ARGV_SIZE>
const CommandDispatcher* cli::CommandManager< BUF_SIZE, ARGV_SIZE >::getDispatcher ( ) const
inline

Return the CommandDispatcher.

VisibleForTesting.

Definition at line 112 of file CommandManager.h.


The documentation for this class was generated from the following file: