jak robiłem testy to "zawijanie" i zniekształcanie ekranu objawiało się jak były za duże kondensatory na liniach "touch" obecnie dałem 68pF ( miały byc 100pF)
bo z 10 nF to była pomyłka...- nawet nie ma sensu pokazywac obrazków... podobnie robiłem próby z bardzo szybkim czytaniem po SPI - też robiły sie "banany" na wykresie - zamiast prostokąta...
warto tu zajrzeć ;-) na pierwszym linku źródła w C do pobrania do noty aplikacyjnej
Myśle że przy dobrze dobranych C i kondensatorach - program z filmu "paint na LCD " rozwiewa niepewnośc czy ekran dziala dobrze... czy źle.
... i jeszcze ten link - z kodami do metody 3 punktowej
Kod:
/*
Calibrate call touch_calibrate(). Routine set calibrate matrix and save to eeprom.
Calibrate using 3 point calibrate.
First point is 24,32.
Second point is 215,160.
Third point is 120,287.
Touch screen api will read matrix at init class. No need to call calibrate again.
*/
lcdFont LCD;
touchscreen TS;
void showPoint(void)
{
char sTemp[8];
TS.readPoint();
if (TS.screenPoint.x > 0)
{
LCD.Color = WHITE;
LCD.FgColor = GREEN; // text foreground color
LCD.BkColor = RED; // text background color
ltoa(TS.screenPoint.x, sTemp, 10);
LCD.TextBox( 0, 280, 59, 310, sTemp, ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
ltoa(TS.screenPoint.y, sTemp, 10);
LCD.TextBox( 60, 280, 119, 310, sTemp, ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
ltoa(TS.displayPoint.x, sTemp, 10);
LCD.TextBox(120, 280, 179, 310, sTemp, ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
ltoa(TS.displayPoint.y, sTemp, 10);
LCD.TextBox(180, 280, 239, 310, sTemp, ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
}
}
int setCalibrationMatrix( POINT * displayPtr,
POINT * screenPtr,
MATRIX * matrixPtr)
{
int retValue = 1 ;
matrixPtr->Divider = ((screenPtr[0].x - screenPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) -
((screenPtr[1].x - screenPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;
if( matrixPtr->Divider == 0 )
{
retValue = 0 ;
}
else
{
matrixPtr->An = ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) -
((displayPtr[1].x - displayPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;
matrixPtr->Bn = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].x - displayPtr[2].x)) -
((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].x - screenPtr[2].x)) ;
matrixPtr->Cn = (screenPtr[2].x * displayPtr[1].x - screenPtr[1].x * displayPtr[2].x) * screenPtr[0].y +
(screenPtr[0].x * displayPtr[2].x - screenPtr[2].x * displayPtr[0].x) * screenPtr[1].y +
(screenPtr[1].x * displayPtr[0].x - screenPtr[0].x * displayPtr[1].x) * screenPtr[2].y ;
matrixPtr->Dn = ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].y - screenPtr[2].y)) -
((displayPtr[1].y - displayPtr[2].y) * (screenPtr[0].y - screenPtr[2].y)) ;
matrixPtr->En = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].y - displayPtr[2].y)) -
((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].x - screenPtr[2].x)) ;
matrixPtr->Fn = (screenPtr[2].x * displayPtr[1].y - screenPtr[1].x * displayPtr[2].y) * screenPtr[0].y +
(screenPtr[0].x * displayPtr[2].y - screenPtr[2].x * displayPtr[0].y) * screenPtr[1].y +
(screenPtr[1].x * displayPtr[0].y - screenPtr[0].x * displayPtr[1].y) * screenPtr[2].y ;
}
return( retValue ) ;
}
void touch_calibrate(void)
{
unsigned char press;
POINT screenSample[3]; //array of input points
POINT displaySample[3] = {{24,32},{215,160},{120,287}}; //array of expected correct answers TS.getMatrix();
POINT capturePoint; //array of valid input points
LCD.Color = WHITE; // graphic color
LCD.FgColor = WHITE; // text foreground color
LCD.BkColor = BLACK; // text background color
LCD.TextBox(0, 0, LCD.getMaxX(), 30, "Calibrate", ALINE_CENTER);
for (uint8_t i=0; i<3; i++)
{
// draw touch point
LCD.Color = RED;
LCD.Circle(displaySample[i].x, displaySample[i].y , 4);
press = 0;
TS.screenPoint.x = 0;
TS.screenPoint.y = 0;
while(!press)
{
capturePoint.x = TS.screenPoint.x;
capturePoint.y = TS.screenPoint.y;
TS.sampling(&TS.screenPoint, 50);
if (TS.screenPoint.x > 0)
{
// Is stable point?
if ((capturePoint.x == TS.screenPoint.x) && (capturePoint.y == TS.screenPoint.y))
press = 1;
}
}
// got a point
screenSample[i].x = TS.screenPoint.x;
screenSample[i].y = TS.screenPoint.y;
// mark complete point
LCD.Circle(displaySample[i].x, displaySample[i].y,3);
delay(20);
LCD.Circle(displaySample[i].x, displaySample[i].y,2);
delay(20);
LCD.Circle(displaySample[i].x, displaySample[i].y,1);
delay(60);
LCD.Color = WHITE;
LCD.Circle(displaySample[i].x, displaySample[i].y,4);
delay(20);
LCD.Circle(displaySample[i].x, displaySample[i].y,3);
delay(20);
LCD.Circle(displaySample[i].x, displaySample[i].y,2);
delay(20);
LCD.Circle(displaySample[i].x, displaySample[i].y,1);
delay(250);
}
LCD.Clear(BLACK);
LCD.TextBox(0, 0, LCD.getMaxX(), 30, "Calibrating", ALINE_CENTER);
setCalibrationMatrix(&displaySample[0], &screenSample[0], &TS.matrix); // calibration
TS.setMatrix(); // save matrix to eeprom
LCD.Clear(BLACK);
LCD.TextBox(0, 0, LCD.getMaxX(), 30, "Calibrated", ALINE_CENTER);
delay(1000);
}
void setup()
{
LCD.Reset();
LCD.Clear(BLACK);
LCD.Font(f20x19);
TS.Reset();
touch_calibrate(); // use for calibrate only
LCD.Color = WHITE; // graphic color
LCD.FgColor = GREEN; // text foreground color
LCD.BkColor = RED; // text background color
LCD.TextBox( 0, 250, 59, 279, "scrX", ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
LCD.TextBox( 60, 250, 119, 279, "scrY", ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
LCD.TextBox(120, 250, 179, 279, "lcdX", ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
LCD.TextBox(180, 250, 239, 279, "lcdY", ALINE_CENTER | BORDER_RECT | BORDER_FILL | BEVEL(8));
}
void loop()
{
showPoint();
}