Task delay start does not seem to work #186
Replies: 2 comments
-
Hard to say without full code. Enabling tasks while OnDisable() is active, equally as disabling tasks in the OnEnable() often leads to interesting unexpected results. I have been there myself many times. |
Beta Was this translation helpful? Give feedback.
-
/*
*/ #include <Arduino.h> #include <TaskScheduler.h> Scheduler ts; void task1Callback(); Task t1(1 * TASK_SECOND, TASK_FOREVER, &task1Callback, &ts, true, &task1OnEnable, &task1OnDisable); void setup() { Serial.println("TaskScheduler Timeout example"); t1.setTimeout(2 * TASK_SECOND); ts.enableAll(); void loop() { void task1Callback() { } bool task1OnEnable() { OUTPUT: |
Beta Was this translation helpful? Give feedback.
-
I am trying to enable a task again with a delay start after it received a timeout. The idea is that is a function takes too long,
to disable it and start it after some time again.
This is what I tried, but the task just keep on running. I receive the disable event, but the delayed start part does not work.
void task1OnDisable() {
if (t1.timedOut()) {
Serial.println("Task 1 has timed out." + String(millis()) + "ms. Restarting... 10S delay before restart.");
t1.setInterval(1 * TASK_SECOND);
t1.setIterations(TASK_FOREVER);
t1.setTimeout(2 * TASK_SECOND);
t1.enableDelayed(10 * TASK_SECOND);//delay 10 seconds before restarting
}
else {
Serial.println("Task 1 has been disabled");
}
}
Beta Was this translation helpful? Give feedback.
All reactions