AceRoutine
0.3
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
|
A convenience wrapper around a CommandDispatcher that hides complexity of creating, initializing and injecting the resources needed by the CommandDispatcher. More...
#include <CommandManager.h>
Public Member Functions | |
CommandManager (const CommandHandler *const *commands, uint8_t numCommands, Stream &serial, const char *prompt=nullptr) | |
Constructor. More... | |
int | runCoroutine () override |
The body of the coroutine. More... | |
const CommandDispatcher * | getDispatcher () const |
Return the CommandDispatcher. More... | |
![]() | |
Coroutine ** | getNext () |
Return the next pointer as a pointer to the pointer, similar to getRoot(). More... | |
const FCString & | getName () const |
Human-readable name of the coroutine. More... | |
virtual unsigned long | coroutineMillis () const |
Returns the current millisecond clock. More... | |
virtual unsigned long | coroutineMicros () const |
Returns the current millisecond clock. More... | |
virtual unsigned long | coroutineSeconds () const |
Returns the current clock in unit of seconds, truncated to the lower 16-bits. More... | |
void | suspend () |
Suspend the coroutine at the next scheduler iteration. More... | |
void | resume () |
Add a Suspended coroutine into the head of the scheduler linked list, and change the state to Yielding. More... | |
bool | isDelayExpired () |
Check if delay time is over. More... | |
bool | isSuspended () const |
The coroutine was suspended with a call to suspend(). More... | |
bool | isYielding () const |
The coroutine returned using COROUTINE_YIELD(). More... | |
bool | isDelaying () const |
The coroutine returned using COROUTINE_DELAY(). More... | |
bool | isRunning () const |
The coroutine is currently running. More... | |
bool | isEnding () const |
The coroutine returned using COROUTINE_END(). More... | |
bool | isTerminated () const |
The coroutine was terminated by the scheduler with a call to setTerminated(). More... | |
bool | isDone () const |
The coroutine is either Ending or Terminated. More... | |
void | setupCoroutine (const char *name) |
Initialize the coroutine for the CoroutineScheduler, set it to Yielding state, and add it to the linked list of coroutines. More... | |
void | setupCoroutine (const __FlashStringHelper *name) |
Same as setupCoroutine(const char*) except using flash string type. More... | |
Additional Inherited Members | |
![]() | |
static Coroutine ** | getRoot () |
Get the pointer to the root pointer. More... | |
![]() | |
typedef uint8_t | Status |
The execution status of the coroutine, corresponding to the COROUTINE_YIELD(), COROUTINE_DELAY(), COROUTINE_AWAIT() and COROUTINE_END() macros. More... | |
![]() | |
Coroutine () | |
Constructor. More... | |
virtual | ~Coroutine () |
Destructor. More... | |
Status | getStatus () const |
Return the status of the coroutine. More... | |
void | statusPrintTo (Print &printer) |
Print the human-readable string of the Status. More... | |
void | setJump (void *jumpPoint) |
Pointer to label where execute will start on the next call to runCoroutine(). | |
void * | getJump () const |
Pointer to label where execute will start on the next call to runCoroutine(). | |
void | setRunning () |
Set the kStatusRunning state. More... | |
void | setYielding () |
Set the kStatusDelaying state. More... | |
void | setDelaying () |
Set the kStatusDelaying state. More... | |
void | setDelayMillis (uint16_t delayMillis) |
Configure the delay timer for delayMillis. More... | |
void | setDelayMicros (uint16_t delayMicros) |
Configure the delay timer for delayMicros. More... | |
void | setDelaySeconds (uint16_t delaySeconds) |
Configure the delay timer for delaySeconds. More... | |
void | setEnding () |
Set the kStatusEnding state. More... | |
void | setTerminated () |
Set status to indicate that the Coroutine has been removed from the Scheduler queue. More... | |
![]() | |
static const Status | kStatusSuspended = 0 |
Coroutine has been suspended using suspend() and the scheduler should remove it from the queue upon the next iteration. More... | |
static const Status | kStatusYielding = 1 |
Coroutine returned using the COROUTINE_YIELD() statement. More... | |
static const Status | kStatusDelaying = 2 |
Coroutine returned using the COROUTINE_DELAY() statement. More... | |
static const Status | kStatusRunning = 3 |
Coroutine is currenly running. More... | |
static const Status | kStatusEnding = 4 |
Coroutine executed the COROUTINE_END() statement. More... | |
static const Status | kStatusTerminated = 5 |
Coroutine has ended and no longer in the scheduler queue. More... | |
static const uint8_t | kDelayTypeMillis = 0 |
Delay using units of millis. More... | |
static const uint8_t | kDelayTypeMicros = 1 |
Delay using units of micros. More... | |
static const uint8_t | kDelayTypeSeconds = 2 |
Delay using units of seconds. More... | |
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:
BUF_SIZE | Size of the input line buffer. |
ARGV_SIZE | Size of the command line argv token list. |
Definition at line 82 of file CommandManager.h.
|
inline |
Constructor.
commands | Array of (CommandHandler*). |
numCommands | Number of commands in 'commands'. |
serial | The serial port used to read commands and send output, will normally be 'Serial', but can be set to something else. |
prompt | If 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 96 of file CommandManager.h.
|
inline |
|
inlineoverridevirtual |
The body of the coroutine.
The COROUTINE macro creates a subclass of this class and puts the body of the coroutine into this method.
Implements ace_routine::Coroutine.
Definition at line 106 of file CommandManager.h.