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
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.
Diff: main.cpp
- Revision:
- 20:3ada4387cc1b
- Parent:
- 18:50520438c129
- Child:
- 21:39ef2fd5c4bf
--- a/main.cpp Fri Aug 04 20:12:07 2017 +0000 +++ b/main.cpp Wed May 16 13:25:59 2018 +0000 @@ -22,7 +22,6 @@ #include "mbed.h" #include <math.h> #include "ILI9341.h" -//#include "TFT.h" // Graphics GUI Library #include "ugui.h" @@ -42,8 +41,6 @@ #include "ArialR20x20.h" #include "compass.h" -//#define PIN_CS_TSC PA_9 -//#define PIN_TSC_INTR PA_8 #define PIN_RESET_TFT PC_13 /* place holder */ //ILI9341 SPI PINS #define PIN_XP A3 @@ -58,9 +55,9 @@ #define PIN_CS_SD D4 #define PIN_RESET D7 // SD Card on GPS shield PINS -#define PIN_MOSI_SPI3 PB_15 //SPI 1 MOSI -#define PIN_MISO_SPI3 PB_14 //SPI 1 MISO -#define PIN_SCLK_SPI3 PB_13 //SPI 1 SLCK +#define PIN_MOSI_SPI3 PB_15 //SPI 3 MOSI +#define PIN_MISO_SPI3 PB_14 //SPI 3 MISO +#define PIN_SCLK_SPI3 PB_13 //SPI 3 SLCK #define PIN_CS_SPI3 D2 // SPI CS #define PIN_RX_GPS PA_12 //GPS Shield RX pin #define PIN_TX_GPS PA_11 //GPS Shield TX pin @@ -80,8 +77,6 @@ #endif //DigitalOut backlight(PB_3) ; -// DigitalOut tsc_cs(PA_9, 1) ; -// DigitalOut tft_cs(PB_6, 1) ; /** Height of display using default orientation */ #define ILI9341_DEFAULT_HEIGHT 240 @@ -121,7 +116,6 @@ double plat = 42.826420; double plon = -84.219413; -void Draw_Compass_Rose(void); void arrow(int x2, int y2, int x1, int y1, int alength, int awidth, int colour); void ili9341_pset(UG_S16 ul_x,UG_S16 ul_y, UG_COLOR ul_color); void window_1_callback( UG_MESSAGE* msg ); @@ -129,25 +123,34 @@ void window_3_callback( UG_MESSAGE* msg ); void cb1(void); -const int centreX = 120; +const int centreX = 120; // e compass indicator const int centreY = 136; const int radius = 104; float last_dx; float last_dy; int pageid = 1; -bool pageinit = 0; +bool pageinit = false; + +struct pt { + int x; + int y; + bool z; +}; +pt ptouch; + #define PAGE1 1 #define PAGE2 2 #define PAGE3 3 UG_GUI gui; -//Ticker to1; - int main() { - //to1.attach(&cb1, 2.0); + //Read touch screen every 0.2 seconds and pass it to uGUI + //Ticker TFTtick; + //TFTtick.attach(&cb1, 0.2); + TFT.BusEnable(true) ; TFT.FastWindow(true) ; wait(0.1); @@ -161,8 +164,7 @@ refresh_Timer.start(); //starts the clock on the timer //backlight = 0 ; wait(0.1); - - // Draw_Compass_Rose(); + /* Window 1 Bike Computer */ #define MAX_OBJECTS 10 UG_WINDOW window_1 ; /* Window */ @@ -229,7 +231,7 @@ UG_ButtonSetFont (&window_3 , BTN_ID_5 , &FONT_8X8) ; UG_ButtonSetText (&window_3 , BTN_ID_4 , "Prev" ); UG_ButtonSetText (&window_3 , BTN_ID_5 , "Next" ); - + while (1) { cb1(); @@ -323,29 +325,29 @@ UG_WindowHide(&window_3); UG_WindowShow(&window_2); UG_Update(); - TFT.drawXBitmap(20,35,compass,compass_width,compass_height,C_WHITE); - } - pageinit = 1; + TFT.drawXBitmap(20,35,compass,compass_width,compass_height,C_WHITE); + } + pageinit = 1; if (imu.read_calib_status() > 0x0) { - imu.get_Euler_Angles(&euler_angles); - float angle = euler_angles.h; // Convert radians to degrees for more a more usual result - - TFT.set_font((unsigned char*) ArialR20x20); - TFT.foreground(White); - TFT.background(UG_WindowGetBackColor(&window_1)); - TFT.locate(10, 224) ; - TFT.printf("%.1f*", euler_angles.h); - - // For the screen -X = up and +X = down and -Y = left and +Y = right, so does not follow coordinate conventions - float dx = (radius * cos((angle-90)*PI/180)) + centreX; // calculate X position for the screen coordinates - can be confusing! - float dy = (radius * sin((angle-90)*PI/180)) + centreY; // calculate Y position for the screen coordinates - can be confusing! - arrow(last_dx,last_dy, centreX, centreY, 2,2,UG_WindowGetBackColor(&window_2)); // Erase last arrow - arrow(dx,dy, centreX, centreY, 2, 2,C_WHITE); // Draw arrow in new position - last_dx = dx; - last_dy = dy; + imu.get_Euler_Angles(&euler_angles); + float angle = euler_angles.h; // Convert radians to degrees for more a more usual result + + TFT.set_font((unsigned char*) ArialR20x20); + TFT.foreground(White); + TFT.background(UG_WindowGetBackColor(&window_1)); + TFT.locate(10, 224) ; + TFT.printf("%.1f*", euler_angles.h); + + // For the screen -X = up and +X = down and -Y = left and +Y = right, so does not follow coordinate conventions + float dx = (radius * cos((angle-90)*PI/180)) + centreX; // calculate X position for the screen coordinates - can be confusing! + float dy = (radius * sin((angle-90)*PI/180)) + centreY; // calculate Y position for the screen coordinates - can be confusing! + arrow(last_dx,last_dy, centreX, centreY, 2,2,UG_WindowGetBackColor(&window_2)); // Erase last arrow + arrow(dx,dy, centreX, centreY, 2, 2,C_WHITE); // Draw arrow in new position + last_dx = dx; + last_dy = dy; } - - + + break; } case PAGE3: { @@ -434,30 +436,6 @@ TFT.set_font((unsigned char*) ArialR20x20); } -void Draw_Compass_Rose(void) -{ - int dxo, dyo, dxi, dyi; - TFT.circle(centreX,centreY,radius,Blue); // Draw compass circle - for (float i = 0; i <360; i = i + 22.5) { - dxo = radius * cos(i*3.14/180); - dyo = radius * sin(i*3.14/180); - dxi = dxo * 0.95; - dyi = dyo * 0.95; - TFT.line(dxi+centreX,dyi+centreY,dxo+centreX,dyo+centreY,Blue); - } - TFT.set_font((unsigned char*) Arial12x12); - TFT.foreground(Blue); - TFT.background(White); - TFT.locate((centreX-2),(centreY-24)); - TFT.printf("N"); - TFT.locate((centreX-2),(centreY+17)); - TFT.printf("S"); - TFT.locate((centreX+19),(centreY-3)); - TFT.printf("E"); - TFT.locate((centreX-23),(centreY-3)); - TFT.printf("W"); -} - void ili9341_pset(UG_S16 ul_x,UG_S16 ul_y, UG_COLOR ul_color) { TFT.pixel(ul_x, ul_y, ul_color); @@ -545,8 +523,15 @@ { point p; TSC.getTouch(p); - if (p.z > __PRESURE) { - UG_TouchUpdate ( p.x, p.y, TOUCH_STATE_PRESSED ) ; + // Only update uGui when screen has been released + if (p.z >= __PRESURE) { + ptouch.x = p.x; + ptouch.y = p.y; + ptouch.z = true; + } + if (p.z < __NOPRESURE and ptouch.z) { + UG_TouchUpdate ( ptouch.x, ptouch.y, TOUCH_STATE_PRESSED ) ; + ptouch.z = false; } else { UG_TouchUpdate (-1, -1, TOUCH_STATE_RELEASED ) ; }