Skip to content

Commit

Permalink
Merge pull request #20 from mairas/release_2.0.0
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
mairas authored Nov 27, 2021
2 parents e7dbeda + d5468e6 commit 0cb5afc
Show file tree
Hide file tree
Showing 347 changed files with 8,656 additions and 4,187 deletions.
29 changes: 29 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[bumpversion]
current_version = 2.0.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
serialize =
{major}.{minor}.{patch}-{release}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = final
first_value = alpha
values =
alpha
final

[bumpversion:file:VERSION]

[bumpversion:file:library.json]
search = "version": "{current_version}",
replace = "version": "{new_version}",

[bumpversion:file:library.properties]
search = version={current_version}
replace = version={new_version}

[bumpversion:file:Doxyfile]
search = = {current_version}
replace = = {new_version}
468 changes: 270 additions & 198 deletions Doxyfile

Large diffs are not rendered by default.

76 changes: 67 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

By [Matti Airas](https://github.com/mairas)

An asynchronous programming library for the ESP8266 and other microcontrollers using the Arduino framework.
An asynchronous programming library for the ESP32 and other microcontrollers using the Arduino framework.

The library is at the core of the [SensESP](https://github.com/SignalK/SensESP) project but is completely generic and can be used for standalone projects without issues.

Expand Down Expand Up @@ -35,19 +35,27 @@ Using ReactESP, the sketch can be rewritten to the following:
```cpp
#include <ReactESP.h>

ReactESP app([] () {
using namespace reactesp;

ReactESP app;

setup() {
pinMode(LED_BUILTIN, OUTPUT);

app.onRepeat(1000, [] () {
static bool state = false;
digitalWrite(LED_BUILTIN, state = !state);
});
});
}

void loop() {
app.tick();
}
```

With ReactESP, the developer creates an `app` object and passes to the constructor a start up function. In the example above, a [lambda function](http://en.cppreference.com/w/cpp/language/lambda) is used.
Instead of directly defining the program logic in the `loop()` function, _reactions_ are defined in the `setup()` function. A reaction is a function that is executed when a certain event happens. In this case, the event is that the function should repeat every second, as defined by the `onRepeat()` method call. The second argument to the `onRepeat()` method is a [lambda function](http://en.cppreference.com/w/cpp/language/lambda) that is executed every time the reaction is triggered. If the syntax feels weird, you can also use regular named functions instead of lambdas.

There is no `setup()` or `loop()`, ReactESP will define these for you. All you need to do is tell ReactESP which events you need to watch, and it will dispatch your handlers/callbacks when they occur.
The `app.tick()` call in the `loop()` function is the main loop of the program. It is responsible for calling the reactions that have been defined. You can also add additional code to the `loop()` function, any delays or other long-executing code should be avoided.

## Why Bother?

Expand Down Expand Up @@ -136,7 +144,11 @@ This solves Charlie's problem, but it's quite verbose. Using ReactESP, Charlie c
```c++
#include <ReactESP.h>

ReactESP app([] () {
using namespace reactesp;

ReactESP app;

void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);

Expand All @@ -146,7 +158,11 @@ ReactESP app([] () {

app.onDelay(1000, [] () { digitalWrite(LED_BUILTIN, LOW); });
});
});
}

void loop() {
app.tick();
}
```

## Advanced callback support
Expand All @@ -167,6 +183,21 @@ for (int i=0; i<20; i++) {

## API

### Namespace use

Note that beginning of ReactESP 2.0.0, the ReactESP library has been wrapped in
a `reactesp` namespace.
This is to avoid name conflicts with other libraries.

The impact to the user is that they need to define the namespace when using the library.
This can be done either globally by placing the following statement in the source code right after the `#include` statements:

using namespace reactesp;

or by using the `reactesp::` prefix when using the library:

reactesp::ReactESP app;

### Event Registration Functions

All of the registration functions return a `Reaction` object pointer. This can be used to store and manipulate
Expand Down Expand Up @@ -216,6 +247,33 @@ Remove the reaction from the execution queue.

- [`Minimal`](examples/minimal/src/main.cpp): A minimal example with two timers switching the LED state.

- [`Servo`](examples/servo.cpp): Demonstrates several different reaction types for controlling a servo, monitoring inputs and blinking an LED.

- [`Torture test`](examples/torture_test/src/main.cpp): A stress test of twenty simultaneous repeat reactions as well as a couple of interrupts, a stream, and a tick reaction. For kicks, try changing `NUM_TIMERS` to 200. Program performance will be practically unchanged!

## Changes between version 1 and 2

ReactESP version 2 has changed the software initialization approach from version 1.
Version 1 implemented the Arduino framework standard `setup()` and `loop()` functions behind the scenes,
and a user just instantiated a ReactESP object and provided a setup function as an argument:

ReactESP app([]() {
app.onDelay(...);
});

While this approach was "neat", it was also confusing to many users familiar with the Arduino framework. Therefore, ReactESP version 2 has reverted back to the more conventional approach:

ReactESP app;

void setup() {
app.onDelay(...);
}

void loop() {
app.tick();
}

Note the changes:
- ReactESP app object is instantiated without any arguments
- There is an explicit `setup()` function.
Its contents can be copied verbatim from the version 1 lambda function.
- There is an explicit `loop()` function.
`app.tick()` must be called in the loop.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
69 changes: 7 additions & 62 deletions docs/generated/docs/_react_e_s_p_8cpp.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">ReactESP<span id="projectnumber">&#160;1.0.0</span>
<div id="projectname">ReactESP<span id="projectnumber">&#160;2.0.0</span>
</div>
<div id="projectbrief">Asynchronous programming for the ESP microcontrollers</div>
</td>
Expand Down Expand Up @@ -91,7 +91,7 @@

<div class="header">
<div class="summary">
<a href="#func-members">Functions</a> </div>
<a href="#namespaces">Namespaces</a> </div>
<div class="headertitle"><div class="title">ReactESP.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
Expand All @@ -102,72 +102,17 @@
</div><div class="textblock"><div class="dynheader">
Include dependency graph for ReactESP.cpp:</div>
<div class="dyncontent">
<div class="center"><!-- SVG 0 -->
<div class="center"><iframe scrolling="no" frameborder="0" src="_react_e_s_p_8cpp__incl.svg" width="464" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
<p><a href="_react_e_s_p_8cpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a7dfd9b79bc5a37d7df40207afbc5431f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="_react_e_s_p_8cpp.html#a7dfd9b79bc5a37d7df40207afbc5431f">setup</a> (void)</td></tr>
<tr class="separator:a7dfd9b79bc5a37d7df40207afbc5431f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0b33edabd7f1c4e4a0bf32c67269be2f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="_react_e_s_p_8cpp.html#a0b33edabd7f1c4e4a0bf32c67269be2f">loop</a> (void)</td></tr>
<tr class="separator:a0b33edabd7f1c4e4a0bf32c67269be2f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:namespacereactesp"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacereactesp.html">reactesp</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="a0b33edabd7f1c4e4a0bf32c67269be2f" name="a0b33edabd7f1c4e4a0bf32c67269be2f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0b33edabd7f1c4e4a0bf32c67269be2f">&#9670;&nbsp;</a></span>loop()</h2>

<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void loop </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">

<p class="definition">Definition at line <a class="el" href="_react_e_s_p_8cpp_source.html#l00109">109</a> of file <a class="el" href="_react_e_s_p_8cpp_source.html">ReactESP.cpp</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><!-- SVG 1 -->
</div>
</div>

</div>
</div>
<a id="a7dfd9b79bc5a37d7df40207afbc5431f" name="a7dfd9b79bc5a37d7df40207afbc5431f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7dfd9b79bc5a37d7df40207afbc5431f">&#9670;&nbsp;</a></span>setup()</h2>

<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void setup </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">

<p class="definition">Definition at line <a class="el" href="_react_e_s_p_8cpp_source.html#l00107">107</a> of file <a class="el" href="_react_e_s_p_8cpp_source.html">ReactESP.cpp</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><!-- SVG 2 -->
</div>
</div>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
Expand Down
5 changes: 0 additions & 5 deletions docs/generated/docs/_react_e_s_p_8cpp.js

This file was deleted.

24 changes: 0 additions & 24 deletions docs/generated/docs/_react_e_s_p_8cpp__incl.dot

This file was deleted.

10 changes: 10 additions & 0 deletions docs/generated/docs/_react_e_s_p_8cpp__incl.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<map id="src/ReactESP.cpp" name="src/ReactESP.cpp">
<area shape="rect" id="node1" title=" " alt="" coords="161,5,289,32"/>
<area shape="rect" id="node2" href="$_react_e_s_p_8h.html" title=" " alt="" coords="107,80,201,107"/>
<area shape="rect" id="node3" title=" " alt="" coords="5,155,84,181"/>
<area shape="rect" id="node7" title=" " alt="" coords="225,80,369,107"/>
<area shape="rect" id="node8" title=" " alt="" coords="393,80,459,107"/>
<area shape="rect" id="node4" title=" " alt="" coords="109,155,199,181"/>
<area shape="rect" id="node5" title=" " alt="" coords="224,155,303,181"/>
<area shape="rect" id="node6" title=" " alt="" coords="327,155,386,181"/>
</map>
1 change: 1 addition & 0 deletions docs/generated/docs/_react_e_s_p_8cpp__incl.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
47f003e2bc519a94d540a6f1430ed492
Loading

0 comments on commit 0cb5afc

Please sign in to comment.