Need Help for compiler error

20 Jan 2012

Hello guys

I am writting an brand new class for keypad interrupt and I encountering several problem for my program and I dont understand what is the problem about, hope you guys can help me, here are some of my errors

1) _row1trig.rise(&trigRow1); "no instance of overloaded function "mbed::InterruptIn::rise" matches the argument list" in file "/keypad.cpp", Line: 18, Col: 42

2) I received some of the error saying that some of my variable (_cols, _row1Name etc etc) is not defined but however i had already defined it, so i not sure what is the problem

Here is my code, really hope you guys can help me thanks!

#include "keypad.h"

Keypad::Keypad(PinName col1, PinName col2, PinName col3, PinName col4,
       PinName row1, PinName row2, PinName row3, PinName row4):
  _row1(row1), _row2(row2), _row3(row3), _row4(row4), _cols(col1, col2, col3, col4),
  _row1trig(row1), _row2trig(row2), _row3trig(row3), _row4trig(row4),
 _row1Name(row1), _row2Name(row2), _row3Name(row3), _row4Name(row4)
{  

}


int Keypad::start()
{
      _cols = 0x0F;
  
  // Attach triggers
  _row1trig.rise(&trigRow1);   
  
  //"no instance of overloaded function "mbed::InterruptIn::rise" matches the argument list" in file "/keypad.cpp", Line: 18, Col: 42
  
  _row2trig.rise(&trigRow2);
  _row3trig.rise(&trigRow3);
  _row4trig.rise(&trigRow4);
}
    
int Keypad::stop()
{
  return 0;
}

void trigRow1()
{
  checkCol(_row1Name);
}

void trigRow2()
{
  checkCol(_row2Name);
}

void trigRow3()
{
  checkCol(_row3Name);
}

void trigRow4()
{
  checkCol(_row4Name);
}

void checkCol(char row){
  DigitalOut p(row);
  p = 0x1;
  _cols.input();
  unsigned char cols = _cols.read();
  if(cols) {
     cols = _lg2(cols);
    
}

char Keypad::getIndex()
{
  _index = keys(unsigned char row, unsigned char col);
}

20 Jan 2012

.rise(&Keypad::trigRow2,this)

25 Jan 2012

Hello Rene, what does the this mean? i dont really get it, hope you can help

25 Jan 2012

the line

_row1trig.rise(&trigRow1)

wants to get the address of the trigRow1 function and give it as parameter to the rise method. But writing it this way only works for C code. If you have a class member function, you need to write it as Rene put it.

For your second error, you would need to show your header file, and the exact error message you get (esp. where the error is reported).

26 Jan 2012

Hi Hendrik, Oh ok i had solve that, thanks ermm here is my header file

#ifndef KEYPAD_H
#define KEYPAD_H

#include "mbed.h"

#define KEY_RELEASED   '\0'


class Keypad {
public:
    Keypad(PinName col1, PinName col2, PinName col3, PinName col4,
           PinName row1, PinName row2, PinName row3, PinName row4);


    int   start();   // Energize the column pins
    int   stop();    // Deenerguze the column pins

    char  getIndex();

    bool  isTriggered() {
        bool ret = _triggered;
        _triggered = false;
        return ret;
    };

private:
    char         _index;     // index of the key pressed
    bool         _triggered; // True: triggered. Will be reset after getIndex();
    PinName      _row1Name, _row2Name, _row3Name, _row4Name,
    _col1Name, _col2Name, _col3Name, _col4Name;
    DigitalIn    _row1, _row2, _row3, _row4;
    BusOut       _cols;
    bool         _use4pins;
    InterruptIn  _row1trig, _row2trig, _row3trig, _row4trig;
    
    char row, cols;
    
    void         trigRow1();
    void         trigRow2();
    void         trigRow3();
    void         trigRow4();


    unsigned char _lg2 (unsigned char cols) {
        return cols & 1 ? 0 : cols & 2 ? 1 : cols &4 ? 2 : 3;
    }

};


#endif

edit:

Like i say on the 1st post, it is on the _rowtrig1.rise(&Keypad::trigRow1,this); I still dont know how to solve it, hope you guys can help me! Really appreciate the help!

26 Jan 2012

Daryl Tan Wei Guang wrote:

Like i say on the 1st post, it is on the _rowtrig1.rise(&Keypad::trigRow1,this); I still dont know how to solve it, hope you guys can help me! Really appreciate the help!

Sorry I've swapped the 2 parameters, so please again swap them.

But aren't you able to read the documentation a little bit?

26 Jan 2012

Which documentation? I look at the compiler error page, but it still cant be solve, the same error keep appear i wonder could it be the way i wrote it is wrong?

26 Jan 2012

Handbook->interruptIn

26 Jan 2012

I had look at it but it seems like i still cant solve it, I wonder could it be i wrote wrongly at the void area

26 Jan 2012

Daryl Tan Wei Guang wrote:

Which documentation? I look at the compiler error page, but it still cant be solve, the same error keep appear i wonder could it be the way i wrote it is wrong?

The page Rene pointed you to shows an example of what you need to write:

_interrupt.rise(this, &Counter::increment);

If you want to know more detail, have a look at the [[|http://www.cprogramming.com/tutorial/function-pointers.html|function pointer tutorial]].

For your other compile error(s):

  • you need to declare that the methods trigRow* belong to the Keypad class - prefix them with Keypad::
  • add the checkCol to the class definition
  • fix the checkIndex method - right now it contains a method declaration?

There are still other errors, where I'm not sure what you want to express with your code (e.g. the first line of the checkCol method).