Hello, I am not famliar with professional coding process. Yet I currently have a housekeeping Arduino and a 'barn-keeping' one. Much of the code is the same and I found out that working on two different code (.ino) files is not the way to go.
So I made a library and am inserting all the globals and many of the functions in a .h file in a the library. In this file there are # idef home and # ifdef barn e.g. for most the pin assignments. In the .ino file I put at the beginning #define home or #define barn. In this way whenever I correct something in a function I don't need to do it twice.
I am noticing that the compiler requests that the function in the .h be organized it call order which was not the case when the functions was in the .ino file and It's a bit annoying: is there a way to avoid that?
Is there a better way to properly merge these two projects?
During the sketch preprocessing, the Arduino IDE automatically generates function prototypes for all functions in .ino files that don't already have a function prototype.
No sketch preprocessing is done on files without the .ino (or .pde) file extension. They are just compiled as is. For this reason, you'll need to manually add function prototypes.
I am not clear what you are trying to achieve. Do you want the complete code for both projects to be in a single .ino file but only the code for one project to be compiled into the sketch or should the code for both projects be compiled into the sketch but only the code for one project be executed, or maybe something else
@UKHeliBob, Thanks, I thought that the 'sketch' was the .ino file(?) from your post the sketch is the loadable binary?
regarding your question, I am not sure what is the way.
Since currently my versioning scheme is to use the filename (named cyclically _00 to _99) as the version number, I would think that it's better to have two .ino files because there should be no reason to change the 'housekeeper' version when I am touching a functionality in the 'barnkeeper'. Yet all of the common functions should be in one copy and so in one file.
The main loop of both is
void (*fptr[])()={
userInterrupt, serve, synchronizer, ... etc ,
};
void loop() {
if (getArg(WDOG)) {
//reset watchdog once per loop if enabled
}
for (function=0; function < FUNCTIONS; function++) { //function is global byte used also by WDT interrupt
(*fptr[function])();
}
}
with most fptr elements identical to the two projects and few different
@pert - Thanks I understand that there is some work made by the .ino processor to alleviate the call ordering requested by the 'pure' compiler. But, if the .ino has prototypes, it can be separately compiled(?) and so too for the functions in the .h? I am confused
In Arduino terminology the sketch is the text that you see in the iDE. However, that does not mean that the whole of that text is always compiled into the executable code
Try this
#define option //comment out this line to change the compiled code
void setup()
{
Serial.begin(115200);
while (!Serial);
#ifdef option
Serial.println("option is set");
#else
Serial.println("option is not set");
#endif
}
void loop()
{
}
I organized most functions commons to two project in a large .h file. Now I have dependencies that cannot be resolved e.g function a call b that calls c that calls a so that there is no textual order that satisfies the arduino ide and it complains 'not defined'