rename lib's

Hi

on a project where i read my heat meter (kamstrup multical 601) via ir interface i need to invert tx in the SoftwareSerial lib

i got the cpp file and .h file in a new folder called SoftwareSerial_inv

but the .h file is the same as the normal SoftwareSerial... its only the cpp that has changed.

now i put them in a new folder so they did not mix up and i have also renamed the file name to end on _inv and my goal was to say: #include <SoftwareSerial_inv.h> in the sketch

what do i need to change inside the SoftwareSerial_inv.h file so it matches up with the cpp file?

is it as simple as searching for SoftwareSerial and add _inv to it?

but then what about these 2 lines?

#ifndef SoftwareSerial_h
#define SoftwareSerial_h

SoftwareSerial has an optional third argument to the constructor that does inversion. Why did you need to clone the class?

is it as simple as searching for SoftwareSerial and add _inv to it?

Yes.

but then what about these 2 lines?

They contain SoftwareSerial, don't they?

yes but they end on _h... i'm just in doubt with double underscore

have attached the files... does it look ok except the 2 lines?

SoftwareSerial_inv.cpp (13.2 KB)

SoftwareSerial_inv.h (3.5 KB)

boelle:
is it as simple as searching for SoftwareSerial and add _inv to it?

but then what about these 2 lines?

#ifndef SoftwareSerial_h
#define SoftwareSerial_h

I don't know the answer but less than 5 minutes of experimenting should allow you to figure it out.

...R

yes it will either work or not... if it does not work i have the problem that i dont know how to get it to work...

but allready now i get errors:

sketch_jan02a:28: error: 'SoftwareSerial_inv' does not name a type
sketch_jan02a.ino: In function 'void setup()':
sketch_jan02a:41: error: 'kamSer' was not declared in this scope
sketch_jan02a.ino: In function 'void kamSend(const byte*, int)':
sketch_jan02a:143: error: 'kamSer' was not declared in this scope
sketch_jan02a.ino: In function 'short unsigned int kamReceive(byte*)':
sketch_jan02a:155: error: 'kamSer' was not declared in this scope

sketch attached.... i have an idea that kamSer pin definitions has to move down to the setyp void?

sketch_jan02a.ino (5.97 KB)

yes but they end on _h... i'm just in doubt with double underscore

The two lines are the start of an inclusion block. Nothing magic about them.

might not be... but should i then add _inv before or after _h ?

might not be... but should i then add _inv before or after _h ?

Where does the SoftwareSerial part appear?

please....

i'm not good at programming so why answer a Q with another Q...?

logic i would add _inv before _h

but what is the _h there for? its that what worries me

but what is the _h there for? its that what worries me

The _h could be *HeyThisIsABunchOfRubbish instead.

The name following the #ifdef statement is the name of the header file with the . changed to an underscore.

so me adding _inv would cause trouble... that is what my logic says

so if i should stay clear -inv would be a better choice right?

i simply added inv and it works.... the _ was simply to optical make it faster to see which one i use

The name you use in that ifdef block could be anything. It doesn't have any special purpose to the compiler. All it is there for is to make sure the .h file doesn't get included twice. So the first time it gets included the ifndef is true and you define something. It could be anything. But the key is that if that library is included again in a sketch, by being included in a library or in another tab, then the compiler will see that thing has already been defined making the ifndef false so the compiler skips to the #endif and nothing gets included.

You could just as well use
#ifndef BHYUGHTF
#define BHYUGHTF

// your calss

#endif

But that might get confusing no? So we typically make it look something like the name of the file so we can know what it is referring to. But the fact that it resembles the file name or the class name is entirely for our human benefit. The compiler could care less what it spells or how many underscores you put in it.