vendredi 12 juin 2015

Pass a callback function with a parameter to a function

I want to call the following function and pass it a function with a parameter. The purpose of that is that it should call the function with my specified parameter so I know what triggered the function (in that case a gpio pin on the Raspberry Pi).

int wiringPiISR (int pin, int edgeType,  void (*function)(void));

Currently I have:

for (int i = 0; i < myValues.size(); ++i){
int myValue = myValues[i];
wiringPiISR(myValue, INT_EDGE_RISING, &myCallback(myValue));
}

Though this is giving me the following error:

error: lvalue required as unary ‘&’ operand

Which I can't really understand as to my understanding, myValue is an lvalue or is it not?

Is it what I want do even possible? If so how? The function wiringPiISR is from a library called wiringPi and I would like to avoid modifying it as much as possible.

Aucun commentaire:

Enregistrer un commentaire