Touch.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Coded by Bodmer 10/2/18, see license in root directory.
  2. // This is part of the TFT_eSPI class and is associated with the Touch Screen handlers
  3. public:
  4. // Get raw x,y ADC values from touch controller
  5. uint8_t getTouchRaw(uint16_t *x, uint16_t *y);
  6. // Get raw z (i.e. pressure) ADC value from touch controller
  7. uint16_t getTouchRawZ(void);
  8. // Convert raw x,y values to calibrated and correctly rotated screen coordinates
  9. void convertRawXY(uint16_t *x, uint16_t *y);
  10. // Get the screen touch coordinates, returns true if screen has been touched
  11. // if the touch coordinates are off screen then x and y are not updated
  12. // The returned value can be treated as a bool type, false or 0 means touch not detected
  13. // In future the function may return an 8 "quality" (jitter) value.
  14. uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
  15. // Run screen calibration and test, report calibration values to the serial port
  16. void calibrateTouch(uint16_t *data, uint32_t color_fg, uint32_t color_bg, uint8_t size);
  17. // Set the screen calibration values
  18. void setTouch(uint16_t *data);
  19. // Private function to validate a touch, allow settle time and reduce spurious coordinates
  20. uint8_t validTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
  21. private:
  22. // Legacy support only - deprecated TODO: delete
  23. void spi_begin_touch();
  24. void spi_end_touch();
  25. // Handlers for the touch controller bus settings
  26. inline void begin_touch_read_write() __attribute__((always_inline));
  27. inline void end_touch_read_write() __attribute__((always_inline));
  28. // Initialise with example calibration values so processor does not crash if setTouch() not called in setup()
  29. uint16_t touchCalibration_x0 = 300, touchCalibration_x1 = 3600, touchCalibration_y0 = 300, touchCalibration_y1 = 3600;
  30. uint8_t touchCalibration_rotate = 1, touchCalibration_invert_x = 2, touchCalibration_invert_y = 0;
  31. uint32_t _pressTime; // Press and hold time-out
  32. uint16_t _pressX, _pressY; // For future use (last sampled calibrated coordinates)