... | ... | @@ -8,7 +8,7 @@ One of the best advantages of using such a component is that all the functions g |
|
|
## Adding Tasks
|
|
|
The interface for adding a new task is pretty simple:
|
|
|
```cpp
|
|
|
void add(function_t func, uint32_t intervalMs, uint8_t id, int64_t start = miosix::getTick());
|
|
|
size_t addTask(function_t function, uint32_t period, Policy policy = Policy::SKIP, int64_t startTick = miosix::getTick());
|
|
|
```
|
|
|
Where `function_t` is an `std::function<void()>`.
|
|
|
The parameters are: the function to be periodically executed, the task period in milliseconds, an identifier for the task and the start time (by default set to the current system time).
|
... | ... | @@ -20,10 +20,11 @@ A method for adding tasks that have to be executed only once also exists and is |
|
|
## Example
|
|
|
The following example creates a `TaskScheduler`, adds to it a period task with period 1 second (1000 milliseconds).
|
|
|
```cpp
|
|
|
#include "Common.h"
|
|
|
#include "miosix.h"
|
|
|
#include "scheduler/TaskScheduler.h"
|
|
|
|
|
|
using namespace miosix;
|
|
|
using namespace Boardcore;
|
|
|
|
|
|
void task()
|
|
|
{
|
... | ... | @@ -38,7 +39,7 @@ int main() |
|
|
|
|
|
TaskScheduler::function_t f{&task};
|
|
|
// add task with period 1 second and id 1
|
|
|
scheduler.add(f, 1000, 1);
|
|
|
scheduler.addTask(f, 1000, TaskScheduler::Policy::ONE_SHOT, miosix::getTick());
|
|
|
|
|
|
// start the active object thread
|
|
|
scheduler.start();
|
... | ... | @@ -53,4 +54,5 @@ int main() |
|
|
Thread::sleep(5000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
``` |
|
|
\ No newline at end of file |