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:
Sat Dec 17 18:55:31 2016 +0000
Revision:
2:c5085faf2aa5
Child:
14:b174ec6e3ca0
Touch pad library is working.

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 2:c5085faf2aa5 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 2:c5085faf2aa5 51 int y2 = readTouch(_xp,_xm,_yp,_ym);
trevieze 2:c5085faf2aa5 52 int x2 = readTouch(_yp,_ym,_xp,_xm);
trevieze 2:c5085faf2aa5 53 int y1 = readTouch(_xp,_xm,_yp,_ym);
trevieze 2:c5085faf2aa5 54 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 2:c5085faf2aa5 59 p.x = x1 + x2;
trevieze 2:c5085faf2aa5 60 p.y = y1 + y2;
trevieze 2:c5085faf2aa5 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 2:c5085faf2aa5 69 rtouch *= (2046-p.x)/2;
trevieze 2:c5085faf2aa5 70 rtouch *= RXPLATE;
trevieze 2:c5085faf2aa5 71 rtouch /= 1024;
trevieze 2:c5085faf2aa5 72 p.z = abs(rtouch);
trevieze 2:c5085faf2aa5 73 }