![]() |
TouchScreenAdapter v0.5.0
TouchScreenAdapter is a library providing a unified touchscreen API.
|
TouchScreenAdapter is a library providing a unified touchscreen API. Included are implementations for typical touchscreen types: 4-wire resistive and capacitive.
The library provides a consistent TouchPoint structure, containing X & Y translated to display coordinates (even for resistive screens) and Z for touch/pressure where 0 = 'not touched' and >0 = 'touched'. Where available, presure will be reported in the range 1-255.
Its primary use is for the EventTouchScreen library (that will become part of InputEvents) but is also very effective as a source for an LVGL input device: lv_indev_t.
The abstract TouchScreenAdapter class specifies the following methods:
void begin()
- required for Arduino compatibility.TouchScreenAdapter::TouchPoint getTouchPoint()
- returns a TouchScreenAdapter::TouchPoint with X & Y display coordinates with Z where 0 is not touched and >= 1 is touched.TouchScreenAdapter::TouchPoint getTouchPointRaw()
- returns a TouchScreenAdapter::TouchPoint with raw Y, Y and Z coordinates.void setDisplayWidth(uint16_t width)
Set the display width. Required for resistive touch or if reversing X and/or Y is necessary.void setDisplayHeight(uint16_t height)
Set the display height. Required for resistive touch or if reversing X and/or Y is necessary.void setRotation(uint8_t rotation)
Rotate the touch panel as required.Concrete implementations provide a constructor suitable for the underlying library and any additional methods required to configure the touch panel.
Adapter classes are fairly trivial to create but must be 'header only' to allow Arduino IDE to compile without error when the underlying libraries are not installed. Pull requests are most welcome.
The concrete classes currently provided are:
AdafruitResistiveTouchScreen
- resistive, using Adafruit's TouchScreen library.AdafruitFT6206TouchScreen
- I2C, using Adafruit's FT6206 library.The TouchScreenAdapter Library is available via the Arduino IDE or PlatformIO Library Managers by searching for 'TouchScreenAdapter'.
Further information, source code, examples and guides are available in the github repository.
Although this library lists no dependencies, it will be dependent on whichever underlying touch screen library that the chosen adapter uses.
Feedback, pull requests and bug reports are welcome or chat on the InputEvents Discord channel if you have any questions.