-
Notifications
You must be signed in to change notification settings - Fork 1
/
FT6236.cpp
61 lines (56 loc) · 1.18 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
#include "FT6236.h"
int readTouchReg(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 = readTouchReg(TOUCH_REG_XH);
XL = readTouchReg(TOUCH_REG_XL);
return ((XH & 0x0F) << 8) | XL;
}
*/
int getTouchPointX() {
int XL = 0;
int XH = 0;
XH = readTouchReg(TOUCH_REG_XH);
//Serial.println(XH >> 6,HEX);
if (XH >> 6 == 1)
return -1;
XL = readTouchReg(TOUCH_REG_XL);
return ((XH & 0x0F) << 8) | XL;
}
int getTouchPointY() {
int YL = 0;
int YH = 0;
YH = readTouchReg(TOUCH_REG_YH);
YL = readTouchReg(TOUCH_REG_YL);
return ((YH & 0x0F) << 8) | YL;
}
int ft6236_pos(int pos[2]) {
int XL = 0;
int XH = 0;
int YL = 0;
int YH = 0;
XH = readTouchReg(TOUCH_REG_XH);
if (XH >> 6 == 1) {
pos[0] = -1;
pos[1] = -1;
return 0;
}
XL = readTouchReg(TOUCH_REG_XL);
YH = readTouchReg(TOUCH_REG_YH);
YL = readTouchReg(TOUCH_REG_YL);
pos[0] = ((XH & 0x0F) << 8) | XL;
pos[1] = ((YH & 0x0F) << 8) | YL;
return 1;
}