AceRoutine
1.2.3
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
|
27 #include <AceCommon.h>
31 namespace ace_routine {
37 return elapsedMillis >= mDelayDuration;
41 return elapsedMicros >= mDelayDuration;
45 return elapsedSeconds >= mDelayDuration;
54 mName = ace_common::FCString(name);
60 mName = ace_common::FCString(name);
66 mName = ace_common::FCString(name);
72 mName = ace_common::FCString(name);
84 void Coroutine::insertSorted() {
88 while (*p !=
nullptr) {
89 if (
getName().compareTo((*p)->getName()) <= 0)
break;
97 void Coroutine::insertAtRoot() {
123 unsigned long m = ::millis();
124 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) || defined(ESP8266)
126 return ace_common::udiv1000(m);
138 static const char kStatusSuspendedString[] PROGMEM =
"Suspended";
139 static const char kStatusYieldingString[] PROGMEM =
"Yielding";
140 static const char kStatusDelayingString[] PROGMEM =
"Delaying";
141 static const char kStatusRunningString[] PROGMEM =
"Running";
142 static const char kStatusEndingString[] PROGMEM =
"Ending";
143 static const char kStatusTerminatedString[] PROGMEM =
"Terminated";
145 const __FlashStringHelper*
const Coroutine::sStatusStrings[] = {
146 FPSTR(kStatusSuspendedString),
147 FPSTR(kStatusYieldingString),
148 FPSTR(kStatusDelayingString),
149 FPSTR(kStatusRunningString),
150 FPSTR(kStatusEndingString),
151 FPSTR(kStatusTerminatedString),
static const uint8_t kDelayTypeSeconds
Delay using units of seconds.
void resume()
Add a Suspended coroutine into the head of the scheduler linked list, and change the state to Yieldin...
static const uint8_t kDelayTypeMillis
Delay using units of millis.
#define FPSTR(p)
A macro that converts a const char* that already points to a PROGMEM string to a const __FlashStringH...
virtual unsigned long coroutineMicros() const
Returns the current millisecond clock.
static const Status kStatusSuspended
Coroutine has been suspended using suspend() and the scheduler should remove it from the queue upon t...
virtual unsigned long coroutineSeconds() const
Returns the current clock in unit of seconds, truncated to the lower 16-bits.
const ace_common::FCString & getName() const
Human-readable name of the coroutine.
static const uint8_t kDelayTypeMicros
Delay using units of micros.
bool isDelayExpired() const
Check if delay time is over.
void setupCoroutineOrderedByName(const char *name)
A version of setupCoroutine(const char*) where the ordering of the coroutines executed by CoroutineSc...
Base class of all coroutines.
static const Status kStatusYielding
Coroutine returned using the COROUTINE_YIELD() statement.
virtual unsigned long coroutineMillis() const
Returns the current millisecond clock.
void setupCoroutine(const char *name)
Initialize the coroutine for the CoroutineScheduler, set it to Yielding state, and add it to the link...