Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
CommandInterface Class Referenceabstract

#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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CommandInterface()

CommandInterface::CommandInterface ( uint8_t  maxCmdLen = 48)

Constructor

Parameters
maxCmdLenthe 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::~CommandInterface ( )

Destructor.

Definition at line 14 of file CommandInterface.cpp.

Member Function Documentation

◆ begin()

void CommandInterface::begin ( Stream &  stream = Serial)
virtual

Initialization.

Typically called from setup().

Parameters
streama reference to the stream to read input from and write output to. This is typically Serial.

Definition at line 22 of file CommandInterface.cpp.

Here is the call graph for this function:

◆ clearBuf()

void CommandInterface::clearBuf ( )
protected

Clear the command buffer.

Definition at line 29 of file CommandInterface.cpp.

Here is the caller graph for this function:

◆ runCmd()

virtual void CommandInterface::runCmd ( )
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.

Here is the caller graph for this function:

◆ update()

void CommandInterface::update ( )

Allocate timeslice.

Called frequently to detect key presses, typically from loop().

Definition at line 36 of file CommandInterface.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ echo

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.


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