Skip to content

Commit 7cfa4c2

Browse files
authored
markdown formatting changes
1 parent 42037aa commit 7cfa4c2

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

README.md

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ChangeLog
3333
* version 2.0 brings two new great features: now you can **modify scheduled tasks** and also **cancel them**.
3434
- to modify task setup (change their timing or priority) simply call the `setTimeout()`/`setInterval()`/`setRepeated()` functions again.
3535
- 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()`).
3737
- to find out when a given task will be called use the new `scheduledIn()` function.
3838
- 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()`.
3939
- 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
5151
---------------------------
5252
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:
5353

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:
56-
| Old code | New code |
57-
| ------------------------------ | ------------------------------ |
58-
| `Tasker tasker;` | `Tasker tasker(TRUE);` |
54+
### 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);`|
5960

6061
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;`
6162

62-
### run() to loop()
63+
### change run() to loop()
6364
If you were using the `tasker.run()` function please change it for calling `tasker.loop()` in your Arduino loop():
65+
66+
old code:
6467
```cpp
6568
// originally Tasker suggested to call run() as the last thing in setup()
6669
void setup() {
@@ -71,6 +74,7 @@ If you were using the `tasker.run()` function please change it for calling `task
7174
void loop() { }
7275
```
7376
77+
new code:
7478
```cpp
7579
// now Tasker needs to have tasker.loop() called in Arduino loop()
7680
void setup() {
@@ -84,9 +88,10 @@ If you were using the `tasker.run()` function please change it for calling `task
8488

8589
### remove unused parameter from task declaration
8690
If you don't use the additional parameter in your task/function then simply remove it:
87-
| Old code | New code |
88-
| ------------------------------------- | ------------------------------ |
89-
| `void myFunction(int /* unused */) {` | `void myFunction() {` |
91+
92+
| old code | new code |
93+
|--------------------------------------|------------------------------|
94+
| `void myFunction(int /* unused */) {`| `void myFunction() {` |
9095

9196
### optional int parameter must be nonnegative
9297
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
108113
is FALSE then the Tasker considers all scheduled tasks equal. More about priorities later.
109114

110115
```cpp
111-
Tasker tasker; // creates non-prioritizing tasker
112-
Tasker tasker(TRUE); // creates prioritizing tasker
116+
Tasker tasker; // creates non-prioritizing tasker
117+
Tasker tasker(TRUE); // creates prioritizing tasker
113118
```
114119
115-
* `setTimeout(function_name, time_in_milliseconds [, optional_int [, optional_priority]])`
116-
Tasker will call the *function_name* in *time_in_milliseconds* from now.
120+
* `setTimeout(function, time_in_milliseconds [, optional_int [, optional_priority]])`
121+
Tasker will call the *function* in *time_in_milliseconds* from now.
117122
It will run the function only once. May pass the *optional_int* parameter (nonnegative) into the called function.
118123
When the task finishes its Tasker slot is made available for new tasks (more about slots later).
119124
120-
* `setInterval(function_name, time_in_milliseconds [, optional_int [, optional_priority]])`
121-
Tasker will call the *function_name* repeatedly and forever, every
125+
* `setInterval(function, time_in_milliseconds [, optional_int [, optional_priority]])`
126+
Tasker will call the *function* repeatedly and forever, every
122127
*time_in_milliseconds* from now on.
123128
May pass the *optional_int* parameter (nonnegative) into the called function.
124129
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*,
127132
every *time* (in_milliseconds) from now on.
128133
May pass the *optional_int* parameter (nonnegative) into the called function.
129134
When the task finishes (after its last iteration) its Tasker slot is made available for new tasks.
130135
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)
133138
it will cancel any further execution of the function and will remove it from its scheduler queue instantly.
134139
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
136141
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.
138143
139-
* `clearTimeout(function_name [, optional_int ])` is identical to `cancel()`, it just
144+
* `clearTimeout(function [, optional_int ])` is identical to `cancel()`, it just
140145
uses the well known Javascript API.
141146
142-
* `clearInterval(function_name [, optional_int ])` is identical to `cancel()`, it just
147+
* `clearInterval(function [, optional_int ])` is identical to `cancel()`, it just
143148
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.
144151
145152
* `loop()` when called it runs the Tasker scheduler and process all waiting tasks, then ends.
146153
It's best to let your program call this Tasker function as often as possible, ideally in the Arduino's `loop()` function:
147154
148155
```cpp
149-
void loop() {
150-
tasker.loop();
151-
}
156+
void loop() {
157+
tasker.loop();
158+
}
152159
```
153160

154161
Task priorities (optional)
@@ -159,10 +166,10 @@ priority than those added earlier, unless you specify their priority with
159166
optional parameter: the lower its value the higher priority, 0 = highest priority.
160167

161168
```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
166173
```
167174
168175
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
175182
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.
176183
177184
```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, ..);
182189
```
183190

184191
Caveats
@@ -189,8 +196,8 @@ simultaneously but you might want to increase this number - or even decrease, to
189196
save the precious RAM (each slot takes 14 bytes of RAM).
190197

191198
```cpp
192-
#define TASKER_MAX_TASKS 32
193-
#include "Tasker.h"
199+
#define TASKER_MAX_TASKS 32
200+
#include "Tasker.h"
194201
```
195202
196203
Good news is that Tasker automatically releases slots of finished tasks (those

0 commit comments

Comments
 (0)