In the M5.begin()
initialization, an instance GT911 TP = GT911()
has been created and initialized. You can use the API in this instance to obtain touch interaction information.
Functionality:
Initializes the I2C bus.
Function Prototype:
esp_err_t begin(uint8_t pin_sda, uint8_t pin_scl, uint8_t pin_int)
Functionality:
Whether new touch data is available for reading on the screen.
Function Prototype:
bool available()
Functionality:
Refreshes screen detection.
Function Prototype:
void update()
Functionality:
Sets the screen rotation angle, usually set to 90 degrees.
Function Prototype:
void SetRotation(uint16_t rotate)
Functionality:
Reads the X coordinate of the touching finger.
Function Prototype:
uint16_t readFingerX(uint8_t num)
Functionality:
Reads the Y coordinate of the touching finger.
Function Prototype:
uint16_t readFingerY(uint8_t num)
Functionality:
Reads the ID coordinate of the touching finger.
Function Prototype:
uint16_t readFingerID(uint8_t num)
Functionality:
Reads the size of the rectangle area affected by the touching finger.
Function Prototype:
uint16_t readFingerSize(uint8_t num)
Functionality:
Reads the number of fingers touched last time.
Function Prototype:
uint8_t getFingerNum(void)
Functionality:
Checks if the finger is lifted up.
Function Prototype:
bool isFingerUp(void)
Functionality:
Clears the current touch status.
Function Prototype:
void flush(void)
Functionality:
Reads touch finger information, returns a structure instance.
Function Prototype:
tp_finger_t readFinger(uint8_t num)
Structure Instance:
typedef struct
{
uint16_t x;
uint16_t y;
uint16_t id;
uint16_t size;
} tp_finger_t;
Usage Example:
#include <M5EPD.h>
M5EPD_Canvas canvas(&M5.EPD);
int point[2][2];
void setup()
{
M5.begin();
M5.EPD.SetRotation(90);
M5.TP.SetRotation(90);
M5.EPD.Clear(true);
canvas.createCanvas(540, 960);
canvas.setTextSize(5);
canvas.drawString("Touch The Screen!", 20, 400);
canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
}
void loop()
{
if(M5.TP.available()){
if(!M5.TP.isFingerUp()){
M5.TP.update();
canvas.fillCanvas(0);
bool is_update = false;
for(int i=0; i<2; i++){
tp_finger_t FingerItem = M5.TP.readFinger(i);
if((point[i][0]!=FingerItem.x)||(point[i][1]!=FingerItem.y)){
is_update = true;
point[i][0] = FingerItem.x;
point[i][1] = FingerItem.y;
canvas.fillRect(FingerItem.x-50, FingerItem.y-50, 100, 100, 15);
Serial.printf("Finger ID:%d-->X: %d*C Y: %d Size: %d\r\n", FingerItem.id, FingerItem.x, FingerItem.y , FingerItem.size);
}
}
if(is_update)
{
canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
}
}
}
}