Several libraries allow to configure the timer to use, e.g. the IRremote library. But the implemented timer selection requires to edit something like
in some library header. Unfortunately such a change will affect all projects, using that library, what’s a bad idea
Now I came across a solution that declares a distinct class for each timer, so that the user is free to instantiate an object of the desired class. Instead of copy&paste the same class and edit it for using a specific timer, I would like to #define new class names, and #include the implementation for each timer. Like this
#define IR_USE_TIMER1 //create code for using timer 1 #define IRsend IRsend1 //sender class name #define IRrecv IRrecv1 //receiver class name #include <IRremote.cpp> //class implementation #undef IR_USE_TIMER1 #define IR_USE_TIMER2 #define IR_send IRsend2 //and so on...
Now I have some headaches, e.g. what will happen if the included source files (*.cpp) are also compiled outside above module, or the implementation is split across multiple cpp files, and header guards are #defined, and whatever further bogus may happen. What should I be aware of?
Or is there another way to achieve the goal, to create classes bound to specific timers or other resources, with less trouble and modifications to the given library code?
Or how can a library be created, that can be configured by a project to use a specific resource? A #define in the *.ino project file won’t help, when the library source files are compiled independently