0

I am making a new library that will utilize PinChangeInt's library. My intention is to further simplify repetitive code by creating a library. (This is to allow for multiple PPM channels without rewriting a bunch of code for each channel i decide to add.) Since i understand OOP i knew that i could go the route of make my own library.

The problem i'm having right now, is that the library is returning an undefined reference. The IDE i'm using is UECIDE with QTcreator on the side to help me with my syntax. The compiler is avr-gcc. The chip is an Arduino Uno. The problem i'm recieving is

C:...\RCRoomba_TestPulseV2.cpp.o: In function '__static_initialization_and_destruction_0':
C:...\RCRoomba_TestPulseV2.ino:5: undefined reference to 'PPMintIn::PPMintIn(int)'
C:...\RCRoomba_TestPulseV2.cpp.o: In function 'setup':
C:...\RCRoomba_TestPulseV2.ino:9: undefined reference to 'PPMintIn::begin()'
Failed linking sketch

I tried to define the variables in my h and cpp files but it doesn't seem to be fixing the problem.

Here is the .ino code.
for some reason UECIDE can't see the Pinchange and PPMint libraries

#include "arduino.h"
#include "C:\Users\User\Documents\UECIDE\libraries\PinChangeInt\PinChangeInt.h"
#include "C:\Users\User\Documents\UECIDE\libraries\PPMintIn\PPMintIn.h"

PPMintIn CH1(A0);

void setup(){
    Serial.begin(115200);
    CH1.begin();
}

void loop(){
}

Here is the .cpp code

#include "arduino.h"
#include "ppmintin.h"
#include "PinChangeInt.h"
//defined these
volatile int pwm_value = 0; 
volatile int prev_time = 0;
uint8_t latest_interrupted_pin = 0;

PPMintIn::PPMintIn(int pin){
    pinMode(pin, INPUT);\
    digitalWrite(pin, HIGH);
    _pin = pin;
}

void PPMintIn::rising(){
    PPMintIn::latest_interrupted_pin = PCintPort::arduinoPin;
    PCintPort::attachInterrupt(latest_interrupted_pin, &rising, RISING);
    PPMintIn::pwm_value = micros()-PPMintIn::prev_time;
}

void PPMintIn::falling(){
    PPMintIn::latest_interrupted_pin=PCintPort::arduinoPin;
    PCintPort::attachInterrupt(latest_interrupted_pin, &rising, RISING);
    PPMintIn::pwm_value = micros()-PPMintIn::prev_time;
}

void PPMintIn::begin(){
    PCintPort::attachInterrupt(_pin, &rising, RISING);
}

void PPMintIn::getSignal(){
    return(PPMintIn::pwm_value);
}

Here is the .h code

#ifndef PPMINTIN_H
#define PPMINTIN_H

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #else
  #include "WProgram.h"
#endif
#include "PinChangeInt.h"

class PPMintIn{
public:
    PPMintIn(int pin);
    void begin();
    void getSignal();
    int _pin;
    volatile int pwm_value;
    volatile int prev_time;
    uint8_t latest_interrupted_pin;
private:
    void rising();
    void falling();
};

#endif // PPMINTIN_H

here is the full thing in github in case I didn't supply it here. https://github.com/tisaconundrum2/PPMintIn

  • The IDE probably can't parse those full paths. Why are you using them instead of trusting that the IDE knows where the headers are? – Ignacio Vazquez-Abrams Aug 24 '15 at 18:59
  • because when i use the debug console included with IDE it can't find the files. It's only when i do the full paths, does it know what i want – tisaconundrum Aug 24 '15 at 19:00
  • Looking for header file C:\Users\User\Documents\Arduino\RCRoomba_TestPulseV2\libraries\PinChangeInt\PinChangeInt.h Library.java 98 (<init>): Looking for header file :\Users\User\Documents\Arduino\RCRoomba_TestPulseV2\libraries\PPMintIn\PPMintIn.h it just scrolls through this forever – tisaconundrum Aug 24 '15 at 19:01
  • i.imgur.com/awwtHKj.png – tisaconundrum Aug 24 '15 at 19:03
  • No, the compiler knows what you want. The IDE has no clue, so it doesn't include the libraries for compilation and linking. – Ignacio Vazquez-Abrams Aug 24 '15 at 19:06
0

As both Majenko and I tried to explain in Pass a member function pointer to a method of a foreign class (EDB Lib) you can't pass a class member function where a static function is expected.


Your error is on:

PCintPort::attachInterrupt(latest_interrupted_pin, &rising, RISING);

Error:

/home/nick/sketchbook/libraries/PPMintIn/ppmintin.cpp: In member function ‘void PPMintIn::rising()’:
/home/nick/sketchbook/libraries/PPMintIn/ppmintin.cpp:22: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say ‘&PPMintIn::rising’

PCintPort::attachInterrupt expects a PCIntvoidFuncPtr variable:

int8_t PCintPort::attachInterrupt(uint8_t arduinoPin, PCIntvoidFuncPtr userFunc, int mode)

That is:

typedef void (*PCIntvoidFuncPtr)(void);

That is a static function (not a class function).

However you have it as a class function:

class PPMintIn{
public:
    PPMintIn(int pin);
    void begin();
    void getSignal();
    int _pin;
    volatile int pwm_value;
    volatile int prev_time;
    uint8_t latest_interrupted_pin;
private:
    void rising();
    void falling();
};

Now you can make rising and falling static but now they can't access any of the class variables (eg. pwm_value, prev_time, latest_interrupted_pin).

The whole thing needs a redesign. You could try making PPMintIn a namespace rather than a class.


Regarding one of the comments:

Error message

Unless your class implements operator() this line doesn't make sense:

chan1(15);

Please copy and paste error messages into the post, don't make people go to Imgur to find a screenshot of some text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.