At the very top of my sketch (before including the touch library) I added:
// Define the LCD type used in this sketch #define SEVEN_POINT_ZERO_INCH
However when compiling I get an error that the calibrations CAL_X, CAL_Y, CAL_S are not declared:
C:\Program Files (x86)\Arduino\libraries\UTouch\UTouch.cpp:51:20: error: 'CAL_Y' was not declared in this scope
Question, what is the scope of a #define within a sketch? And, How can I declare it so it is seen by the included libraries?
Strange way to do it anyway. The straightforward way would be with a macro variable:
// Define the LCD type used in this sketch
#define LCD_TYPE THREE_POINT_TWO_INCH
#if LCD_TYPE == THREE_POINT_TWO_INCH
// 3.2 Inch 320x240
#define CAL_X 0x00378F66UL
#define CAL_Y 0x03C34155UL
#define CAL_S 0x000EF13FUL
That method is what I wanted to use originally, however, since the touch library already defines these three constants, which define takes precedence the library or the sketch?
P.S. I deleted the errant #endif (Below the THREE_POINT_FIVE_INCH group) with no change in outcome.
The touch library expects you to list sets of constants for each display and uncomment the one of interest. Since I have many sketches that target different displays, I often get burned by forgetting to tweak the library file each time. Plus, once the library is edited, you must completely shut down the IDE and restart it for the change to take effect because the IDE caches libraries.
I will try the local re-defininition option and see if that works.
No luck.
To test this, I commented out all of these CAL defines in the library and tried placing the #defines before any other code and I get the same compile error.
It seems that the IDE compiles the libraries independently of the sketch.
aarg,
Sorry, I'm not at liberty to post the code for this project. And it is also a fairly large sketch. For now I have gone back to shuffling commented lines in the .h file. I just wanted a better way to automate this LCD variability between projects.
With all of the various methods I have tried to solve this, I am certain that anything defined within a sketch is LOCAL only to that sketch.
If you wish to pursue further, The URTouch library can be found at URTouch - Rinky-Dink Electronics it contains a header file for the three touch screen calibration constants.
// Since there are slight deviations in all touch screens you should run a
// calibration on your display module. Run the URTouch_Calibration sketch
// that came with this library and follow the on-screen instructions to
// update this file.
//
// Remember that is you have multiple display modules they will probably
// require different calibration data so you should run the calibration
// every time you switch to another module.
// You can, of course, store calibration data for all your modules here
// and comment out the ones you dont need at the moment.
The problem is that UTouch.cpp has an "#include <UTouchCD.h>" and does NOT have the #define that is in your sketch. When UTouchCD.h gets included in UTouch.cpp, none of the definitions are selected so UTouch.cpp can't use those names.
One thing that might work:
In UTouchCD.h put:
extern const unsigned long CAL_X;
extern const unsigned long CAL_Y;
extern const unsigned long CAL_S;
Then, in your sketch, put:
const unsigned long CAL_X = 0x00378F66UL;
const unsigned long CAL_Y = 0x03C34155UL;
const unsigned long CAL_S = 0x000EF13FUL;
(Of course, using your desired values.)
The linker can then fill in the constants wherever they are needed.