Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
#include <CommandInterface.h>
Public Member Functions | |
CommandInterface (uint8_t maxCmdLen=48) | |
~CommandInterface () | |
virtual void | begin (Stream &stream=Serial) |
void | update () |
virtual void | runCmd ()=0 |
Public Attributes | |
bool | echo |
Protected Member Functions | |
void | clearBuf () |
Protected Attributes | |
Stream * | _stream |
uint8_t | _maxLen |
uint8_t | _idx |
char * | _buf |
CommandInterface class is a base for implementing simple CLIs.
Character will be read from a Stream into a buffer. When CR (\r) or LF (
) is read, the runCmd() member will be called, and should interpret the contents of the command buffer and take some action accordingly.
This implementation supports optional local echo, and backspace/DEL handling (provided your terminal software can move the cursor left on printing of a character).
Definition at line 18 of file CommandInterface.h.
CommandInterface::CommandInterface | ( | uint8_t | maxCmdLen = 48 | ) |
Constructor
maxCmdLen | the maximum command length in bytes. Note: a buffer of this size is dynamically allocated when the CommandInterface object is constructed! |
Definition at line 4 of file CommandInterface.cpp.
CommandInterface::~CommandInterface | ( | ) |
Destructor.
Definition at line 14 of file CommandInterface.cpp.
|
virtual |
Initialization.
Typically called from setup().
stream | a reference to the stream to read input from and write output to. This is typically Serial. |
Definition at line 22 of file CommandInterface.cpp.
|
protected |
Clear the command buffer.
Definition at line 29 of file CommandInterface.cpp.
|
pure virtual |
Implement the parsing and launching of commands.
This function is pur virtual - you must sub-class CommandInterface and define it in your derived class in order to implement a CLI.
void CommandInterface::update | ( | ) |
Allocate timeslice.
Called frequently to detect key presses, typically from loop().
Definition at line 36 of file CommandInterface.cpp.
bool CommandInterface::echo |
Flag to turn on/off local echo.
If true, characters read from the stream will be written back to it, which is typically what we want when we have serial connected to a terminal emulator like minicom / screen or the Arduino serial monitor.
Definition at line 61 of file CommandInterface.h.