Go Down

Topic: Library configuration (Read 1 time) previous topic - next topic



I'm currently writing an Arduino Library to support xPL protocol (more details there : http://www.mgth.fr).

Cause it is very memory angry, I try to get it configurable.
for now I just have a config.h inside the library folder, but I would like to have configuration sketch dependent. Does anyone have an idea on how to achieve that ?

thank you.

Mgth : ArduixPL http://www.mgth.fr


define a struct that a user can fill and pass to the library. or use #ifdef to check if custom values have been provided via #define
https://forum.arduino.cc/index.php?action=dlattach;topic=327736.0;attach=128670 New EEPROM library released


eh, it seams to work with #define I don't know why when I first tried, I got the feeling that defines declared into main sketch were not taken into accounts inside libraries cpp, but your right it is. I'm gonna do that.
does any body know if this is a normal c++ behaviour or a special Arduino magic ?

thanks for your reply.
Mgth : ArduixPL http://www.mgth.fr


Jun 29, 2012, 08:16 pm Last Edit: Jun 29, 2012, 08:21 pm by pYro_65 Reason: 1
If you define things before including a file, the included file will have the defines in scope. They are valid with in the defining translation unit ( .cpp/.ino file being compiled + all code inside of #include files )

Is normal behaviour ( although IDE may have ordered things in such a way that a non working design will work ), consider a #include as literally pasting the included file's contents into the file being compiled.
https://forum.arduino.cc/index.php?action=dlattach;topic=327736.0;attach=128670 New EEPROM library released


After a second check it seams that I does not do what I want.

if I #define in the ino file, things are not defined while compiling cpp in libraries, it seams logical to me, but It does not help...

I would need some kind of global define, or maybe I'm wrong on the way of doing it.

Mgth : ArduixPL http://www.mgth.fr


Ahh yes, the cpp file for the library will be compiled before any file includes the library header. You would need a global header like global.h that the library and your code ( sketch includes first ) so the #defines are taken into account before compiling the library .cpp.

I think passing a struct of values is adequate ( not really much different that having a constructor with a lot of parameters ). And if there are a lot of options/settings, you could store the struct in program memory and pass the PGM pointer to the library for it to handle data access, but easier is having a predefined struct as a data member then if a user provides one in a constructor, copy the values into the struct member to overwrite the default values.
https://forum.arduino.cc/index.php?action=dlattach;topic=327736.0;attach=128670 New EEPROM library released

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131