Compile error with arduino keypad "Event listener"

I have created the function:

void Keypad_apiClass::createKeypadventHandler(void)
{
keypad44.addEventListener(screenState_keyHandler);
}

which will be called in the setup() of my main sketch.
The eventlistener is also defined:

void screenState_keyHandler(KeypadEvent keyPressed)
{
switch(Display_api.screenDisplayID)
{
case 0x0A: //menu screen
switch(keyPressed)
{
case '1':
//go to sensor readings screen
break;

case '2':
//go to system settings screen
break;

case '#':
//go to systemReboot screen
break;

default:
//do nothing
break;
}
break;

default:
break;
}

}

And finally, in the header file, i have the class declaration:

class Keypad_apiClass
{
protected:

public:
void init();
char retrieveKeyPressed(void);
char waitAndRetrieveKeyPressed(void);
uint8_t returnKeyPressed_IntVersion(char keyPressed);
void createKeypadventHandler(void);
void screenState_keyHandler(KeypadEvent keyPressed);
};

I keep getting this compile error:

Compiling 'adutoSecuritySystem' for 'Arduino Mega w/ ATmega2560 (Mega 2560)'
keypad_api.cpp:In member function 'void Keypad_apiClass::createKeypadventHandler()'
keypad_api.cpp:112:50: error: no matching function for call to 'Keypad::addEventListener()'
keypad_api.cpp:candidate is
Keypad.h:addEventListener(void ()(char))
Keypad.h:no known conversion for argument 1 from '' to 'void (
)(char)'
Error compiling

It would seem that the addEventListener is not accepting the type of "screenState_keyHandler".
I'm not sure how to fix this.
Any help will be appreciated. Thanks. :slight_smile:

First...why does NOBODY every put there code in code tags?!?!?!

Yay code tags, click the </> button

Second...where is the class KeypadEvent?

Thanks for the quick reply :slight_smile:
It's my first time using the forum.

KeypadEvent is not a class, it's actually a typedef, which can be seen in the keypad.h library:

 typedef char KeypadEvent;

This is the eventListener function declaration:

void Keypad_apiClass::createKeypadventHandler(void)
{
   keypad44.addEventListener(screenState_keyHandler);
}

The "screenState_keyHandler" is defined:

void screenState_keyHandler(KeypadEvent keyPressed)
{
   switch(Display_api.screenDisplayID)
   {
      case 0x0A:      //menu screen
      switch(keyPressed)
      {
         case '1':
         //go to sensor readings screen
         break;

         case '2':
         //go to  system settings screen
         break;

         case '#':
         //go to  systemReboot screen
         break;

         default:
         //do nothing
         break;
      }
      break;

      default:
      break;
   }

}

And of course, the function prototype is included in the corresponding header file:

class Keypad_apiClass
{
 protected:


 public:
   void init();
   char retrieveKeyPressed(void);
   char waitAndRetrieveKeyPressed(void);
   uint8_t returnKeyPressed_IntVersion(char keyPressed);
   void createKeypadventHandler(void);
   void screenState_keyHandler(KeypadEvent keyPressed);
};

And here's the compile error:

Compiling 'adutoSecuritySystem' for 'Arduino Mega w/ ATmega2560 (Mega 2560)'
keypad_api.cpp:In member function 'void Keypad_apiClass::createKeypadventHandler()'
keypad_api.cpp:112:50: error: no matching function for call to 'Keypad::addEventListener(<unresolved overloaded function type>)'
keypad_api.cpp:candidate is
Keypad.h:addEventListener(void (*)(char))
Keypad.h:no known conversion for argument 1 from '<unresolved overloaded function type>' to 'void (*)(char)'
Error compiling

I can see that the addEventListener accepts functions of type "void (*)(char) " as the parameter.
So where in my code do I have to fix this?

First, shouldn't createKeypadventHandler(void); be spelled with "Event"?

Second, please include the "keypad.h" file, because addEventListener isnt declared anywhere in the included files.

Thirdly,

keypad44.addEventListener(screenState_keyHandler);

you use screenState_keyHandler function as a parameter...but...

void screenState_keyHandler(KeypadEvent keyPressed);

it has a parameter...
I'm not amazing a programming, but I'm pretty sure if the function calls for a parameter, it needs a parameter...

I'm pretty sure that is what this error is talking about, it is expecting 1 thing and cannot convert to another

Keypad.h:no known conversion for argument 1 from '<unresolved overloaded function type>' to 'void (*)(char)'
  1. That was just a typo. That's fixed.
    2.The keypad.h file is included. I just didnt want to include the whole code. I only included the parts relevant to the problem.
  2. I'm following an example from here:

http://playground.arduino.cc/KeypadTutorial/EventSerialKeypad

Observe that when the "keypadEvent" is defined just below the loop() function. Also, observe that "keypadEvent" is passed as a parameter to keypad.addEventListener() in the setup() function.

That's exactly what I did too. I defined "screenState_keyHandler" and then pass it as a parameter:

keypad44.addEventListener(screenState_keyHandler);

So what exactly am I overlooking?

Can you attach all of your code, I'm trying to find any differences, but, I can't follow all of your snippets.