28
28
//
29
29
30
30
// For Paul Stoffregen's touch screen XPT2046 (or ThingPulse fork)
31
- #include < XPT2046_Touchscreen.h>
32
- #define TOUCH_CLASS XPT2046_Touchscreen
33
- #define CS_PIN 5
34
- XPT2046_Touchscreen touchDevice (CS_PIN, 0xFF );
31
+ // #include <XPT2046_Touchscreen.h>
32
+ // #define TOUCH_CLASS XPT2046_Touchscreen
33
+ // #define CS_PIN 5
34
+ // XPT2046_Touchscreen touchDevice(CS_PIN, 0xFF);
35
35
// end XPT2046
36
36
37
37
// For Adafruit's FT6206 touch screen library
38
- // #include <Adafruit_FT6206>
39
- // #define TOUCH_CLASS Adafruit_FT6206
40
- // Adafruit_FT6206 touchDevice;
38
+ #include < Adafruit_FT6206.h >
39
+ #define TOUCH_CLASS Adafruit_FT6206
40
+ Adafruit_FT6206 touchDevice;
41
41
// end FT6206
42
42
43
43
@@ -60,13 +60,13 @@ public:
60
60
// * if there is a touch, the reading should be obtained, and converted into floating points value between 0 and 1
61
61
// * these x and y values should be run through the calibrator and used to set the pointers to x and y passed in
62
62
// * lastly you should return TOUCHED to indicate a touch as taken place.
63
- TouchState internalProcessTouch (float *ptrX, float *ptrY, TouchRotation rotation , const CalibrationHandler& calib) {
63
+ TouchState internalProcessTouch (float *ptrX, float *ptrY, const TouchOrientationSettings& orientationSettings , const CalibrationHandler& calib) {
64
64
if (theTouchDevice.touched () == 0 ) return NOT_TOUCHED;
65
65
66
66
TS_Point pt = theTouchDevice.getPoint ();
67
67
68
- *ptrX = calib.calibrateX (float (pt.x ) / KNOWN_DEVICE_TOUCH_RANGE, false );
69
- *ptrY = calib.calibrateY (float (pt.y ) / KNOWN_DEVICE_TOUCH_RANGE, false );
68
+ *ptrX = calib.calibrateX (float (pt.x ) / KNOWN_DEVICE_TOUCH_RANGE, orientationSettings. isXInverted () );
69
+ *ptrY = calib.calibrateY (float (pt.y ) / KNOWN_DEVICE_TOUCH_RANGE, orientationSettings. isYInverted () );
70
70
return TOUCHED;
71
71
}
72
72
} interrogator(touchDevice);
@@ -76,12 +76,21 @@ public:
76
76
* interface. In the simplest case you can use the ValueStoringResistiveTouchScreen, but you can also extend from
77
77
* ResistiveTouchScreen, see the reference documentation for more on this.
78
78
*
79
- * Notice that we pass in the above created "glue" interrogator and the desired rotation.
79
+ * Notice that we pass in the above created "glue" interrogator and the desired orientation, the three parameters to
80
+ * the orientation:
81
+ * 1. XY are inverted if true, otherwise false
82
+ * 2. the raw X value is inverted
83
+ * 3, the raw Y value is inverted
80
84
*/
81
- ValueStoringResistiveTouchScreen touchScreen (interrogator, TouchInterrogator::PORTRAIT );
85
+ ValueStoringResistiveTouchScreen touchScreen (interrogator, TouchOrientationSettings( false , true , true ) );
82
86
83
87
void setup () {
84
88
Serial.begin (115200 );
89
+
90
+ // depending on your board, adjust as needed.
91
+ // Wire.begin();
92
+ Wire.begin (5 , 4 );
93
+
85
94
// first start the underlying touch library
86
95
touchDevice.begin ();
87
96
0 commit comments