@@ -7,6 +7,8 @@ application logic.
7
7
This document assumes familiarity with ` uasyncio ` . See [ official docs] ( http://docs.micropython.org/en/latest/library/uasyncio.html ) and
8
8
[ unofficial tutorial] ( https://github.com/peterhinch/micropython-async/blob/master/v3/docs/TUTORIAL.md ) .
9
9
10
+ # 0. Contents
11
+
10
12
1 . [ An alternative to callbacks in uasyncio code] ( ./EVENTS.md#1-an-alternative-to-callbacks-in-uasyncio-code )
11
13
2 . [ Rationale] ( ./EVENTS.md#2-rationale )
12
14
3 . [ Device driver design] ( ./EVENTS.md#3-device-driver-design )
@@ -23,7 +25,7 @@ This document assumes familiarity with `uasyncio`. See [official docs](http://do
23
25
6.2 [ EButton] ( ./EVENTS.md#62-ebutton )
24
26
  ;  ;  ;  ;  ; 6.2.1 [ The suppress constructor argument] ( ./EVENTS.md#621-the-suppress-constructor-argument )
25
27
  ;  ;  ;  ;  ; 6.2.2 [ The sense constructor argument] ( ./EVENTS.md#622-the-sense-constructor-argument )
26
- [ Appendix 1 Polling] ( ./EVENTS.md-appendix-1-polling )
28
+ [ Appendix 1 Polling] ( ./EVENTS.md# -appendix-1-polling )
27
29
28
30
# 1. An alternative to callbacks in uasyncio code
29
31
@@ -69,6 +71,8 @@ Note the `Stream` mechanism provides another approach which works well with
69
71
devices such as sockets and UARTs. It is less well suited to handling arbitrary
70
72
events, partly because it relies on polling under the hood.
71
73
74
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
75
+
72
76
# 2. Rationale
73
77
74
78
Consider a device driver ` Sensor ` which has a bound ` Event ` object ` .ready ` .
@@ -119,6 +123,8 @@ callbacks:
119
123
execution reaches ` .wait() ` before the ` Event ` is cleared, it will not pause.
120
124
If the ` Event ` is cleared, it will pause until it is set again.
121
125
126
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
127
+
122
128
# 3. Device driver design
123
129
124
130
This document introduces the idea of an event-like object (ELO). This is an
@@ -146,6 +152,8 @@ Drivers exposing `Event` instances include:
146
152
* [ Switch] [ 5m ] Similar but interfaces also expose callbacks.
147
153
* [ Pushbutton] [ 6m ]
148
154
155
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
156
+
149
157
# 4. Primitives
150
158
151
159
Applying ` Events ` to typical logic problems requires two new primitives:
@@ -188,6 +196,8 @@ await WaitAll((event1, event2, WaitAny(event3, event4))).wait()
188
196
This will pause until ` event1 ` and ` event2 ` and either ` event3 ` or ` event4 ` have
189
197
been set.
190
198
199
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
200
+
191
201
# 5. Event based programming
192
202
193
203
## 5.1 Use of Delay_ms
@@ -281,6 +291,8 @@ async def main():
281
291
# Both timers running: run "short press" code
282
292
```
283
293
294
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
295
+
284
296
## 5.3 Application example
285
297
286
298
A measuring instrument is started by pressing a button. The measurement
@@ -314,6 +326,8 @@ async def foo():
314
326
# Normal outcome, process readings
315
327
```
316
328
329
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
330
+
317
331
# 6. Drivers
318
332
319
333
This document describes drivers for mechanical switches and pushbuttons. These
@@ -355,6 +369,8 @@ Bound objects:
355
369
356
370
Application code is responsible for clearing the ` Event ` instances.
357
371
372
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
373
+
358
374
## 6.2 EButton
359
375
360
376
This extends the functionality of ` ESwitch ` to provide additional events for
@@ -443,6 +459,8 @@ the voltage on the pin is gnd.
443
459
Whenever the pin value changes, the new value is compared with ` sense ` to
444
460
determine whether the button is closed or open.
445
461
462
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
463
+
446
464
# Appendix 1 Polling
447
465
448
466
The primitives or drivers referenced here do not use polling with the following
0 commit comments