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:
Wed May 16 13:25:59 2018 +0000
Revision:
20:3ada4387cc1b
Parent:
18:50520438c129
Child:
21:39ef2fd5c4bf
Commit 5/26/2018 No changes that I am aware of.

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 2:c5085faf2aa5 18
trevieze 20:3ada4387cc1b 19 //Serial pc(USBTX,USBRX,19200);
trevieze 2:c5085faf2aa5 20
trevieze 2:c5085faf2aa5 21 TouchScreen::TouchScreen(PinName xp, PinName xm, PinName yp, PinName ym)
trevieze 2:c5085faf2aa5 22 {
trevieze 2:c5085faf2aa5 23 //font = NULL;
trevieze 2:c5085faf2aa5 24 // touch screen pins
trevieze 2:c5085faf2aa5 25 _xp = xp;
trevieze 2:c5085faf2aa5 26 _yp = yp;
trevieze 2:c5085faf2aa5 27 _xm = xm;
trevieze 2:c5085faf2aa5 28 _ym = ym;
trevieze 2:c5085faf2aa5 29 // default touch calibration
trevieze 2:c5085faf2aa5 30 // orientation // 0 1 2 3
trevieze 2:c5085faf2aa5 31 x_off = 108000; // 17252 16605 108755 108000
trevieze 2:c5085faf2aa5 32 y_off = 22000; // 22330 105819 97167 22000
trevieze 2:c5085faf2aa5 33 pp_tx = -291; // 378 289 -390 -291
trevieze 2:c5085faf2aa5 34 pp_ty = 356; // 261 -355 -239 356
trevieze 2:c5085faf2aa5 35 }
trevieze 2:c5085faf2aa5 36
trevieze 2:c5085faf2aa5 37 int TouchScreen::readTouch(PinName p, PinName m, PinName a, PinName i)
trevieze 2:c5085faf2aa5 38 {
trevieze 2:c5085faf2aa5 39 DigitalOut _p(p);
trevieze 2:c5085faf2aa5 40 _p = 1;
trevieze 2:c5085faf2aa5 41 DigitalOut _m(m);
trevieze 2:c5085faf2aa5 42 _m = 0;
trevieze 2:c5085faf2aa5 43 AnalogIn _a(a);
trevieze 2:c5085faf2aa5 44 AnalogIn _i(i); // this pin has to be high Z (DigitalIn may also work)
trevieze 2:c5085faf2aa5 45 wait_us(10);
trevieze 2:c5085faf2aa5 46 return _a.read_u16();
trevieze 2:c5085faf2aa5 47 }
trevieze 2:c5085faf2aa5 48
trevieze 2:c5085faf2aa5 49 void TouchScreen :: getTouch(point& p)
trevieze 2:c5085faf2aa5 50 {
trevieze 14:b174ec6e3ca0 51 volatile int y2 = readTouch(_xp,_xm,_yp,_ym);
trevieze 14:b174ec6e3ca0 52 volatile int x2 = readTouch(_yp,_ym,_xp,_xm);
trevieze 14:b174ec6e3ca0 53 volatile int y1 = readTouch(_xp,_xm,_yp,_ym);
trevieze 14:b174ec6e3ca0 54 volatile int x1 = readTouch(_yp,_ym,_xp,_xm);
trevieze 2:c5085faf2aa5 55 int xd = x1 - x2;
trevieze 2:c5085faf2aa5 56 int yd = y1 - y2;
trevieze 2:c5085faf2aa5 57 xd = (xd > 0) ? xd : -xd;
trevieze 2:c5085faf2aa5 58 yd = (yd > 0) ? xd : -xd;
trevieze 14:b174ec6e3ca0 59 p.y = x1 + x2;
trevieze 14:b174ec6e3ca0 60 p.x = y1 + y2;
trevieze 14:b174ec6e3ca0 61
trevieze 2:c5085faf2aa5 62 int z1 = _xm;
trevieze 2:c5085faf2aa5 63 int z2 = _yp;
trevieze 2:c5085faf2aa5 64 float rtouch = 0;
trevieze 2:c5085faf2aa5 65
trevieze 2:c5085faf2aa5 66 rtouch = z2;
trevieze 2:c5085faf2aa5 67 rtouch /= z1;
trevieze 2:c5085faf2aa5 68 rtouch -= 1;
trevieze 14:b174ec6e3ca0 69 rtouch *= (4094-p.x)/2;
trevieze 2:c5085faf2aa5 70 rtouch *= RXPLATE;
trevieze 14:b174ec6e3ca0 71 rtouch /= 2048;
trevieze 14:b174ec6e3ca0 72 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
trevieze 14:b174ec6e3ca0 73 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
trevieze 14:b174ec6e3ca0 74 p.z = abs(rtouch);
trevieze 14:b174ec6e3ca0 75 }
trevieze 14:b174ec6e3ca0 76
trevieze 14:b174ec6e3ca0 77 long TouchScreen :: map(long x, long in_min, long in_max, long out_min, long out_max)
trevieze 14:b174ec6e3ca0 78 {
trevieze 14:b174ec6e3ca0 79 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
trevieze 14:b174ec6e3ca0 80 }