Skip to content

Commit f229a22

Browse files
committed
updated documentation for signals
1 parent 8996014 commit f229a22

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ pa_activity (Main, pa_ctx_tm(pa_co_res(3); pa_use(Delay); pa_use(FastBlinker); p
6161
6262
In this example, a fast led is blinked for 3 ticks and then both the fast and a slow led are blinked concurrently for 10 ticks.
6363
64+
To trigger the Main activity you need to declare its usage and then tick it until done - either at a specific frequency - or in a free-running style - by repeatedly calling `pa_tick`:
65+
66+
```
67+
int main(int argc, char* argv[]) {
68+
pa_use(Main);
69+
70+
while (pa_tick(Main) == PA_RC_WAIT) {
71+
std::this_thread::sleep_for(std::chrono::milliseconds(20)); // Will result in a 50Hz tick frequency.
72+
}
73+
74+
return 0;
75+
}
76+
```
77+
6478
## Constructs
6579
6680
As can be seen in the example above, an activity is defined by the `pa_activity` macro which takes the
@@ -103,9 +117,13 @@ For a detailed description of the statements, please currently refer to the [Ble
103117
When compiling wit C++ you could also define the following lifecycle callbacks:
104118
105119
* `pa_defer`: defines an instantaneous block of code to run when the activity ends by itself or gets aborted. Add `pa_defer_res` annotation to the context to enable this feature.
120+
* `pa_enter`: defines an instantaneous block of code to run whenever the activity is entered - and initially when defined. Add `pa_enter_res` annotation to the context to enable this feature.
106121
* `pa_suspend`: defines an instantaneous block of code to run when an activity gets suspended by the surrounding `pa_when_suspend`. Add `pa_susres_res` annotation to the context to enable this feature.
107122
* `pa_resume`: defines an instantaneous block of code to run when an activity gets resumed by the surrounding `pa_when_suspend`. Add `pa_susres_res` annotation to the context to enable this feature.
108123
124+
In C++ you can also use signals. Signals can be emitted and checked for presence within a tick. The presence is automatically retreated at the begining of the next tick.
125+
Define a signal in a `pa_ctx` with either `pa_def_signal(sig)` or `pa_def_val_signal(T, sig)`. The latter can be used to define signals carrying a value in addition to the presence flag. You also need to annotatate the activity defining signals with either `pa_signal_res` or `pa_enter_res`.
126+
Emit a signal with either `pa_emit(sig)` for pure signals or `pa_emit_val(sig, val)` for valued signals and check for presence by `operator bool`. Extract the value of a valued signal by `sig.val()`. Note that the value will stay in the next ticks even if not emitted again. This can e.g. be used to model flow values which inform about their update by the presence flag.
109127
110128
## Related projects
111129

0 commit comments

Comments
 (0)