TouchScreenAdapter v0.5.0
TouchScreenAdapter is a library providing a unified touchscreen API.
AdafruitFT6206TouchScreen.h
1
9#ifndef AdafruitFT6206TouchScreen_h
10#define AdafruitFT6206TouchScreen_h
11
12//Only create adapter if Adafruit's FT6206 library is already included.
13#ifdef ADAFRUIT_FT6206_LIBRARY
14
15#include <Arduino.h>
16
17
18#include "TouchScreenAdapter.h"
19#include <Wire.h> // this is needed for FT6206
20
21
30
31public:
32
42 AdafruitFT6206TouchScreen(uint8_t thresh = FT62XX_DEFAULT_THRESHOLD,
43 TwoWire *theWire = &Wire, uint8_t i2c_addr = FT62XX_DEFAULT_ADDR) {
44 this->thresh = thresh;
45 this->wire = theWire;
46 this->i2c_addr = i2c_addr;
47 }
48
55 bool begin(void) {
56 return ctp.begin(thresh, wire, i2c_addr);
57 }
58
59
66 TS_Point tsPoint = ctp.getPoint();
68 uint16_t x = rotation % 2 ? tsPoint.y : tsPoint.x;
69 uint16_t y = rotation % 2 ? tsPoint.x : tsPoint.y;
70 // Would you believe it?
71 // The FT6206 report both X and Y backwards!
72 touchPoint.x = ( rotation == 2 || rotation == 3 ) ? x : displayWidth - x;
73 touchPoint.y = ( rotation == 1 || rotation == 2 ) ? y : displayHeight - y;
74 touchPoint.z = tsPoint.z;
75 return touchPoint;
76 }
77
87 TS_Point p = ctp.getPoint();
88 return TouchScreenAdapter::TouchPoint(p.x, p.y, p.z);
89 }
90
91
92
93private:
94
95 Adafruit_FT6206 ctp = Adafruit_FT6206();
96 uint8_t thresh = FT62XX_DEFAULT_THRESHOLD;
97 TwoWire *wire = &Wire;
98 uint8_t i2c_addr = FT62XX_DEFAULT_ADDR;
99
100
101
102};
103
104
105
106#endif
107#endif
Concrete implementation of TouchScreenAdapter for Adafruit's FT6206 TouchScreen class.
Definition: AdafruitFT6206TouchScreen.h:29
bool begin(void)
begin() Calls the FT6106 begin() method.
Definition: AdafruitFT6206TouchScreen.h:55
TouchScreenAdapter::TouchPoint getTouchPoint()
Get the Touch Point object.
Definition: AdafruitFT6206TouchScreen.h:65
AdafruitFT6206TouchScreen(uint8_t thresh=FT62XX_DEFAULT_THRESHOLD, TwoWire *theWire=&Wire, uint8_t i2c_addr=FT62XX_DEFAULT_ADDR)
Construct a new AdafruitFT6206TouchScreen Adapter.
Definition: AdafruitFT6206TouchScreen.h:42
TouchScreenAdapter::TouchPoint getTouchPointRaw()
Get the raw TouchPoint struct containing X/Y values directly from the underlyig library.
Definition: AdafruitFT6206TouchScreen.h:86
A lightweight abstract Abstract class for touch screen panels.
Definition: TouchScreenAdapter.h:19
uint16_t displayHeight
The (optionally rotated) height of the display in pixels.
Definition: TouchScreenAdapter.h:162
uint16_t displayWidth
The (optionally rotated) width of the display in pixels.
Definition: TouchScreenAdapter.h:161
uint8_t rotation
The current rotation of the touch panel. Default is 0 (native orientation).
Definition: TouchScreenAdapter.h:156
A consistent struct containing points X & Y plus Z as pressure.
Definition: TouchScreenAdapter.h:27
uint16_t x
Mapped 0 to screen width -1.
Definition: TouchScreenAdapter.h:47
uint16_t y
Mapped 0 to screen height -1.
Definition: TouchScreenAdapter.h:48
uint16_t z
Mapped 0-255 representing pressure (0 = not touched). is uint16_t because raw is odten > 255.
Definition: TouchScreenAdapter.h:49