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, ¶m, sizeof(param));
Great idea! Thank you, that worked for me!