C++ library problems

Hello!
I am writing a small library for reading the pulse width from a RC receiver. I have manage to do this in a normal sketch, but I am having some trouble transferring it to C++.

I can't get my code to compile and I am currently getting this error:

C:\Users\Michael Marne\Desktop\Arduino\arduino-1.0.5\libraries\ReadReceiver\ReadReceiver.cpp: In member function 'void Receiver::attach(uint8_t)':
C:\Users\Michael Marne\Desktop\Arduino\arduino-1.0.5\libraries\ReadReceiver\ReadReceiver.cpp:39: error: no matching function for call to 'PCintPort::attachInterrupt(uint8_t&, void (Receiver::*)(), int)'
C:\Users\Michael Marne\Desktop\Arduino\arduino-1.0.5\libraries\ReadReceiver\/PinChangeInt.h:421: note: candidates are: static int8_t PCintPort::attachInterrupt(uint8_t, void (*)(), int)
C:\Users\Michael Marne\Desktop\Arduino\arduino-1.0.5\libraries\ReadReceiver\ReadReceiver.cpp: In member function 'void Receiver::read(uint8_t, int*)':
C:\Users\Michael Marne\Desktop\Arduino\arduino-1.0.5\libraries\ReadReceiver\ReadReceiver.cpp:51: error: lvalue required as left operand of assignment

Any help is very appriciated,
Thanks in advance,
Kalveo

EDIT: Forgot to attach code :stuck_out_tongue:

ReadReceiver.cpp

#include "ReadReceiver.h"

// <<Constructor>>
Receiver::Receiver(){

}

// <<Destructor>>
Receiver::~Receiver(){}


boolean interruptPins[20] = {0};
int startRise[20] = {0};
int durationRise[20] = {0};
boolean typeOfInterrupt[20] = {0};

// Handle interrupts
void Receiver::onInterrupt(){
	uint8_t intPin = PCintPort::arduinoPin; // Pin on which the interrupt occurred
	
	if (interruptPins[intPin]) {
	
		// Rising edge detected, save start time
		if (!typeOfInterrupt[intPin]){
			startRise[intPin] = micros();
			typeOfInterrupt[intPin] = true;
		}
		// Falling edge detected, calculate duration of "HIGH"
		else {
			durationRise[intPin] = micros() - startRise[intPin];
			typeOfInterrupt[intPin] = false;
		}
	}
}

// Attach to a pin
void Receiver::attach(uint8_t pin){
	interruptPins[pin] = true;
	PCintPort::attachInterrupt(pin, (void*)&Receiver::onInterrupt, CHANGE);
}

// Detach from a pin
void Receiver::detach(uint8_t pin){
	interruptPins[pin] = false;
	PCintPort::detachInterrupt(pin);
}

// Read status of pin
void Receiver::read(uint8_t pin, int *result){
	if (interruptPins[pin]){
		&result = &durationRise[pin];
	}
}

ReadReceiver.h

#include "PinChangeInt.h"

#ifndef ReadReceiver_H
#define ReadReceiver_H

#include <Arduino.h>

class Receiver {
	public:
		Receiver();
		~Receiver();
		void attach(uint8_t pin);
		void detach(uint8_t pin);
		void read(uint8_t pin, int *result);
	
	private:
		void onInterrupt();
};

#endif

ReadReceiver.h (313 Bytes)

ReadReceiver.cpp (1.18 KB)

Ok, so I've managed to solve the problems I initially asked about, but now I've got a really weird one.

In my library I am using PinChangeInt.h, which somehow get included several times, or atleast some functions in it get defined multiple times.

ReadReceiver\ReadReceiver.cpp.o: In function `PCintPort::enable(PCintPort::PCintPin*, void (*)(), unsigned char)':
/PinChangeInt.h:366: multiple definition of `PCintPort::enable(PCintPort::PCintPin*, void (*)(), unsigned char)'
ReadTwoChannels.cpp.o:C:\Users\Michael Marne\Desktop\Arduino\arduino-1.0.5\libraries\ReadReceiver/PinChangeInt.h:366: first defined here

I get like 20 of these messages.

I think it's odd because PinChangeInt checks if it's defined before defining itself, so shouldn't that prevent this prom happening?

My guess is that you have both the library included in the sketch and the library as part of your library. It's one or the other, not both - make up your mind.

My guess is that you have both the library included in the sketch and the library as part of your library. It's one or the other, not both - make up your mind.

No. It's because the PCintPort library is a piece of crap. The implementation is in the header file, not in a separate source file.

PaulS:

My guess is that you have both the library included in the sketch and the library as part of your library. It's one or the other, not both - make up your mind.

No. It's because the PCintPort library is a piece of crap. The implementation is in the header file, not in a separate source file.

Oh dear, is it? That's not good. Maybe a new version needs writing by someone that has a clue...?