EventQueue call memberfunction with arguments

I have a problem with using queue.call calling a member function with arguments:

The class has an overloaded member function:

  uint8_t LEDcontrol(bool on);
  uint8_t LEDcontrol(uint8_t control, uint8_t speed, uint8_t coloridx,  uint8_t count = 0);

When I try to call it as callback it fails to compile with error ‘…have incompatible cv-qualifiers’ and ‘couldn’t deduce template parameter ‘R’’:

    queue.call(&finger, &Adafruit_Fingerprint::LEDcontrol, (uint8_t)FINGERPRINT_LED_ON, (uint8_t)0, (uint8_t)FINGERPRINT_LED_BLUE, (uint8_t)0);

Compilation is only fine when I remove the overladed function with the bool argument so that only one member function LEDcontrol exists.

What is the trick to tell the compiler to use the correct function?

error message:

[build] /home/jojo/projects/mbed-ce-hello-world/app_Fingerprint/main.cpp:25:27: error: no matching function for call to 'events::EventQueue::call(Adafruit_Fingerprint*, <unresolved overloaded function type>, uint8_t, uint8_t, uint8_t, uint8_t)'
[build]    25 |                 queue.call(&finger, &Adafruit_Fingerprint::LEDcontrol, (uint8_t)FINGERPRINT_LED_ON, (uint8_t)0, (uint8_t)FINGERPRINT_LED_BLUE, (uint8_t)0);

with some help I’ve got the solution, it needs a static_cast to help the compiler to find the correct member function. Because in call() the vararg is the same for both functions.

	// fingerprint detect action
	wakeupFP.fall( []() {
		queue.call(&finger, static_cast<uint8_t(Adafruit_Fingerprint::*)(uint8_t, uint8_t, uint8_t, uint8_t)>(&Adafruit_Fingerprint::LEDcontrol), 
			(uint8_t)FINGERPRINT_LED_ON, (uint8_t)0, (uint8_t)FINGERPRINT_LED_BLUE, (uint8_t)0);
	});


	// fingerprint release action
	wakeupFP.rise( []() {
		queue.call(&finger, static_cast<uint8_t(Adafruit_Fingerprint::*)(uint8_t, uint8_t, uint8_t, uint8_t)>(&Adafruit_Fingerprint::LEDcontrol), 
			(uint8_t)FINGERPRINT_LED_OFF, (uint8_t)0, (uint8_t)FINGERPRINT_LED_BLUE, (uint8_t)0);
	});

1 Like