|
CommandCatcher
Helps obtain commands from attached host.
|
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. | |
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.
| typedef void(* CommandCatcher::CCListener) (char *, char *) |
The listener function must accept two strings - the command and the parameter string - and return void.
| CommandCatcher::CommandCatcher | ( | ) |
default constructor
Generally, you should use the predefined global instance 'CCatcher' rather than create your own instance.
| 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:
This method works with free functions.
| myListener | - The listener to be added |
| 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.
| obj | - the object |
| void CommandCatcher::close | ( | ) |
Closes out the current command.
If you use update(false), you should call close() after processing the command.
| char * CommandCatcher::getCommand | ( | ) |
Returns the command.
To be used when polling for commands.
| char * CommandCatcher::getParameter | ( | ) |
Returns the parameter string.
To be used when polling for commands.
| 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.
| serial | - the serial stream to be used |
| bufsize | - the desired buffer size number of listeners will be ignored. |
| bool CommandCatcher::ready | ( | ) |
Returns true if a command is ready to be processed.
To be used when polling for commands.
| void CommandCatcher::setSeparator | ( | char | sep | ) |
Sets the separator character.
Should be called during the setup() function.
| sep | - separator character to be used. |
| void CommandCatcher::setTerminator | ( | char | term | ) |
Sets the terminator character.
Should be called during the setup() function.
| term | - terminator character to be used. |
| 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.
| If | true, 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). |