Hi,
Here's the problem, I've got a library that I use on a variety of projects. Sometimes it's used on a Mega (with plenty of memory) and sometimes on a mini-pro (not much memory).
To cope with the different memory available, I use a #define statement to enable or disable some of the less important functions that I don't need when used on memory-scarce projects.
Code looks a bit like this.......
gps.h
#ifndef gps_h
#define gps_h
#define LOADS_OF_MEMORY
class gps
{
public:
gps(); //Constructor
void funcA(void);
void funcB(void);
#ifdef LOADS_OF_MEMORY
void funcC(void);
void funcD(void);
#endif
private:
};
#endif
So, when I know I'm going to be short of memory I comment-out the line '#define LOADS_OF_MEMORY' and the two non-essential functions funcC() and funcD() will get missed from the build.
What I'm doing works ok, but it does have a problem (not a coding problem, but a human problem). The catch is that because the #define statement is in the .h file for the library then I need to remember to edit that file before I build the project. If I then forget what I've done and come to use the same library in a later project then sometimes I get problems because half the functions have been missed due to the #define.
I thought the solution would be to remove the #define from the library header file, and put it in the top-level arduino sketch (the .ino file) that defines the overall project. That way I don't need to change the library file each time a build a different project.
The problem seems to be that scope of the #define doesn't extend beyond the .ino file into the .h file.
Is there a solution? can I extend the scope of the #define? or is there a better approach to this problem?