Closed sadilekivan closed 1 year ago
hi @sadilekivan. I understand your use case.
However, it is not trivial:
The task schedule is driven by a current requested delay, which can be the same as the currently requested interval or different in case an explicit delay(delayTime)
was called.
If the task for which you are changing the interval is not active, then it is simple - delay and interval are the same.
However (and I realize this may not be your case, but I have to think about the general use of the library), the task you are changing the interval for is currently delayed for a different interval - what should be done then?
Example: let's say your interval is 100 ms and your current delay is 50 ms, and you are 25 ms into the interval.
Your task should run in 25 ms.
If you change the interval to 200 ms, what happens to the current task? Should it still run in 25 ms? Or should it also be recalculated to be 125 ms from now?
I think the safe way is to give programmers a choice:
I will push v3.8.0 into the test branch soon for you to play with and confirm
Thanks for the explanation, I understand the point of delay and agree with the solution of having a choice. Happy to test when it will be possible!
Just pushed 3.8.0 into testing branch - whenever you have time!
void Task::setIntervalNodelay (unsigned long aInterval, unsigned int aOption) {
Options:
#define TASK_INTERVAL_KEEP 0
#define TASK_INTERVAL_RECALC 1
#define TASK_INTERVAL_RESET 2
Sorry for the day delay. The function works great and since I have no specific task delays in my code I keep the default argument TASK_INTERVAL_KEEP
, works just as I'd expect, thanks!
I'm setting a task interval with a 100ms read task for an analog input. This analog input calculates the interval of another task that is enabled and disabled by buttons. I can't seem to get the desired result with the
Task::setInterval
function as it is now. Setting the Interval every 100 ms just keeps my task from ever running again, because it recalculates the delay. Commenting outdelay();
helped my issue.I just wanted to mention my case of it being useful to just change the interval of a task, without recalculating
iDelay
. I expected that behavior fromsetInterval
, but had to fiddle with it. Perhaps there would be a use for two functions to set the Interval. One that does it with no precautions and one that recalculates the delay.My changes:
I would also mention that I can get my desired behavior as is by changing the interval only when the analogue value changes, but it still makes some delays that add up when I make a big change or there is noise. And driving a pump with it makes calibrating the frequency a bit more noisy.
For reference here is my code: