This is a fork of a functional ILI9341 display with a functional Seeed touch screen library.

Dependencies:   BMP180 UniGraphic mbed BNO055_fusionI_fixed HTU21D GPSISR Compass Fonts uGUI

Fork of TFT_test_NUCLEO-F411RE by Motoo Tanaka

/media/uploads/trevieze/win_20170427_21_31_20_pro.jpg

Had to move sensors to a remote board because of interference. Added spi burst mode to supported displays.

To do.... ugui buttons are slow. will need to add rtos to project. Finish other way points screen. Will have to rewrite portions of the touch screen class. Sense touch, delay, read values and then average, touch released, is the sequence. Add cadence input and logic to program for computer screen.

Committer:
trevieze
Date:
Thu Jul 20 19:34:41 2017 +0000
Revision:
17:4f10efd72d9d
Parent:
14:b174ec6e3ca0
Child:
20:3ada4387cc1b
Has a visible compass now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trevieze 2:c5085faf2aa5 1 /* mbed library for resistive touch pads
trevieze 2:c5085faf2aa5 2 * uses 4 pins - 2 IO and 2 Analog
trevieze 2:c5085faf2aa5 3
trevieze 2:c5085faf2aa5 4 * c 2011 Peter Drescher - DC2PD
trevieze 2:c5085faf2aa5 5 *
trevieze 2:c5085faf2aa5 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
trevieze 2:c5085faf2aa5 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
trevieze 2:c5085faf2aa5 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
trevieze 2:c5085faf2aa5 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
trevieze 2:c5085faf2aa5 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
trevieze 2:c5085faf2aa5 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
trevieze 2:c5085faf2aa5 12 * THE SOFTWARE.
trevieze 2:c5085faf2aa5 13 */
trevieze 2:c5085faf2aa5 14
trevieze 2:c5085faf2aa5 15
trevieze 2:c5085faf2aa5 16 #include "mbed.h"
trevieze 2:c5085faf2aa5 17 #include "SeeedStudioTFTv2.h"
trevieze 17:4f10efd72d9d 18 //#include "SmoothAnalogIn.h"
trevieze 2:c5085faf2aa5 19
trevieze 17:4f10efd72d9d 20 extern Serial pc;
trevieze 17:4f10efd72d9d 21 //SmoothAnalogIn analogY(PIN_YP, .1, 1, 1);
trevieze 17:4f10efd72d9d 22 //SmoothAnalogIn analogX(PIN_XP, .1, 1, 1);
trevieze 2:c5085faf2aa5 23
trevieze 2:c5085faf2aa5 24 TouchScreen::TouchScreen(PinName xp, PinName xm, PinName yp, PinName ym)
trevieze 2:c5085faf2aa5 25 {
trevieze 2:c5085faf2aa5 26 //font = NULL;
trevieze 2:c5085faf2aa5 27 // touch screen pins
trevieze 2:c5085faf2aa5 28 _xp = xp;
trevieze 2:c5085faf2aa5 29 _yp = yp;
trevieze 2:c5085faf2aa5 30 _xm = xm;
trevieze 2:c5085faf2aa5 31 _ym = ym;
trevieze 2:c5085faf2aa5 32 // default touch calibration
trevieze 2:c5085faf2aa5 33 // orientation // 0 1 2 3
trevieze 2:c5085faf2aa5 34 x_off = 108000; // 17252 16605 108755 108000
trevieze 2:c5085faf2aa5 35 y_off = 22000; // 22330 105819 97167 22000
trevieze 2:c5085faf2aa5 36 pp_tx = -291; // 378 289 -390 -291
trevieze 2:c5085faf2aa5 37 pp_ty = 356; // 261 -355 -239 356
trevieze 17:4f10efd72d9d 38
trevieze 2:c5085faf2aa5 39 }
trevieze 2:c5085faf2aa5 40
trevieze 2:c5085faf2aa5 41 int TouchScreen::readTouch(PinName p, PinName m, PinName a, PinName i)
trevieze 2:c5085faf2aa5 42 {
trevieze 2:c5085faf2aa5 43 DigitalOut _p(p);
trevieze 2:c5085faf2aa5 44 _p = 1;
trevieze 2:c5085faf2aa5 45 DigitalOut _m(m);
trevieze 2:c5085faf2aa5 46 _m = 0;
trevieze 2:c5085faf2aa5 47 AnalogIn _a(a);
trevieze 2:c5085faf2aa5 48 AnalogIn _i(i); // this pin has to be high Z (DigitalIn may also work)
trevieze 2:c5085faf2aa5 49 wait_us(10);
trevieze 2:c5085faf2aa5 50 return _a.read_u16();
trevieze 2:c5085faf2aa5 51 }
trevieze 2:c5085faf2aa5 52
trevieze 2:c5085faf2aa5 53 void TouchScreen :: getTouch(point& p)
trevieze 2:c5085faf2aa5 54 {
trevieze 14:b174ec6e3ca0 55 volatile int y2 = readTouch(_xp,_xm,_yp,_ym);
trevieze 14:b174ec6e3ca0 56 volatile int x2 = readTouch(_yp,_ym,_xp,_xm);
trevieze 14:b174ec6e3ca0 57 volatile int y1 = readTouch(_xp,_xm,_yp,_ym);
trevieze 14:b174ec6e3ca0 58 volatile int x1 = readTouch(_yp,_ym,_xp,_xm);
trevieze 2:c5085faf2aa5 59 int xd = x1 - x2;
trevieze 2:c5085faf2aa5 60 int yd = y1 - y2;
trevieze 2:c5085faf2aa5 61 xd = (xd > 0) ? xd : -xd;
trevieze 2:c5085faf2aa5 62 yd = (yd > 0) ? xd : -xd;
trevieze 14:b174ec6e3ca0 63 p.y = x1 + x2;
trevieze 14:b174ec6e3ca0 64 p.x = y1 + y2;
trevieze 14:b174ec6e3ca0 65
trevieze 2:c5085faf2aa5 66 int z1 = _xm;
trevieze 2:c5085faf2aa5 67 int z2 = _yp;
trevieze 2:c5085faf2aa5 68 float rtouch = 0;
trevieze 2:c5085faf2aa5 69
trevieze 2:c5085faf2aa5 70 rtouch = z2;
trevieze 2:c5085faf2aa5 71 rtouch /= z1;
trevieze 2:c5085faf2aa5 72 rtouch -= 1;
trevieze 14:b174ec6e3ca0 73 rtouch *= (4094-p.x)/2;
trevieze 2:c5085faf2aa5 74 rtouch *= RXPLATE;
trevieze 14:b174ec6e3ca0 75 rtouch /= 2048;
trevieze 14:b174ec6e3ca0 76 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
trevieze 14:b174ec6e3ca0 77 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
trevieze 14:b174ec6e3ca0 78 p.z = abs(rtouch);
trevieze 14:b174ec6e3ca0 79 }
trevieze 14:b174ec6e3ca0 80
trevieze 14:b174ec6e3ca0 81 long TouchScreen :: map(long x, long in_min, long in_max, long out_min, long out_max)
trevieze 14:b174ec6e3ca0 82 {
trevieze 14:b174ec6e3ca0 83 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
trevieze 14:b174ec6e3ca0 84 }