Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
Adafruit_FT6206.cpp
Go to the documentation of this file.
1 /***************************************************
2  This is a library for the Adafruit Capacitive Touch Screens
3 
4  ----> http://www.adafruit.com/products/1947
5 
6  Check out the links above for our tutorials and wiring diagrams
7  This chipset uses I2C to communicate
8 
9  Adafruit invests time and resources providing this open source code,
10  please support Adafruit and open-source hardware by purchasing
11  products from Adafruit!
12 
13  Written by Limor Fried/Ladyada for Adafruit Industries.
14  MIT license, all text above must be included in any redistribution
15  ****************************************************/
16 
17 
18 #if ARDUINO >= 100
19 #include "Arduino.h"
20 #else
21 #include "WProgram.h"
22 #endif
23 
24 #include <Wire.h>
25 
26 #include <Adafruit_FT6206.h>
27 
28 #if defined(__SAM3X8E__)
29 #define Wire Wire1
30 #endif
31 
32 /**************************************************************************/
33 /*!
34  @brief Instantiates a new FT6206 class
35 */
36 /**************************************************************************/
37 // I2C, no address adjustments or pins
39 {
40 }
41 
42 
43 /**************************************************************************/
44 /*!
45  @brief Setups the HW
46 */
47 /**************************************************************************/
48 boolean Adafruit_FT6206::begin(uint8_t threshhold)
49 {
50  Wire.begin();
51 
52  // change threshhold to be higher/lower
54 
55  if ((readRegister8(FT6206_REG_VENDID) != 17) || (readRegister8(FT6206_REG_CHIPID) != 6)) return false;
56  /*
57  Serial.print("Vend ID: "); Serial.println(readRegister8(FT6206_REG_VENDID));
58  Serial.print("Chip ID: "); Serial.println(readRegister8(FT6206_REG_CHIPID));
59  Serial.print("Firm V: "); Serial.println(readRegister8(FT6206_REG_FIRMVERS));
60  Serial.print("Point Rate Hz: "); Serial.println(readRegister8(FT6206_REG_POINTRATE));
61  Serial.print("Thresh: "); Serial.println(readRegister8(FT6206_REG_THRESHHOLD));
62  */
63  // dump all registers
64  /*
65  for (int16_t i=0; i<0x20; i++) {
66  Serial.print("I2C $"); Serial.print(i, HEX);
67  Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX);
68  }
69  */
70  return true;
71 }
72 
73 // DONT DO THIS - REALLY - IT DOESNT WORK
75 {
77  delay(100);
78 //Serial.println("Calibrating...");
80  delay(300);
81  for (uint8_t i = 0; i < 100; i++)
82  {
83  uint8_t temp;
85  Serial.println(temp, HEX);
86  //return to normal mode, calibration finish
87  if (0x0 == ((temp & 0x70) >> 4))
88  break;
89  }
90  delay(200);
91 //Serial.println("Calibrated");
92  delay(300);
94  delay(100);
96  delay(300);
98  delay(300);
99 }
100 
101 
103 {
104 
106  if ((n == 1) || (n == 2)) return true;
107  return false;
108 }
109 
110 /*****************************/
111 
112 void Adafruit_FT6206::readData(uint16_t *x, uint16_t *y)
113 {
114 
115  uint8_t i2cdat[16];
116  Wire.beginTransmission(FT6206_ADDR);
117  Wire.write((byte)0);
118  Wire.endTransmission();
119  Wire.beginTransmission(FT6206_ADDR);
120  Wire.requestFrom((byte)FT6206_ADDR, (byte)32);
121  for (uint8_t i=0; i<16; i++)
122  i2cdat[i] = Wire.read();
123  Wire.endTransmission();
124 
125  /*
126  for (int16_t i=0; i<0x20; i++) {
127  Serial.print("I2C $"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(i2cdat[i], HEX);
128  }
129  */
130 
131  touches = i2cdat[0x02];
132 
133  //Serial.println(touches);
134  if (touches > 2)
135  {
136  touches = 0;
137  *x = *y = 0;
138  }
139  if (touches == 0)
140  {
141  *x = *y = 0;
142  return;
143  }
144 
145  /*
146  if (touches == 2) Serial.print('2');
147  for (uint8_t i=0; i<16; i++) {
148  // Serial.print("0x"); Serial.print(i2cdat[i], HEX); Serial.print(" ");
149  }
150  */
151 
152  /*
153  Serial.println();
154  if (i2cdat[0x01] != 0x00) {
155  Serial.print("Gesture #");
156  Serial.println(i2cdat[0x01]);
157  }
158  */
159 
160  //Serial.print("# Touches: "); Serial.print(touches);
161  for (uint8_t i=0; i<2; i++)
162  {
163  touchX[i] = i2cdat[0x03 + i*6] & 0x0F;
164  touchX[i] <<= 8;
165  touchX[i] |= i2cdat[0x04 + i*6];
166  touchY[i] = i2cdat[0x05 + i*6] & 0x0F;
167  touchY[i] <<= 8;
168  touchY[i] |= i2cdat[0x06 + i*6];
169  touchID[i] = i2cdat[0x05 + i*6] >> 4;
170  }
171  /*
172  Serial.println();
173  for (uint8_t i=0; i<touches; i++) {
174  Serial.print("ID #"); Serial.print(touchID[i]); Serial.print("\t("); Serial.print(touchX[i]);
175  Serial.print(", "); Serial.print(touchY[i]);
176  Serial.print (") ");
177  }
178  Serial.println();
179  */
180  *x = touchX[0];
181  *y = touchY[0];
182 }
183 
185 {
186  uint16_t x, y;
187  uint8_t z;
188  readData(&x, &y);
189  return TS_Point(x, y, 1);
190 }
191 
192 
193 uint8_t Adafruit_FT6206::readRegister8(uint8_t reg)
194 {
195  uint8_t x ;
196  // use i2c
197  Wire.beginTransmission(FT6206_ADDR);
198  Wire.write((byte)reg);
199  Wire.endTransmission();
200  Wire.beginTransmission(FT6206_ADDR);
201  Wire.requestFrom((byte)FT6206_ADDR, (byte)1);
202  x = Wire.read();
203  Wire.endTransmission();
204 
205  // Serial.print("$"); Serial.print(reg, HEX);
206  // Serial.print(": 0x"); Serial.println(x, HEX);
207 
208  return x;
209 }
210 
211 void Adafruit_FT6206::writeRegister8(uint8_t reg, uint8_t val)
212 {
213  // use i2c
214  Wire.beginTransmission(FT6206_ADDR);
215  Wire.write((byte)reg);
216  Wire.write((byte)val);
217  Wire.endTransmission();
218 }
219 
220 /****************/
221 
223 {
224  x = y = 0;
225 }
226 
227 TS_Point::TS_Point(int16_t x0, int16_t y0, int16_t z0)
228 {
229  x = x0;
230  y = y0;
231  z = z0;
232 }
233 
235 {
236  return ((p1.x == x) && (p1.y == y) && (p1.z == z));
237 }
238 
240 {
241  return ((p1.x != x) || (p1.y != y) || (p1.z != z));
242 }
#define FT6206_REG_THRESHHOLD
int16_t z
int16_t x
#define FT6206_ADDR
void readData(uint16_t *x, uint16_t *y)
void autoCalibrate(void)
#define FT6206_REG_CHIPID
#define FT6206_REG_NUMTOUCHES
#define FT6206_REG_WORKMODE
int16_t y
bool operator==(TS_Point)
boolean begin(uint8_t thresh=FT6206_DEFAULT_THRESSHOLD)
Setups the HW.
bool operator!=(TS_Point)
void writeRegister8(uint8_t reg, uint8_t val)
TS_Point getPoint(void)
Adafruit_FT6206(void)
Instantiates a new FT6206 class.
#define FT6206_REG_FACTORYMODE
#define FT6206_REG_VENDID
static int i
Definition: DC2430A.ino:184
#define FT6206_REG_MODE
uint8_t readRegister8(uint8_t reg)
boolean touched(void)
#define FT6206_REG_CALIBRATE