CommandCatcher
Helps obtain commands from attached host.
Loading...
Searching...
No Matches
CommandCatcher Class Reference

Project: CommandCatcher for Arduino. More...

#include <CommandCatcher.h>

Public Types

typedef void(* CCListener) (char *, char *)

Public Member Functions

 CommandCatcher ()
 default constructor
void init (Stream &serial=Serial, uint8_t bufsize=16)
 Initializes the serial interface for communication.
void update (bool close=true)
 checks the Serial input stream and processes any command info available.
void addListener (CCListener myListener)
 Adds a listener to be called when a command is available.
void addListener (CommandListener *obj)
 Adds a listener to be called when a command is available.
void setTerminator (char term)
 Sets the terminator character.
void setSeparator (char sep)
 Sets the separator character.
void close ()
 Closes out the current command.
bool ready ()
 Returns true if a command is ready to be processed.
char * getCommand ()
 Returns the command.
char * getParameter ()
 Returns the parameter string.

Detailed Description

Project: CommandCatcher for Arduino.

The CommandCatcher class provides a wrapper to the Serial object in order to receive commands through the serial interface.

This header file also provides a shared global object CCatcher of class CommandCatcher for convenience.

Member Typedef Documentation

◆ CCListener

typedef void(* CommandCatcher::CCListener) (char *, char *)

The listener function must accept two strings - the command and the parameter string - and return void.

Constructor & Destructor Documentation

◆ CommandCatcher()

CommandCatcher::CommandCatcher ( )

default constructor

Generally, you should use the predefined global instance 'CCatcher' rather than create your own instance.

Member Function Documentation

◆ addListener() [1/2]

void CommandCatcher::addListener ( CCListener myListener)

Adds a listener to be called when a command is available.

Should generally be called during the setup() function. The CommandCatchersupports up to 4 listeners. The listener function must be a function returning void that accepts two char* parameters:

void myListener(char* command, char* parameter)

This method works with free functions.

Parameters
myListener- The listener to be added

◆ addListener() [2/2]

void CommandCatcher::addListener ( CommandListener * obj)

Adds a listener to be called when a command is available.

Should generally be called during the setup() function. The CommandCatchersupports up to 4 listeners. The listening class must extend the CommandListener abstract class. This method allows a non-static member function of a class to be added as a listener.

Parameters
obj- the object

◆ close()

void CommandCatcher::close ( )

Closes out the current command.

If you use update(false), you should call close() after processing the command.

◆ getCommand()

char * CommandCatcher::getCommand ( )

Returns the command.

To be used when polling for commands.

Returns
the command string

◆ getParameter()

char * CommandCatcher::getParameter ( )

Returns the parameter string.

To be used when polling for commands.

Returns
the parameter string

◆ init()

void CommandCatcher::init ( Stream & serial = Serial,
uint8_t bufsize = 16 )

Initializes the serial interface for communication.

The init method is meant to be called from a central location, for example in the top-level sketch. If init is not called, the serial stream will not be monitored.

Parameters
serial- the serial stream to be used
bufsize- the desired buffer size number of listeners will be ignored.

◆ ready()

bool CommandCatcher::ready ( )

Returns true if a command is ready to be processed.

To be used when polling for commands.

Returns
true if a command is ready to be processed.

◆ setSeparator()

void CommandCatcher::setSeparator ( char sep)

Sets the separator character.

Should be called during the setup() function.

Parameters
sep- separator character to be used.

◆ setTerminator()

void CommandCatcher::setTerminator ( char term)

Sets the terminator character.

Should be called during the setup() function.

Parameters
term- terminator character to be used.

◆ update()

void CommandCatcher::update ( bool close = true)

checks the Serial input stream and processes any command info available.

Should be called at the beginning of the loop() function.

Parameters
Iftrue, the command will be closed out and discarded after the listener functions are called. If you want to poll for commands rather than be notified, call update(false).

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