@@ -98,7 +98,7 @@ bool GT911::readBytes(uint16_t reg, uint8_t *data, uint16_t size) {
9898 index++;
9999 }
100100
101- return size == index;
101+ return size == index - 1 ;
102102}
103103
104104uint8_t GT911::calcChecksum (uint8_t *buf, uint8_t len) {
@@ -129,7 +129,18 @@ int8_t GT911::readTouches() {
129129}
130130
131131bool GT911::readTouchPoints () {
132- return readBytes (GT911_REG_COORD_ADDR + 1 , (uint8_t *)_points, sizeof (GTPoint) * GT911_MAX_CONTACTS);
132+ bool result = readBytes (GT911_REG_COORD_ADDR + 1 , (uint8_t *)_points, sizeof (GTPoint) * GT911_MAX_CONTACTS);
133+
134+ if (result && _rotation != Rotate::_0) {
135+ for (uint8_t i = 0 ; i < GT911_MAX_CONTACTS; i++) {
136+ if (_rotation == Rotate::_180) {
137+ _points[i].x = _info.xResolution - _points[i].x ;
138+ _points[i].y = _info.yResolution - _points[i].y ;
139+ }
140+ }
141+ }
142+
143+ return result;
133144}
134145
135146bool GT911::begin (int8_t intPin, int8_t rstPin, uint8_t addr, uint32_t clk) {
@@ -151,7 +162,11 @@ bool GT911::begin(int8_t intPin, int8_t rstPin, uint8_t addr, uint32_t clk) {
151162 _wire->setClock (clk);
152163 _wire->begin ();
153164 _wire->beginTransmission (_addr);
154- return _wire->endTransmission () == 0 ;
165+ if (_wire->endTransmission () == 0 ) {
166+ readInfo (); // Need to get resolution to use rotation
167+ return true ;
168+ }
169+ return false ;
155170}
156171
157172bool GT911::productID (uint8_t *buf, uint8_t len) {
@@ -220,3 +235,7 @@ GTPoint GT911::getPoint(uint8_t num) {
220235GTPoint *GT911::getPoints () {
221236 return _points;
222237}
238+
239+ void GT911::setRotation (Rotate rotation) {
240+ _rotation = rotation;
241+ }
0 commit comments