@@ -80,9 +80,9 @@ Arduino API (AVR, Teensy, ESP8266, ESP32, etc), and it provides a handful of
8080additional macros that can reduce boilerplate code.
8181
8282
83- ** Version** : 1.0. 1 (2020-09-18 )
83+ ** Version** : 1.1 (2020-11-01 )
8484
85- ** Changelog** : [ CHANGELOG.md] ( CHANGELOG.md ) .
85+ ** Changelog** : [ CHANGELOG.md] ( CHANGELOG.md )
8686
8787![ AUnit Tests] ( https://github.com/bxparks/AceRoutine/workflows/AUnit%20Tests/badge.svg )
8888
@@ -231,21 +231,30 @@ void loop() {
231231
232232## Installation
233233
234- The latest stable release is available in the Arduino IDE Library Manager.
235- Search for "AceRoutine". Click Install.
234+ The latest stable release is available in the Arduino IDE Library Manager. Two
235+ libraries need to be installed since v1.1:
236236
237- The development version can be installed by cloning the
238- [GitHub repository](https://github.com/bxparks/AceRoutine), checking out the
239- `develop` branch, then manually copying over the contents to the `./libraries`
240- directory used by the Arduino IDE. (The result is a directory named
241- `./libraries/AceRoutine`.) The `master` branch contains the stable release.
237+ * Search for "AceRoutine". Click Install.
238+ * Search for "AceCommon". Click Install.
239+
240+ The development version can be installed by cloning the 2 git repos:
241+
242+ * AceRoutine (https://github.com/bxparks/AceRoutine)
243+ * AceCommon (https://github.com/bxparks/AceCommon)
244+
245+ You can copy these directories to the `./libraries` directory used by the
246+ Arduino IDE. (The result is a directory named `./libraries/AceRoutine` and
247+ `./libraries/AceCommon`). Or you can create symlinks from `/.libraries` to these
248+ directories.
249+
250+ The `develop` branch contains the latest working version.
251+ The `master` branch contains the stable release.
242252
243253### Source Code
244254
245255The source files are organized as follows:
246256* `src/AceRoutine.h` - main header file
247257* `src/ace_routine/` - implementation files
248- * `src/ace_routine/cli` - command line interface library
249258* `src/ace_routine/testing/` - internal testing files
250259* `tests/` - unit tests which depend on
251260 [AUnit](https://github.com/bxparks/AUnit)
@@ -274,12 +283,6 @@ The following example sketches are provided:
274283* [BlinkSlowFastManualRoutine.ino](examples/BlinkSlowFastManualRoutine): same
275284 as BlinkSlowFastRoutine but using manual `Coroutine` subclasses
276285* [CountAndBlink.ino](examples/CountAndBlink): count and blink at the same time
277- * [CommandLineShell.ino](examples/CommandLineShell): uses the
278- `src/ace_routine/cli` classes to implement a command line interface that
279- accepts a number of commands on the serial port. In other words, it is a
280- primitive "shell". The shell is non-blocking and uses coroutines so that other
281- coroutines continue to run while the board waits for commands to be typed on
282- the serial port.
283286* [Delay.ino](examples/Delay): validate the various delay macros
284287 (`COROUTINE_DELAY()`, `COROUTINE_DELAY_MICROS()` and
285288 `COROUTINE_DELAY_SECONDS()`)
@@ -366,6 +369,51 @@ void loop() {
366369}
367370```
368371
372+ ### Coroutine Class
373+
374+ The `Coroutine` class looks something like this (not all public methods shown):
375+
376+ ```C++
377+ class Coroutine {
378+ public:
379+ static Coroutine** getRoot();
380+
381+ const ace_common::FCString& getName() const;
382+
383+ virtual int runCoroutine() = 0;
384+
385+ virtual unsigned long coroutineMillis() const;
386+
387+ virtual unsigned long coroutineMicros() const;
388+
389+ virtual unsigned long coroutineSeconds() const;
390+
391+ void suspend();
392+
393+ void resume();
394+
395+ void reset();
396+
397+ bool isSuspended() const;
398+
399+ bool isYielding() const;
400+
401+ bool isDelaying() const;
402+
403+ bool isRunning() const;
404+
405+ bool isEnding() const;
406+
407+ bool isTerminated() const;
408+
409+ bool isDone() const;
410+
411+ void setupCoroutine(const char* name);
412+
413+ void setupCoroutine(const __FlashStringHelper* name);
414+ };
415+ ```
416+
369417### Coroutine Instance
370418
371419All coroutines are instances of the ` Coroutine ` class or one of its
@@ -383,6 +431,25 @@ subclass of `Coroutine`. The name of this subclass is autogenerated to be
383431`Coroutine_doSomething` but it is unlikely that you will need know the exact
384432name of this generated class.
385433
434+ If you expand the `COROUTINE()` macro from `Coroutine.h`, the above code is
435+ equivalent to writing out the following by hand:
436+
437+ ```C++
438+ struct Coroutine_doSomething: Coroutine {
439+ Coroutine_doSomething() {
440+ setupCoroutine(F("doSomething"));
441+ }
442+
443+ int runCoroutine() override {
444+ COROUTINE_BEGIN();
445+ ...
446+ COROUTINE_END();
447+ }
448+ };
449+
450+ Coroutine_doSomething doSomething;
451+ ```
452+
386453### Coroutine Body
387454
388455The code immediately following the ` COROUTINE() ` macro becomes the body of the
@@ -862,6 +929,23 @@ If the `Coroutine::suspend()` method is called on the coroutine *before*
862929coroutine into the active list of coroutines at all. This is useful in unit
863930tests to prevent extraneous coroutines from interfering with test validation.
864931
932+ ### Reset Coroutine
933+
934+ A coroutine can be reset to its initial state using the ` Coroutine::reset() `
935+ method so that the next time ` runCoroutine() ` is called, it begins execution
936+ from the start of that method instead of the most recent continuation point
937+ (i.e. after a ` COROUTINE_YIELD() ` , ` COROUTINE_DELAY() ` , etc).
938+
939+ If the coroutine object has any other state variables, for example, additional
940+ member variables of the Coroutine subclass, or static variables inside the
941+ ` runCoroutine() ` method, you may ned to manually reset those variables to their
942+ initial states as well.
943+
944+ Personally, I have never needed the ` reset() ` functionalty, but it is apparently
945+ useful for some people. See for example
946+ [ Issue #13 ] ( https://github.com/bxparks/AceRoutine/issues/13 ) and
947+ [ Issue #14 ] ( https://github.com/bxparks/AceRoutine/issues/14 ) .
948+
865949### Coroutine States
866950
867951A coroutine has several internal states:
@@ -1332,14 +1416,12 @@ void loop() {
13321416
13331417** Examples**
13341418
1335- A really good example of using a ` Channel ` can be found in the
1336- [ace_routine/cli](src/ace_routine/cli) package which uses 2 coroutines
1337- and a channel between them to communicate:
1338-
1339- * `StreamLineReader.h`: a coroutine that reads from `Serial` and writes to a
1340- `Channel`
1341- * `CommandDispatcher.h`: a coroutine that reads from a `Channel` and dispatches
1342- to a `CommandHandler`
1419+ The CommandLineInterface package in the AceUtils library
1420+ (https:// github.com/bxparks/AceUtils) uses 2 Coroutines which communicate with
1421+ each other using a Channel. One coroutine reads from the `Serial` port, while
1422+ the other coroutine writes the output of the command to the `Serial` port.
1423+ Neither coroutines are blocking, which allows other coroutines to do other
1424+ things.
13431425
13441426**Limitations**
13451427
0 commit comments