arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.21k stars 221 forks source link

Task default constructors sets iterations count incorrectly according to Wiki #138

Closed xpalaa00 closed 2 years ago

xpalaa00 commented 2 years ago

I have tried to write some testing code using TaskScheduler library to learn how to work with it. The code was simple, just blinked with LED, but it didn't work. I've tried to construct one global task to execute using a default constructor without any parameters and in setup() function I've set task parameters such as call period (interval) and callback method as shown at the picture bellow.

obrazek

While I was looking for a mistake, I also tried to print all set values of the task including that weren't set by me, but were default.

According to code shown above I've got these values: interval = 1000 ms, enabled status = true, but I've been supprised by the iterations count = 0.

I've read Yours wiki and I think that the iterations count should be set to -1 by default according to text bellow:

"Default constructor. Takes no parameters and creates a task that could be scheduled to run at every scheduling pass indefinitely, but does not have a callback method defined, so no code execution will actually take place."

Looking into code of the library TaskSchedulerDeclarations.h on the lines 163 and 165 there is preset value 0 for iterations parameter. https://github.com/arkhipenko/TaskScheduler/blob/776cb42397c6e059612cbb47709820c2d35386d4/src/TaskSchedulerDeclarations.h#L163 https://github.com/arkhipenko/TaskScheduler/blob/776cb42397c6e059612cbb47709820c2d35386d4/src/TaskSchedulerDeclarations.h#L165

After inserting line which sets iterations count of the task explicitely to indefinitely (-1) the code worked properly.

Is the wiki information mistaken and the 0 value has specific reason, or the 0 value is incorrectly defined as default, or I've just understood the information wrongly? Thank You for answer gratefully.

arkhipenko commented 2 years ago

Fixed WiKi. Thank you for spotting this