You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-37Lines changed: 44 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ ChangeLog
33
33
* version 2.0 brings two new great features: now you can **modify scheduled tasks** and also **cancel them**.
34
34
- to modify task setup (change their timing or priority) simply call the `setTimeout()`/`setInterval()`/`setRepeated()` functions again.
35
35
- to stop/cancel a scheduled task and remove from Tasker's queue call the new function `cancel()`.
36
-
- if familiar with Javascript feel free to use `clearTimeout()`or`clearInterval()` functions (identical with `cancel()`).
36
+
- if familiar with Javascript you can call `clearTimeout()`and`clearInterval()` (identical with `cancel()`).
37
37
- to find out when a given task will be called use the new `scheduledIn()` function.
38
38
- another important change is making the optional `int` parameter passed into your functions truly optional, so if you don't want to use it you don't need to declare your function with it. I.e. the `void myFunction(int /*unused*/)` is a history now - use simple and clean `void myFunction()`.
39
39
- Please read the *Upgrading from v1.2 to v2.0* paragraph below for further details.
@@ -51,16 +51,19 @@ Upgrading from v1.2 to v2.0
51
51
---------------------------
52
52
Versions 1.3-2.0 released in May 2018 introduced some small API changes that were not backward compatible so you may need to update your source code (see below for details). Changing library API is always better avoided but the collected user feedback in last year led me to simplify the API and made it more intuitive to use, which is so good thing that it was worth changing the API a bit. These are the things you might need to update in your application when using Tasker:
53
53
54
-
### default value of Tasker constructor
55
-
If you rely on the prioritized task execution (most users don't!) then enable it explicitly by adding (TRUE) as the ctor parameter:
### default value of Tasker constructor has changed
55
+
If you rely on the prioritized task execution (most users don't!) then enable it explicitly by adding (TRUE) as the ctor parameter because it's no longer enabled by default:
56
+
57
+
| old code | new code |
58
+
|----------------------|-----------------------|
59
+
|`Tasker tasker;`|`Tasker tasker(TRUE);`|
59
60
60
61
Let me repeat that the prioritized task execution may cause that some tasks with lower priority are sometimes not executed if the tasks with higher priority spent too much time. This might lead to some head scratching when you're missing some function calls randomly. So most users will be happier with the default constructor without any parameter: `Tasker tasker;`
61
62
62
-
### run() to loop()
63
+
### change run() to loop()
63
64
If you were using the `tasker.run()` function please change it for calling `tasker.loop()` in your Arduino loop():
65
+
66
+
old code:
64
67
```cpp
65
68
// originally Tasker suggested to call run() as the last thing in setup()
66
69
voidsetup() {
@@ -71,6 +74,7 @@ If you were using the `tasker.run()` function please change it for calling `task
71
74
void loop() { }
72
75
```
73
76
77
+
new code:
74
78
```cpp
75
79
// now Tasker needs to have tasker.loop() called in Arduino loop()
76
80
void setup() {
@@ -84,9 +88,10 @@ If you were using the `tasker.run()` function please change it for calling `task
84
88
85
89
### remove unused parameter from task declaration
86
90
If you don't use the additional parameter in your task/function then simply remove it:
Functions/tasks can be called with an optional `int` parameter. Since v2.0 its value (specified in ``setTimeout()`` etc) must be nonnegative, i.e. 0 or greater.
@@ -108,47 +113,49 @@ Tasker API
108
113
is FALSE then the Tasker considers all scheduled tasks equal. More about priorities later.
Tasker will call the *function* repeatedly and forever, every
122
127
*time_in_milliseconds* from now on.
123
128
May pass the *optional_int* parameter (nonnegative) into the called function.
124
129
125
-
* `setRepeated(function_name, time, number_of_repeats [, optional_int [, optional_priority]])`
126
-
Tasker will call the *function_name* repeatedly for *number_of_repeats*,
130
+
* `setRepeated(function, time, number_of_repeats [, optional_int [, optional_priority]])`
131
+
Tasker will call the *function* repeatedly for *number_of_repeats*,
127
132
every *time* (in_milliseconds) from now on.
128
133
May pass the *optional_int* parameter (nonnegative) into the called function.
129
134
When the task finishes (after its last iteration) its Tasker slot is made available for new tasks.
130
135
131
-
* `cancel(function_name [, optional_int ])`
132
-
If Tasker has the *function_name* in its scheduler queue (added there by either of those three functions above)
136
+
* `cancel(function [, optional_int ])`
137
+
If Tasker has the *function* in its scheduler queue (added there by either of those three functions above)
133
138
it will cancel any further execution of the function and will remove it from its scheduler queue instantly.
134
139
Its Tasker slot is made available for new tasks, of course.
135
-
If you happened to add certain *function_name* to Tasker several times with different optional int parameters
140
+
If you happened to add certain *function* to Tasker several times with different optional int parameters
136
141
then you need to use the same optional int parameter when calling the `cancel()` so that Tasker
137
-
knows which of the several task slots with the same *function_name* to remove.
142
+
knows which of the several task slots with the same *function* to remove.
138
143
139
-
* `clearTimeout(function_name [, optional_int ])` is identical to `cancel()`, it just
144
+
* `clearTimeout(function [, optional_int ])` is identical to `cancel()`, it just
140
145
uses the well known Javascript API.
141
146
142
-
* `clearInterval(function_name [, optional_int ])` is identical to `cancel()`, it just
147
+
* `clearInterval(function [, optional_int ])` is identical to `cancel()`, it just
143
148
uses the well known Javascript API.
149
+
150
+
* `scheduledIn(function [, optional_int ])` returns number of milliseconds till calling the given *function*. Returned 0 means that *function* (with *optional_int*) is not in Tasker's queue so it will never be called.
144
151
145
152
* `loop()` when called it runs the Tasker scheduler and process all waiting tasks, then ends.
146
153
It's best to let your program call this Tasker function as often as possible, ideally in the Arduino's `loop()` function:
147
154
148
155
```cpp
149
-
void loop() {
150
-
tasker.loop();
151
-
}
156
+
void loop() {
157
+
tasker.loop();
158
+
}
152
159
```
153
160
154
161
Task priorities (optional)
@@ -159,10 +166,10 @@ priority than those added earlier, unless you specify their priority with
159
166
optional parameter: the lower its value the higher priority, 0 = highest priority.
160
167
161
168
```cpp
162
-
Tasker tasker(TRUE);
163
-
tasker.setInterval(most_important_fn, ..); // formerly added calls have automatically higher priority
164
-
tasker.setInterval(less_important_fn, ..); // the later added calls the lower priority they have
165
-
tasker.setInterval(highest_priority_fn, .., .., 0); // unless you specify the priority explicitly by the last parameter
169
+
Tasker tasker(TRUE);
170
+
tasker.setInterval(most_important_fn, ..); // formerly added calls have automatically higher priority
171
+
tasker.setInterval(less_important_fn, ..); // the later added calls the lower priority they have
172
+
tasker.setInterval(highest_priority_fn, .., .., 0); // unless you specify the priority explicitly by the last parameter
166
173
```
167
174
168
175
Normally, when there is enough time for calling each of the scheduled task
@@ -175,10 +182,10 @@ If the priorities were disabled (by default the are) then the scheduler would si
175
182
in its queue. If all your tasks are equally important (they most probably are) you might simply ignore the whole idea of priorities and their implementation.
176
183
177
184
```cpp
178
-
Tasker tasker;
179
-
tasker.setInterval(fn, ..);
180
-
tasker.setInterval(equally_important_fn, ..);
181
-
tasker.setInterval(order_doesnt_matter_fn, ..);
185
+
Tasker tasker;
186
+
tasker.setInterval(fn, ..);
187
+
tasker.setInterval(equally_important_fn, ..);
188
+
tasker.setInterval(order_doesnt_matter_fn, ..);
182
189
```
183
190
184
191
Caveats
@@ -189,8 +196,8 @@ simultaneously but you might want to increase this number - or even decrease, to
189
196
save the precious RAM (each slot takes 14 bytes of RAM).
190
197
191
198
```cpp
192
-
#defineTASKER_MAX_TASKS 32
193
-
#include "Tasker.h"
199
+
#defineTASKER_MAX_TASKS 32
200
+
#include "Tasker.h"
194
201
```
195
202
196
203
Good news is that Tasker automatically releases slots of finished tasks (those
0 commit comments