-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFT6236.cpp
70 lines (57 loc) · 1.28 KB
/
FT6236.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "FT6236.h"
int readTouchRegister(int reg) {
int data = 0;
Wire.beginTransmission(TOUCH_I2C_ADD);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom(TOUCH_I2C_ADD, 1);
if (Wire.available()) {
data = Wire.read();
}
return data;
}
/*
int getTouchPointX()
{
int XL = 0;
int XH = 0;
XH = readTouchRegister(TOUCH_REG_XH);
XL = readTouchRegister(TOUCH_REG_XL);
return ((XH & 0x0F) << 8) | XL;
}
*/
int getTouchPointX() {
int XL = 0;
int XH = 0;
XH = readTouchRegister(TOUCH_REG_XH);
// Serial.println(XH >> 6,HEX);
if (XH >> 6 == 1)
return -1;
XL = readTouchRegister(TOUCH_REG_XL);
return ((XH & 0x0F) << 8) | XL;
}
int getTouchPointY() {
int YL = 0;
int YH = 0;
YH = readTouchRegister(TOUCH_REG_YH);
YL = readTouchRegister(TOUCH_REG_YL);
return ((YH & 0x0F) << 8) | YL;
}
void ft6236_pos(int pos[2]) {
int XL = 0;
int XH = 0;
int YL = 0;
int YH = 0;
XH = readTouchRegister(TOUCH_REG_XH);
if (XH >> 6 == 1) {
pos[0] = -1;
pos[1] = -1;
return;
}
XL = readTouchRegister(TOUCH_REG_XL);
YH = readTouchRegister(TOUCH_REG_YH);
YL = readTouchRegister(TOUCH_REG_YL);
// your rotation is important here, amend accordingly
pos[0] = ((YH & 0x0F) << 8) | YL;
pos[1] = ((XH & 0x0F) << 8) | XL;
}