Skip to content

Commit bc4a7ac

Browse files
committed
run() removed to improve compatibility - call loop() repeatedly instead
1 parent ac03f7d commit bc4a7ac

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

README.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ started (in what time since now) and how many times they should be invoked
1212
(only once, X times or forever).
1313

1414
The "co-operation" is best achieved by creating small, short running tasks.
15-
Basically wherever you'd need to include the infamous *delay()* call in your Arduino program
15+
Basically wherever you'd need to include the infamous <code>delay()</code> call in your Arduino program
1616
that's the place where you actually want to break the code flow, split
1717
the source code into separate functions and let Tasker run them as separate tasks.
1818

@@ -31,8 +31,12 @@ illustrates the whole API and its best usage.
3131
ChangeLog
3232
---------
3333
* version 1.1 adds clear example of DS18B20 handling
34+
3435
* version 1.2 adds optional priorities when defining tasks
3536

37+
* version 1.3 removes the <code>run()</code> function - please call <code>tasker.loop()</code> in your Arduino <code>loop()</code> function instead. This makes **Tasker** much more Arduino friendly and compatible with far more platforms where the Arduino 'kernel' does some housekeeping behind the scenes and needs the <code>loop()</code> to be running for it. It also allowed me to remove the <code>yield()</code> call that didn't really bring anything but issues in compiling on some platforms.
38+
39+
3640
How to use
3741
----------
3842

@@ -70,24 +74,8 @@ Tasker API
7074
May pass the <code>optional_int</code> parameter into the called function.
7175
When the task finishes (after its last iteration) its Tasker slot is made available for new tasks.
7276
73-
* <code>run()</code> when called it starts the Tasker scheduler and will never return.
74-
Best to be called as the very last command of the Arduino's <code>setup()</code> function:
75-
76-
```cpp
77-
void setup() {
78-
tasker.setInterval(...);
79-
tasker.run(); // will not return
80-
}
81-
82-
void loop() {
83-
// unused, never called
84-
}
85-
```
86-
87-
* optional: if you, for whatever reason, don't want to let the <code>Tasker.run()</code>
88-
govern all of your running code and wish to run Tasker together with some
89-
existing code you can omit the <code>run()</code> and call the <code>Tasker.loop()</code>
90-
repeatedly instead.
77+
* <code>loop()</code> when called it runs the Tasker scheduler and process all waiting tasks, then ends.
78+
Best to be called as often as possible, ideally in the Arduino's <code>loop()</code> function:
9179
9280
```cpp
9381
void setup() {
@@ -96,7 +84,6 @@ Tasker API
9684
9785
void loop() {
9886
tasker.loop(); // needs to be called as often as possible
99-
// legacy code here
10087
}
10188
```
10289

Tasker.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Tasker
2323
bool setInterval(TaskCallback func, unsigned long interval, int param = 0, byte prio = TASKER_MAX_TASKS);
2424
bool setRepeated(TaskCallback func, unsigned long interval, unsigned int repeat, int param = 0, byte prio = TASKER_MAX_TASKS);
2525
void loop(void);
26-
void run(void) { while(true) { loop(); yield(); } }
2726
private:
2827
struct TASK {
2928
TaskCallback call;
@@ -90,7 +89,6 @@ void Tasker::loop(void)
9089
}
9190
if (t_prioritized)
9291
break;
93-
yield();
9492
now = millis();
9593
}
9694
if (inc)

examples/DallasTemperature/DallasTemperature.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ void setup() {
2929
sensor.setWaitForConversion(false);
3030
// read temperature every 5 seconds
3131
tasker.setInterval(startConversion, 5000);
32-
tasker.run();
3332
}
3433

35-
void loop() { }
34+
void loop() {
35+
tasker.loop();
36+
}

examples/MultiBlink/MultiBlink.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ void setup()
4242
tasker.setInterval(blink2, 750, 12);
4343
// called every 1000 milliseconds 10 times, with optional parameter pin = 11
4444
tasker.setRepeated(blink2, 1000, 10, 11);
45-
46-
tasker.run(); // never returns
4745
}
4846

4947
void loop()
5048
{
49+
tasker.loop();
5150
}
5251

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Tasker KEYWORD1
33
setTimeout KEYWORD2
44
setInterval KEYWORD2
55
setRepeated KEYWORD2
6-
TASKER_MAX_TASKS KEYWORD2
6+
loop KEYWORD2
7+
TASKER_MAX_TASKS LITERAL1

0 commit comments

Comments
 (0)