GUIslice  0.16.0
Embedded GUI in C
GUIslice_th_XPT2046.h
Go to the documentation of this file.
1 // touch handler (TH) for XPT2046 using the arduino built in driver <XPT2046_touch.h>
2 
3 // The touch handler performs the adaption in between the GUIslice framework and any touch driver
4 // The touch handler used is specified in the main program by calling gslc_InitTouchHandler(&touchHandler);
5 
7 
8 #ifndef _GUISLICE_TH_XPT2046_H_
9 #define _GUISLICE_TH_XPT2046_H_
10 
11 #include <Arduino.h>
12 #include <GUIslice_th.h>
13 #include <XPT2046_touch.h>
14 
16  public:
17  // parameters:
18  // spi object to be used
19  // chip select pin for spi
20  TouchHandler_XPT2046(SPIClass &spi, uint8_t spi_cs_pin) : spi(spi), touchDriver(XPT2046_touch(spi_cs_pin, spi)) {
21  //empirical calibration values, can be updated by calling setCalibration in the user program
22  setCalibration(398,3877,280,3805);
23  //swapping and flipping to adopt to default GUIslice orientation
24  setSwapFlip(true,false,true);
25  }
26 
27  //begin is called by gslc_InitTouchHandler
28  void begin(void) {
29  //init the touch driver
30  touchDriver.begin();
31  }
32 
33  //this method returns the scaled point provided by the touch driver
34  THPoint getPoint(void) {
35  //get the coordinates from the touch driver
36  TS_Point pt = touchDriver.getPoint();
37  //Serial.print("pt= ");Serial.print(pt.x);Serial.print(",");Serial.print(pt.y);Serial.print(",");Serial.println(pt.z);
38 
39  //perform scaling (this includes swapping and flipping)
40  THPoint ps = scale( THPoint(pt.x,pt.y,pt.z) );
41  //Serial.print("ps= ");Serial.print(ps.x);Serial.print(",");Serial.print(ps.y);Serial.print(",");Serial.println(ps.z);
42 
43  return ps;
44  };
45 
46  SPIClass spi;
47  XPT2046_touch touchDriver;
48 
49 };
50 
51 
52 #endif
XPT2046_touch touchDriver
Definition: GUIslice_th_XPT2046.h:47
THPoint getPoint(void)
Definition: GUIslice_th_XPT2046.h:34
Definition: GUIslice_th_XPT2046.h:15
void begin(void)
Definition: GUIslice_th_XPT2046.h:28
void setSwapFlip(bool _swapXY, bool _flipX, bool _flipY)
Definition: GUIslice_th.cpp:50
TouchHandler_XPT2046(SPIClass &spi, uint8_t spi_cs_pin)
Definition: GUIslice_th_XPT2046.h:20
void setCalibration(uint16_t ts_xMin, uint16_t ts_xMax, uint16_t ts_yMin, uint16_t ts_yMax)
Definition: GUIslice_th.cpp:42
SPIClass spi
Definition: GUIslice_th_XPT2046.h:44
Definition: GUIslice_th.h:16
THPoint scale(THPoint pIn)
Definition: GUIslice_th.cpp:57
Definition: GUIslice_th.h:31