I am working on "libraryising" some code I've written. The idea is to create a library which can then be used wherever required, in a wide variety of projects. I plan to share the library at some point too.
However I need a way to get user-supplied (meaning from the ino file, the idea being that a user should have no need to edit the hfile or cpp file when in use) #defines. I need #defined values to pass from the top of the ino file, in to the library code.
This would work with a h file library, but I don't want that, I want to have the library in its own cpp file as a separate compilation unti from the main ino code.
I must use #defines, NOT, passing of variables as arguments, because for the functions I've written in the library to run at their proper speed certain variables (pin numbers used in port manipulation operations for example) must be constants. I have verified this on an oscilloscope, the code runs something like 5 times faster when #define or const uint8_t is used for certain variable names, compared to the slow case where a variable is used and the code has to perform certain if loops and switch cases on variable value at run time.
These #defines are constant for any given arduino system built, but the values may vary for different applications, so while they don't need to be actual variables (they will never vary during operation) (and must not be for speed reasons), they also can't be #defines contained in the library's h file or cpp file, as when the library is used for different projects different values will be needed.
But when different compilation units are used, a #define in the ino file doesn't seem to be accessible by the cpp file, I get compiler errors.
I would also like to have the library generate a compiler error with a custom message if these #defines are undefined or if they meet certain properties. For example, refusing to compile and giving a message "ERROR, pins PinAlpha, PinBeta, PinGamma and PinDelta must all be defined, and PinAlpha...PinDelta MUST all be different values" if one of those names isn't defined in the ino file, or if PinBeta and PinGamma were equal values. With other error messages available like "ERROR, defined value Epsilon must be between 2 and 25" if the ino file contained something such as #define Epsilon 30 .
I would be ok with a requirement that in the ino file the #defines must be writen above where the #include command sits.
What is the best way to proceed?
Thank you