mikaelpatel / Arduino-Scheduler

Portable Cooperative Multi-tasking Scheduler for Arduino

Home Page:https://mikaelpatel.github.io/Arduino-Scheduler/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing arguments to function

axelbusch opened this issue · comments

I try to adjust the SchedulerTaskCompletionQueue example. I would like to pass some arguments to the function that is executed by the worker. Such as:

void print(char c){
Serial.println(c);
}
[..]
char c = 'a';
task_t task = print(c);
taskq.push(&task);

Unfortunately I can only pass functions without any parameters. Is that possible and how?

Nothing is impossible :) there are several approaches depending how high level syntax is wanted. The simplest is to add an environment pointer i.e. void* as a generic pointer to the task function and push a parameter block together with the function pointer.
taskq.push(&task, &param, sizeof(param));

Great idea! Thank you, that worked for me!