Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low impact support for multitouch, example app #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions Adafruit_FT6206.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***************************************************
/***************************************************
This is a library for the Adafruit Capacitive Touch Screens

----> http://www.adafruit.com/products/1947

Check out the links above for our tutorials and wiring diagrams
This chipset uses I2C to communicate

Expand Down Expand Up @@ -30,7 +30,7 @@
#endif

/**************************************************************************/
/*!
/*!
@brief Instantiates a new FT6206 class
*/
/**************************************************************************/
Expand All @@ -40,7 +40,7 @@ Adafruit_FT6206::Adafruit_FT6206() {


/**************************************************************************/
/*!
/*!
@brief Setups the HW
*/
/**************************************************************************/
Expand All @@ -49,9 +49,9 @@ boolean Adafruit_FT6206::begin(uint8_t threshhold) {

// change threshhold to be higher/lower
writeRegister8(FT6206_REG_THRESHHOLD, threshhold);

if ((readRegister8(FT6206_REG_VENDID) != 17) || (readRegister8(FT6206_REG_CHIPID) != 6)) return false;
/*
/*
Serial.print("Vend ID: "); Serial.println(readRegister8(FT6206_REG_VENDID));
Serial.print("Chip ID: "); Serial.println(readRegister8(FT6206_REG_CHIPID));
Serial.print("Firm V: "); Serial.println(readRegister8(FT6206_REG_FIRMVERS));
Expand Down Expand Up @@ -79,7 +79,7 @@ void Adafruit_FT6206::autoCalibrate(void) {
uint8_t temp;
temp = readRegister8(FT6206_REG_MODE);
Serial.println(temp, HEX);
//return to normal mode, calibration finish
//return to normal mode, calibration finish
if (0x0 == ((temp & 0x70) >> 4))
break;
}
Expand All @@ -96,7 +96,7 @@ void Adafruit_FT6206::autoCalibrate(void) {


boolean Adafruit_FT6206::touched(void) {

uint8_t n = readRegister8(FT6206_REG_NUMTOUCHES);
if ((n == 1) || (n == 2)) return true;
return false;
Expand All @@ -108,13 +108,13 @@ void Adafruit_FT6206::readData(uint16_t *x, uint16_t *y) {

uint8_t i2cdat[16];
Wire.beginTransmission(FT6206_ADDR);
Wire.write((byte)0);
Wire.write((byte)0);
Wire.endTransmission();
Wire.beginTransmission(FT6206_ADDR);
Wire.requestFrom((byte)FT6206_ADDR, (byte)32);
for (uint8_t i=0; i<16; i++)
i2cdat[i] = Wire.read();
Wire.endTransmission();
Wire.endTransmission();

/*
for (int16_t i=0; i<0x20; i++) {
Expand Down Expand Up @@ -144,7 +144,7 @@ void Adafruit_FT6206::readData(uint16_t *x, uint16_t *y) {
/*
Serial.println();
if (i2cdat[0x01] != 0x00) {
Serial.print("Gesture #");
Serial.print("Gesture #");
Serial.println(i2cdat[0x01]);
}
*/
Expand All @@ -153,7 +153,7 @@ void Adafruit_FT6206::readData(uint16_t *x, uint16_t *y) {
for (uint8_t i=0; i<2; i++) {
touchX[i] = i2cdat[0x03 + i*6] & 0x0F;
touchX[i] <<= 8;
touchX[i] |= i2cdat[0x04 + i*6];
touchX[i] |= i2cdat[0x04 + i*6];
touchY[i] = i2cdat[0x05 + i*6] & 0x0F;
touchY[i] <<= 8;
touchY[i] |= i2cdat[0x06 + i*6];
Expand All @@ -171,6 +171,35 @@ void Adafruit_FT6206::readData(uint16_t *x, uint16_t *y) {
*x = touchX[0]; *y = touchY[0];
}

// minimal impact method to read multitouches
uint8_t Adafruit_FT6206::readMultiData(uint8_t *id0, uint16_t *x0, uint16_t *y0, uint8_t *id1, uint16_t *x1, uint16_t *y1 ) {
// save ourselves some trouble if there are no touches
uint8_t n = readRegister8(FT6206_REG_NUMTOUCHES);
if ( n == 0 || n > 2 ) {
*id0 = 0x0F;
*id1 = 0x0F;
return 0;
}

// call the main data reader... it does the job
readData( x0, y0 );
// readData returns 0 - 0 if there was no touch when it got around to reading it
// -1's might have been another good choice
if ( x0 == 0 && y0 == 0 ) {
*id0 = 0x0F;
*id1 = 0x0F;
return 0;
}

*id0 = touchID[ 0 ];
*id1 = touchID[ 1 ];
*x1 = touchX[ 1 ];
*y1 = touchY[ 1 ];

// return the number of touches
return n;
}

TS_Point Adafruit_FT6206::getPoint(void) {
uint16_t x, y;
uint8_t z;
Expand All @@ -190,9 +219,9 @@ uint8_t Adafruit_FT6206::readRegister8(uint8_t reg) {
x = Wire.read();
Wire.endTransmission();

// Serial.print("$"); Serial.print(reg, HEX);
// Serial.print("$"); Serial.print(reg, HEX);
// Serial.print(": 0x"); Serial.println(x, HEX);

return x;
}

Expand Down
12 changes: 6 additions & 6 deletions Adafruit_FT6206.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***************************************************
/***************************************************
This is a library for the Adafruit Capacitive Touch Screens

----> http://www.adafruit.com/products/1947

Check out the links above for our tutorials and wiring diagrams
This chipset uses I2C to communicate

Expand Down Expand Up @@ -48,7 +48,7 @@ class TS_Point {
public:
TS_Point(void);
TS_Point(int16_t x, int16_t y, int16_t z);

bool operator==(TS_Point);
bool operator!=(TS_Point);

Expand All @@ -59,13 +59,14 @@ class Adafruit_FT6206 {
public:

Adafruit_FT6206(void);
boolean begin(uint8_t thresh = FT6206_DEFAULT_THRESSHOLD);
boolean begin(uint8_t thresh = FT6206_DEFAULT_THRESSHOLD);

void writeRegister8(uint8_t reg, uint8_t val);
uint8_t readRegister8(uint8_t reg);

void readData(uint16_t *x, uint16_t *y);
void autoCalibrate(void);
uint8_t readMultiData(uint8_t *id0, uint16_t *x0, uint16_t *y0, uint8_t *id1, uint16_t *x1, uint16_t *y1 );
void autoCalibrate(void);

boolean touched(void);
TS_Point getPoint(void);
Expand All @@ -75,4 +76,3 @@ class Adafruit_FT6206 {
uint16_t touchX[2], touchY[2], touchID[2];

};

Loading