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:
Fri May 18 18:26:36 2018 +0000
Revision:
22:39a8e5c47f3c
Parent:
21:39ef2fd5c4bf
Working on touch screen response. Loading new uGui class for a test drive.

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 21:39ef2fd5c4bf 39 int n, avg;
trevieze 21:39ef2fd5c4bf 40 // Setup analog ports to read X and Y touch values on display.
trevieze 2:c5085faf2aa5 41 DigitalOut _p(p);
trevieze 2:c5085faf2aa5 42 _p = 1;
trevieze 2:c5085faf2aa5 43 DigitalOut _m(m);
trevieze 2:c5085faf2aa5 44 _m = 0;
trevieze 2:c5085faf2aa5 45 AnalogIn _a(a);
trevieze 2:c5085faf2aa5 46 AnalogIn _i(i); // this pin has to be high Z (DigitalIn may also work)
trevieze 21:39ef2fd5c4bf 47
trevieze 21:39ef2fd5c4bf 48 // Put averaging solution here. Take n samples then average.
trevieze 21:39ef2fd5c4bf 49 n=5000;
trevieze 21:39ef2fd5c4bf 50 for (int j=0; i<n; j++) {
trevieze 21:39ef2fd5c4bf 51 avg = avg + _a.read_u16();
trevieze 21:39ef2fd5c4bf 52 }
trevieze 21:39ef2fd5c4bf 53 avg=avg/n;
trevieze 21:39ef2fd5c4bf 54
trevieze 2:c5085faf2aa5 55 wait_us(10);
trevieze 21:39ef2fd5c4bf 56 //return _a.read_u16();
trevieze 21:39ef2fd5c4bf 57 return avg;
trevieze 2:c5085faf2aa5 58 }
trevieze 2:c5085faf2aa5 59
trevieze 2:c5085faf2aa5 60 void TouchScreen :: getTouch(point& p)
trevieze 2:c5085faf2aa5 61 {
trevieze 14:b174ec6e3ca0 62 volatile int y2 = readTouch(_xp,_xm,_yp,_ym);
trevieze 14:b174ec6e3ca0 63 volatile int x2 = readTouch(_yp,_ym,_xp,_xm);
trevieze 14:b174ec6e3ca0 64 volatile int y1 = readTouch(_xp,_xm,_yp,_ym);
trevieze 14:b174ec6e3ca0 65 volatile int x1 = readTouch(_yp,_ym,_xp,_xm);
trevieze 2:c5085faf2aa5 66 int xd = x1 - x2;
trevieze 2:c5085faf2aa5 67 int yd = y1 - y2;
trevieze 2:c5085faf2aa5 68 xd = (xd > 0) ? xd : -xd;
trevieze 2:c5085faf2aa5 69 yd = (yd > 0) ? xd : -xd;
trevieze 14:b174ec6e3ca0 70 p.y = x1 + x2;
trevieze 14:b174ec6e3ca0 71 p.x = y1 + y2;
trevieze 14:b174ec6e3ca0 72
trevieze 2:c5085faf2aa5 73 int z1 = _xm;
trevieze 2:c5085faf2aa5 74 int z2 = _yp;
trevieze 2:c5085faf2aa5 75 float rtouch = 0;
trevieze 2:c5085faf2aa5 76
trevieze 2:c5085faf2aa5 77 rtouch = z2;
trevieze 2:c5085faf2aa5 78 rtouch /= z1;
trevieze 2:c5085faf2aa5 79 rtouch -= 1;
trevieze 22:39a8e5c47f3c 80 //Constants from origional reference.
trevieze 22:39a8e5c47f3c 81 //12 bit ADC
trevieze 14:b174ec6e3ca0 82 rtouch *= (4094-p.x)/2;
trevieze 2:c5085faf2aa5 83 rtouch *= RXPLATE;
trevieze 14:b174ec6e3ca0 84 rtouch /= 2048;
trevieze 14:b174ec6e3ca0 85 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
trevieze 14:b174ec6e3ca0 86 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
trevieze 14:b174ec6e3ca0 87 p.z = abs(rtouch);
trevieze 14:b174ec6e3ca0 88 }
trevieze 14:b174ec6e3ca0 89
trevieze 14:b174ec6e3ca0 90 long TouchScreen :: map(long x, long in_min, long in_max, long out_min, long out_max)
trevieze 14:b174ec6e3ca0 91 {
trevieze 14:b174ec6e3ca0 92 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
trevieze 14:b174ec6e3ca0 93 }