keypad.addEventListener problem

Can somebody plss help me how to put keypad.addEventListener for int function...

MENU3.ino: In function 'void eventSchedM(KeypadEvent)':
MENU3:112: error: invalid conversion from 'int ()()' to 'void ()(char)'
MENU3:112: error: initializing argument 1 of 'void Keypad::addEventListener(void (*)(char))'

void eventSchedM(KeypadEvent key){

switch (keypad.getState()){
case PRESSED:

switch (key){
case 'C':
GLCD.DrawBitmap(viewMenu, 0,0, BLACK);
keypad.addEventListener(eventView2);
break;
case 'A':
//GLCD.DrawBitmap(schedMenu, 0,0, BLACK);
keypad.addEventListener(c1);
//keypad.addEventListener(c1);
//c1();
break;
}
break;

}
}

int c1(){

}

what is eventView2 and cl?
the error is in the line of adding event listener,
either in,

keypad.addEventListener(eventView2);

or

keypad.addEventListener(c1);

and whats this? i think the problem is in here.

int c1(){
  
}

addEventListener only accepts void (*)(char)

why would you want to add an int function??

if the case is you only want to handle int as input, you can just check the input if its a digit or not using "isdigit(key)" of ctype.h library

peanutbread:
Can somebody plss help me how to put keypad.addEventListener for int function...

MENU3.ino: In function 'void eventSchedM(KeypadEvent)':
MENU3:112: error: invalid conversion from 'int ()()' to 'void ()(char)'
MENU3:112: error: initializing argument 1 of 'void Keypad::addEventListener(void (*)(char))'

keypad.addEventListener(name_of_event_function) creates a new call-back function everytime you call it. So everytime you press the A or C key you are creating a duplicate function pointer for the associated name. In your code that would be the function c1(). Also, you are trying to create two event listeners (c1() and eventView2()) when the library only supports one. Unless you understand function pointers you may not want to do that. Plus, you are trying to change the call-back function from a return value of void to int. It doesn't make sense for it to have a return value because it is called within the library and never from your sketch.

It's a bit abstract and if you don't understand call-backs and function pointers then you should follow the EventKeypad.ino example provided with the library.

From the main menu "File -> Examples -> Keypad -> EventKeypad" will load a sketch that demonstrates proper usage.

From your attempts to use addEventListener() I can see that you are struggling with understanding its proper use. I can help you with that but it might be a lot easier if you were to tell me what you are trying to accomplish. Then we might be able to help you design your sketch.

kamijean47:
what is eventView2 and cl?
the error is in the line of adding event listener,
either in,

keypad.addEventListener(eventView2);

or

keypad.addEventListener(c1);

and whats this? i think the problem is in here.

int c1(){

}




addEventListener only accepts void (*)(char)

my problem is I cant use an int function in keypad.addEventListener(c1); because I need to return a value...

void eventView2(KeypadEvent key){
  
switch (keypad.getState()){
    case PRESSED:
    
    
      switch (key){
        case 'C': 
                  GLCD.DrawBitmap(mainMenu, 0,0, BLACK); 
                  keypad.addEventListener(eventMain);
                break;
        case 'A': 
                 GLCD.DrawBitmap(schedMenu, 0,0, BLACK);
                 keypad.addEventListener(eventSchedM);
                 
                break;
      }
    break;
   
}
}

void eventSchedM(KeypadEvent key){
  GLCD.SelectFont(System5x7);
  int j=2;
switch (keypad.getState()){
    case PRESSED:   
      switch (key){
        case 'C': 
                  GLCD.DrawBitmap(viewMenu, 0,0, BLACK); 
                  keypad.addEventListener(eventView2);
                  break;
        case 'A': 

                 c1();
                break;
                
                default:
          GLCD.CursorTo(j+i,3);
          GLCD.print(key);
          i++;
      }
    break;
   
}
}

int c1(){ 
  
  GLCD.SelectFont(System5x7);
  char key = keypad.getKey();
  int j=2;
  
  GLCD.ClearScreen();
  GLCD.print("How many a day:");
  
    switch (keypad.getState()){
    case PRESSED:

        switch (key){
            case 'A':
                     GLCD.DrawBitmap(schedMenu, 0,0, BLACK);
                     keypad.addEventListener(eventSchedM);

                     break;

        }
      break;
  }
  
}

I can't press 'A' in function c1() and everytime I press 'C' in function c1() it will go back in eventView2() function.

And the thing that I wat to achieve is to be able to use key in function c1 becuase I need a value to return...

You don't NEED to return a value. You can set a global variable.