Skip to content

Commit 6e6fb2e

Browse files
authored
Merge pull request #17 from bxparks/develop
merge 1.1 into master
2 parents 20057a1 + 3ad40ed commit 6e6fb2e

File tree

202 files changed

+1121
-8125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+1121
-8125
lines changed

.github/workflows/aunit_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
run: |
1515
cd ..
1616
git clone https://github.com/bxparks/UnixHostDuino
17+
git clone https://github.com/bxparks/AceCommon
1718
git clone https://github.com/bxparks/AUnit
1819
1920
- name: Verify examples

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Changelog
22

33
* Unreleased
4+
* 1.1 (2020-11-01)
5+
* Add a `Coroutine::reset()` method that causes the Coroutine to restart
6+
from the beginning of the coroutine upon the next iteration. (Fixes #13
7+
and #14).
8+
* **Potentially Breaking**: AceRoutine now depends on the AceCommon
9+
(https://github.com/bxparks/AceCommon) library to avoid maintaining
10+
multiple versions of low-level common code. The externally exposed API has
11+
not changed. The AceCommon library can be installed through the Arduino
12+
IDE Library Manager, as explained in Installation section of the
13+
README.md.
14+
* **Potentially Breaking**: Move the CommandLineInterface package from
15+
`src/ace_routine/cli` to the AceUtils library
16+
(https://github.com/bxparks/AceUtils). The AceUtils library is a better
17+
home for this higher-level package that depends on AceRoutine.
418
* 1.0.1 (2020-09-18)
519
* Add continuous integration using GitHub Actions.
620
* Add more documentation and examples of Manual Coroutines in README.md.

README.md

Lines changed: 106 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ Arduino API (AVR, Teensy, ESP8266, ESP32, etc), and it provides a handful of
8080
additional 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
245255
The 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

371419
All 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
384432
name 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

388455
The 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*
862929
coroutine into the active list of coroutines at all. This is useful in unit
863930
tests 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

867951
A 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

docs/doxygen.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "AceRoutine"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 1.0.1
41+
PROJECT_NUMBER = 1.1
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a
@@ -2156,15 +2156,15 @@ ENABLE_PREPROCESSING = YES
21562156
# The default value is: NO.
21572157
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
21582158

2159-
MACRO_EXPANSION = NO
2159+
MACRO_EXPANSION = YES
21602160

21612161
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
21622162
# the macro expansion is limited to the macros specified with the PREDEFINED and
21632163
# EXPAND_AS_DEFINED tags.
21642164
# The default value is: NO.
21652165
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
21662166

2167-
EXPAND_ONLY_PREDEF = NO
2167+
EXPAND_ONLY_PREDEF = YES
21682168

21692169
# If the SEARCH_INCLUDES tag is set to YES, the include files in the
21702170
# INCLUDE_PATH will be searched if a #include is found.
@@ -2196,7 +2196,7 @@ INCLUDE_FILE_PATTERNS =
21962196
# recursively expanded use the := operator instead of the = operator.
21972197
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
21982198

2199-
PREDEFINED =
2199+
PREDEFINED = PROGMEM=
22002200

22012201
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
22022202
# tag can be used to specify a list of macro names that should be expanded. The

docs/html/AceRoutine_8h_source.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<tr style="height: 56px;">
2323
<td id="projectalign" style="padding-left: 0.5em;">
2424
<div id="projectname">AceRoutine
25-
&#160;<span id="projectnumber">1.0.1</span>
25+
&#160;<span id="projectnumber">1.1</span>
2626
</div>
2727
<div id="projectbrief">A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.</div>
2828
</td>
@@ -103,8 +103,8 @@
103103
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;<span class="preprocessor">#include &quot;ace_routine/Channel.h&quot;</span></div>
104104
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; </div>
105105
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;<span class="comment">// Version format: xxyyzz == &quot;xx.yy.zz&quot;</span></div>
106-
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor">#define ACE_ROUTINE_VERSION 10001</span></div>
107-
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="preprocessor">#define ACE_ROUTINE_VERSION_STRING &quot;1.0.1&quot;</span></div>
106+
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor">#define ACE_ROUTINE_VERSION 10100</span></div>
107+
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="preprocessor">#define ACE_ROUTINE_VERSION_STRING &quot;1.1&quot;</span></div>
108108
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; </div>
109109
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;<span class="preprocessor">#endif</span></div>
110110
</div><!-- fragment --></div><!-- contents -->

docs/html/Channel_8h_source.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<tr style="height: 56px;">
2323
<td id="projectalign" style="padding-left: 0.5em;">
2424
<div id="projectname">AceRoutine
25-
&#160;<span id="projectnumber">1.0.1</span>
25+
&#160;<span id="projectnumber">1.1</span>
2626
</div>
2727
<div id="projectbrief">A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.</div>
2828
</td>

0 commit comments

Comments
 (0)