Works
Dependencies: BMP180 BNO055_fusion Fonts GPSISR HTU21D SDFileSystem UniGraphic mbed uGUI
Fork of Bicycl_Computer_NUCLEO-F411RE by
Diff: SeeedStudioTFTv2.cpp
- Revision:
- 15:b174ec6e3ca0
- Parent:
- 2:c5085faf2aa5
diff -r 4f0ebc5a4f00 -r b174ec6e3ca0 SeeedStudioTFTv2.cpp --- a/SeeedStudioTFTv2.cpp Fri Mar 03 02:56:25 2017 +0000 +++ b/SeeedStudioTFTv2.cpp Wed Apr 12 20:30:06 2017 +0000 @@ -48,17 +48,17 @@ void TouchScreen :: getTouch(point& p) { - int y2 = readTouch(_xp,_xm,_yp,_ym); - int x2 = readTouch(_yp,_ym,_xp,_xm); - int y1 = readTouch(_xp,_xm,_yp,_ym); - int x1 = readTouch(_yp,_ym,_xp,_xm); + volatile int y2 = readTouch(_xp,_xm,_yp,_ym); + volatile int x2 = readTouch(_yp,_ym,_xp,_xm); + volatile int y1 = readTouch(_xp,_xm,_yp,_ym); + volatile int x1 = readTouch(_yp,_ym,_xp,_xm); int xd = x1 - x2; int yd = y1 - y2; xd = (xd > 0) ? xd : -xd; yd = (yd > 0) ? xd : -xd; - p.x = x1 + x2; - p.y = y1 + y2; - + p.y = x1 + x2; + p.x = y1 + y2; + int z1 = _xm; int z2 = _yp; float rtouch = 0; @@ -66,8 +66,15 @@ rtouch = z2; rtouch /= z1; rtouch -= 1; - rtouch *= (2046-p.x)/2; + rtouch *= (4094-p.x)/2; rtouch *= RXPLATE; - rtouch /= 1024; - p.z = abs(rtouch); - } \ No newline at end of file + rtouch /= 2048; + p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); + p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); + p.z = abs(rtouch); + } + + long TouchScreen :: map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +}