touch screen handler for the microchip AR1020
Revision 3:b7eb3b3fe79f, committed 2011-02-22
- Comitter:
- hlipka
- Date:
- Tue Feb 22 22:54:25 2011 +0000
- Parent:
- 2:1a436d154c84
- Child:
- 4:510ea5b28a05
- Commit message:
- initial public version
Changed in this revision
AreaTouchHandler.cpp | Show annotated file Show diff for this revision Revisions of this file |
ar1020.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/AreaTouchHandler.cpp Tue Feb 22 22:11:49 2011 +0000 +++ b/AreaTouchHandler.cpp Tue Feb 22 22:54:25 2011 +0000 @@ -29,6 +29,7 @@ uint32_t AreaTouchHandler::down(uint32_t arg) { TouchEvent *te=(TouchEvent*)arg; +// printf("d %i/%i\n",te->x,te->y); _x=te->x; _y=te->y; _samples=1; @@ -46,7 +47,7 @@ if (_called) return 0; TouchEvent *te=(TouchEvent*)arg; - printf("%i\n",te->y); +// printf("m %i/%i\n",te->x,te->y); _x=(te->x+_x*_samples)/(_samples+1); _y=(te->y+_y*_samples)/(_samples+1); _samples++; @@ -60,7 +61,6 @@ } uint32_t AreaTouchHandler::up(uint32_t arg) { - printf("up\n"); _x=0; _y=0; _samples=0; @@ -72,14 +72,12 @@ { if (_called) return 0; - if (_samples<3) + if (_samples<5) return 0; - printf("%f\n",_y); for (list<area*>::iterator it = _areas.begin(); it != _areas.end(); it++) { area* a=*it; if (_x>=a->left && _x<=a->right && _y>=a->top && _y<=a->bottom) return a->command; } - printf(".\n"); return 0; }
--- a/ar1020.cpp Tue Feb 22 22:11:49 2011 +0000 +++ b/ar1020.cpp Tue Feb 22 22:54:25 2011 +0000 @@ -63,24 +63,36 @@ } void AR1020::init() { - _power->write(1); - wait_ms(100); - int r=cmd(0x13,NULL,0); - printf("disable touch=%i\n",r); - - int regStart=cmd(0x22,NULL,0); - printf("reg offset=%i\n",regStart); - - if (regStart<0) - return; - - char cid2[4]={0x00,0x0d+regStart,0x01,0x01}; - r=cmd(0x21,cid2,4); - printf("set mode=1 => %i\n",r); - - - r=cmd(0x12,NULL,0); - printf("enable touch=%i\n",r); + bool ok=false; + while (!ok) + { + _power->write(0); + wait_ms(200); + _power->write(1); + wait_ms(100); + int r=cmd(0x13,NULL,0); + printf("disable touch=%i\n",r); + if (0!=r) + continue; + + int regStart=cmd(0x22,NULL,0); + printf("reg offset=%i\n",regStart); + + if (regStart<0) + continue; + + char cid2[4]={0x00,0x0d+regStart,0x01,0x01}; + r=cmd(0x21,cid2,4); + printf("set mode=1 => %i\n",r); + if (0!=r) + continue; + + r=cmd(0x12,NULL,0); + printf("enable touch=%i\n",r); + if (0!=r) + continue; + ok=true; + } _irq->rise(this, &AR1020::read); }