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:
15:27e0a1721d13
Has a visible compass now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:cd5e3d371b54 1 /* mbed main.cpp to test adafruit 2.8" TFT LCD shiled w Touchscreen
Rhyme 0:cd5e3d371b54 2 * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
Rhyme 0:cd5e3d371b54 3 *
Rhyme 0:cd5e3d371b54 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Rhyme 0:cd5e3d371b54 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Rhyme 0:cd5e3d371b54 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Rhyme 0:cd5e3d371b54 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Rhyme 0:cd5e3d371b54 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Rhyme 0:cd5e3d371b54 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Rhyme 0:cd5e3d371b54 10 * THE SOFTWARE.
Rhyme 0:cd5e3d371b54 11 */
trevieze 15:27e0a1721d13 12
trevieze 15:27e0a1721d13 13 /*
trevieze 15:27e0a1721d13 14 * Note: This program is derived from the SeeeStudioTFTv2 program.
trevieze 15:27e0a1721d13 15 * Although both program share same ILI9341 TFT driver,
trevieze 15:27e0a1721d13 16 * the touch sensor was not same with the Display I purchased from Akizuki.
trevieze 15:27e0a1721d13 17 * http://akizukidenshi.com/catalog/g/gM-07747/
trevieze 15:27e0a1721d13 18 * The touch sensor on the display is STMPE610,
trevieze 15:27e0a1721d13 19 * so I hacked the minimum spi driver for it (polling mode only).
trevieze 15:27e0a1721d13 20 */
Rhyme 0:cd5e3d371b54 21
Rhyme 0:cd5e3d371b54 22 #include "mbed.h"
Rhyme 0:cd5e3d371b54 23 #include <math.h>
Rhyme 0:cd5e3d371b54 24 #include "ILI9341.h"
trevieze 14:b174ec6e3ca0 25 //#include "TFT.h"
trevieze 14:b174ec6e3ca0 26 // Graphics GUI Library
trevieze 14:b174ec6e3ca0 27 #include "ugui.h"
trevieze 14:b174ec6e3ca0 28
trevieze 2:c5085faf2aa5 29 #include "SeeedStudioTFTv2.h"
trevieze 5:6eb4b9322931 30 #include "BNO055.h"
trevieze 5:6eb4b9322931 31 #include "HTU21D.h"
trevieze 5:6eb4b9322931 32 #include "BMP180.h"
trevieze 7:8aa9cdab4a07 33 #include "SDFileSystem.h"
trevieze 7:8aa9cdab4a07 34 #include "GPSISR.h"
trevieze 12:1a9c0f9d7128 35 #include "nav.h"
trevieze 8:855884782f67 36
trevieze 10:869a102dd31c 37 #include "ArialR16x17.h"
trevieze 10:869a102dd31c 38 #include "Arial24x23i.h"
trevieze 10:869a102dd31c 39 #include "Arial28x28.h"
trevieze 10:869a102dd31c 40 #include "Neu44x36.h"
trevieze 10:869a102dd31c 41 #include "SCProSB31x55.h"
Rhyme 0:cd5e3d371b54 42 #include "Arial12x12.h"
trevieze 10:869a102dd31c 43 #include "ArialR20x20.h"
trevieze 17:4f10efd72d9d 44 #include "compass.h"
Rhyme 0:cd5e3d371b54 45
trevieze 15:27e0a1721d13 46 //#define PIN_CS_TSC PA_9
trevieze 7:8aa9cdab4a07 47 //#define PIN_TSC_INTR PA_8
Rhyme 0:cd5e3d371b54 48 #define PIN_RESET_TFT PC_13 /* place holder */
trevieze 7:8aa9cdab4a07 49 //ILI9341 SPI PINS
trevieze 1:e265e7245ab8 50 #define PIN_XP A3
trevieze 1:e265e7245ab8 51 #define PIN_XM A1
trevieze 1:e265e7245ab8 52 #define PIN_YP A2
trevieze 1:e265e7245ab8 53 #define PIN_YM A0
trevieze 7:8aa9cdab4a07 54 #define PIN_MOSI_SPI1 D11 //SPI 1 MOSI
trevieze 7:8aa9cdab4a07 55 #define PIN_MISO_SPI1 D12 //SPI 1 MISO
trevieze 7:8aa9cdab4a07 56 #define PIN_SCLK_SPI1 D13 //SPI 1 SLCK
trevieze 7:8aa9cdab4a07 57 #define PIN_CS_SPI1 D5 // SPI CS D10 Was D5
trevieze 1:e265e7245ab8 58 #define PIN_DC_TFT D6
trevieze 1:e265e7245ab8 59 #define PIN_CS_SD D4
trevieze 5:6eb4b9322931 60 #define PIN_RESET D7
trevieze 7:8aa9cdab4a07 61 // SD Card on GPS shield PINS
trevieze 7:8aa9cdab4a07 62 #define PIN_MOSI_SPI3 PB_15 //SPI 1 MOSI
trevieze 7:8aa9cdab4a07 63 #define PIN_MISO_SPI3 PB_14 //SPI 1 MISO
trevieze 7:8aa9cdab4a07 64 #define PIN_SCLK_SPI3 PB_13 //SPI 1 SLCK
trevieze 7:8aa9cdab4a07 65 #define PIN_CS_SPI3 D2 // SPI CS
trevieze 7:8aa9cdab4a07 66 #define PIN_RX_GPS PA_12 //GPS Shield RX pin
trevieze 7:8aa9cdab4a07 67 #define PIN_TX_GPS PA_11 //GPS Shield TX pin
trevieze 7:8aa9cdab4a07 68
trevieze 10:869a102dd31c 69 #define PI 3.14159265358979f
trevieze 14:b174ec6e3ca0 70 BNO055_ID_INF_TypeDef bno055_id_inf;
trevieze 14:b174ec6e3ca0 71 BNO055_EULER_TypeDef euler_angles;
trevieze 14:b174ec6e3ca0 72 BNO055_QUATERNION_TypeDef quaternion;
trevieze 14:b174ec6e3ca0 73 BNO055_LIN_ACC_TypeDef linear_acc;
trevieze 14:b174ec6e3ca0 74 BNO055_GRAVITY_TypeDef gravity;
trevieze 14:b174ec6e3ca0 75 BNO055_TEMPERATURE_TypeDef chip_temp;
trevieze 10:869a102dd31c 76
Rhyme 0:cd5e3d371b54 77 #define DEVICE_NAME "F411RE"
Rhyme 0:cd5e3d371b54 78
Rhyme 0:cd5e3d371b54 79 #ifndef TARGET_NECLEO_F411RE
trevieze 15:27e0a1721d13 80 #define TARGET_NECLEO_F411RE
Rhyme 0:cd5e3d371b54 81 #endif
Rhyme 0:cd5e3d371b54 82
trevieze 6:b78ff34209e5 83 //DigitalOut backlight(PB_3) ;
trevieze 5:6eb4b9322931 84 // DigitalOut tsc_cs(PA_9, 1) ;
trevieze 5:6eb4b9322931 85 // DigitalOut tft_cs(PB_6, 1) ;
Rhyme 0:cd5e3d371b54 86
trevieze 14:b174ec6e3ca0 87 /** Height of display using default orientation */
trevieze 14:b174ec6e3ca0 88 #define ILI9341_DEFAULT_HEIGHT 240
trevieze 14:b174ec6e3ca0 89
trevieze 14:b174ec6e3ca0 90 /** Width of display using default orientation */
trevieze 14:b174ec6e3ca0 91 #define ILI9341_DEFAULT_WIDTH 320
trevieze 14:b174ec6e3ca0 92
trevieze 14:b174ec6e3ca0 93 /** Height of display using swapped X/Y orientation */
trevieze 14:b174ec6e3ca0 94 #define ILI9341_SWITCH_XY_HEIGHT 320
trevieze 14:b174ec6e3ca0 95
trevieze 14:b174ec6e3ca0 96 /** Width of display using swapped X/Y orientation */
trevieze 14:b174ec6e3ca0 97 #define ILI9341_SWITCH_XY_WIDTH 240
trevieze 14:b174ec6e3ca0 98
trevieze 7:8aa9cdab4a07 99 Serial pc(USBTX, USBRX);
trevieze 7:8aa9cdab4a07 100
trevieze 5:6eb4b9322931 101 // Display
trevieze 15:27e0a1721d13 102 ILI9341 TFT(SPI_8, 20000000,
trevieze 15:27e0a1721d13 103 PIN_MOSI_SPI1, PIN_MISO_SPI1, PIN_SCLK_SPI1,
trevieze 15:27e0a1721d13 104 PIN_CS_SPI1, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
trevieze 15:27e0a1721d13 105
trevieze 5:6eb4b9322931 106 // TouchScreen
trevieze 2:c5085faf2aa5 107 TouchScreen TSC(PIN_XP, PIN_XM, PIN_YP, PIN_YM);
Rhyme 0:cd5e3d371b54 108
trevieze 5:6eb4b9322931 109 // 3 Axis IMU
trevieze 14:b174ec6e3ca0 110 BNO055 imu(I2C_SDA, I2C_SCL, PIN_RESET); // Reset =D7, addr = BNO055_G_CHIP_ADDR, mode = MODE_NDOF <- as default
trevieze 5:6eb4b9322931 111 // Humidity and Temperature
trevieze 10:869a102dd31c 112 HTU21D humid(I2C_SDA, I2C_SCL);
trevieze 5:6eb4b9322931 113
trevieze 5:6eb4b9322931 114 // Pressure
trevieze 6:b78ff34209e5 115 BMP180 bmp180(I2C_SDA, I2C_SCL);
trevieze 5:6eb4b9322931 116
trevieze 7:8aa9cdab4a07 117 // SD Card Reader On Adafruit GPS Shield
trevieze 7:8aa9cdab4a07 118 SDFileSystem sd(PIN_MOSI_SPI3, PIN_MISO_SPI3, PIN_SCLK_SPI3, PIN_CS_SPI3, "sd"); // the pinout on the mbed Cool Components workshop board
trevieze 7:8aa9cdab4a07 119
trevieze 8:855884782f67 120 // Set up serial interrupe service handler for gps characters.
trevieze 7:8aa9cdab4a07 121 GPS MyGPS(PIN_TX_GPS,PIN_RX_GPS, 9600);
trevieze 8:855884782f67 122
trevieze 12:1a9c0f9d7128 123 //Navigation Class.
trevieze 12:1a9c0f9d7128 124 NAV nav;
trevieze 12:1a9c0f9d7128 125 double plat = 42.826420;
trevieze 12:1a9c0f9d7128 126 double plon = -84.219413;
trevieze 12:1a9c0f9d7128 127
trevieze 10:869a102dd31c 128 void Draw_Compass_Rose(void);
trevieze 10:869a102dd31c 129 void arrow(int x2, int y2, int x1, int y1, int alength, int awidth, int colour);
trevieze 14:b174ec6e3ca0 130 void ili9341_pset(UG_S16 ul_x,UG_S16 ul_y, UG_COLOR ul_color);
trevieze 14:b174ec6e3ca0 131 void window_1_callback( UG_MESSAGE* msg );
trevieze 14:b174ec6e3ca0 132 void window_2_callback( UG_MESSAGE* msg );
trevieze 14:b174ec6e3ca0 133 void window_3_callback( UG_MESSAGE* msg );
trevieze 14:b174ec6e3ca0 134 void cb1(void);
Rhyme 0:cd5e3d371b54 135
trevieze 17:4f10efd72d9d 136 const int centreX = 100;
trevieze 17:4f10efd72d9d 137 const int centreY = 120;
trevieze 17:4f10efd72d9d 138 const int radius = 180;
trevieze 11:49600de70963 139 float last_dx;
trevieze 11:49600de70963 140 float last_dy;
Rhyme 0:cd5e3d371b54 141
trevieze 14:b174ec6e3ca0 142 int pageid = 1;
trevieze 14:b174ec6e3ca0 143 bool pageinit = 0;
trevieze 14:b174ec6e3ca0 144 #define PAGE1 1
trevieze 14:b174ec6e3ca0 145 #define PAGE2 2
trevieze 14:b174ec6e3ca0 146 #define PAGE3 3
trevieze 14:b174ec6e3ca0 147
trevieze 14:b174ec6e3ca0 148 UG_GUI gui;
trevieze 14:b174ec6e3ca0 149
trevieze 14:b174ec6e3ca0 150 //Ticker to1;
trevieze 14:b174ec6e3ca0 151
Rhyme 0:cd5e3d371b54 152 int main()
Rhyme 0:cd5e3d371b54 153 {
trevieze 15:27e0a1721d13 154 //to1.attach(&cb1, 2.0);
trevieze 9:a3cb458d7b1c 155 TFT.BusEnable(true) ;
trevieze 9:a3cb458d7b1c 156 TFT.FastWindow(true) ;
trevieze 9:a3cb458d7b1c 157 wait(0.1);
trevieze 9:a3cb458d7b1c 158 TFT.cls();
trevieze 9:a3cb458d7b1c 159 wait(0.1);
trevieze 15:27e0a1721d13 160
trevieze 15:27e0a1721d13 161 UG_Init(&gui,ili9341_pset,ILI9341_DEFAULT_HEIGHT,ILI9341_DEFAULT_WIDTH);
trevieze 15:27e0a1721d13 162
trevieze 7:8aa9cdab4a07 163 Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info?
trevieze 9:a3cb458d7b1c 164 const int refresh_Time = 2000; //refresh time in ms
trevieze 7:8aa9cdab4a07 165 refresh_Timer.start(); //starts the clock on the timer
trevieze 7:8aa9cdab4a07 166 //backlight = 0 ;
trevieze 9:a3cb458d7b1c 167 wait(0.1);
trevieze 15:27e0a1721d13 168
trevieze 15:27e0a1721d13 169 // Draw_Compass_Rose();
trevieze 14:b174ec6e3ca0 170 /* Window 1 Bike Computer */
trevieze 15:27e0a1721d13 171 #define MAX_OBJECTS 10
trevieze 14:b174ec6e3ca0 172 UG_WINDOW window_1 ; /* Window */
trevieze 14:b174ec6e3ca0 173 UG_BUTTON button_1; /* Button container */
trevieze 14:b174ec6e3ca0 174 UG_BUTTON button_2; /* Button container */
trevieze 14:b174ec6e3ca0 175 UG_OBJECT obj_buff_wnd_1 [MAX_OBJECTS] ; /* Object buffer */
trevieze 14:b174ec6e3ca0 176 UG_WindowCreate ( &window_1 , obj_buff_wnd_1 , MAX_OBJECTS, window_1_callback);
trevieze 14:b174ec6e3ca0 177 UG_WindowSetTitleTextFont ( &window_1 , &FONT_8X8 ) ;
trevieze 14:b174ec6e3ca0 178 UG_WindowSetTitleText ( &window_1 , "Bike Computer" ) ;
trevieze 14:b174ec6e3ca0 179 UG_WindowSetBackColor( &window_1 , C_GRAY ) ;
trevieze 14:b174ec6e3ca0 180 UG_ButtonCreate (&window_1, &button_1, BTN_ID_0, 10 , 230 , 115 , 290 );
trevieze 14:b174ec6e3ca0 181 UG_ButtonCreate (&window_1, &button_2, BTN_ID_1, 125 , 230 , 225 , 290 );
trevieze 14:b174ec6e3ca0 182 UG_ButtonSetBackColor (&window_1 ,BTN_ID_0 , C_BLUE ) ;
trevieze 14:b174ec6e3ca0 183 UG_ButtonSetForeColor (&window_1 ,BTN_ID_0 , C_WHITE ) ;
trevieze 14:b174ec6e3ca0 184 UG_ButtonSetBackColor (&window_1 ,BTN_ID_1 , C_BLUE ) ;
trevieze 14:b174ec6e3ca0 185 UG_ButtonSetForeColor (&window_1 ,BTN_ID_1 , C_WHITE ) ;
trevieze 14:b174ec6e3ca0 186 UG_ButtonSetFont (&window_1 , BTN_ID_0 , &FONT_8X8) ;
trevieze 14:b174ec6e3ca0 187 UG_ButtonSetFont (&window_1 , BTN_ID_1 , &FONT_8X8) ;
trevieze 14:b174ec6e3ca0 188 UG_ButtonSetText (&window_1 , BTN_ID_0 , "Prev" );
trevieze 14:b174ec6e3ca0 189 UG_ButtonSetText (&window_1 , BTN_ID_1 , "Next" );
trevieze 15:27e0a1721d13 190
trevieze 14:b174ec6e3ca0 191 /* Window 2 e-Compass */
trevieze 14:b174ec6e3ca0 192 UG_WINDOW window_2 ; /* Window */
trevieze 14:b174ec6e3ca0 193 UG_BUTTON button_3; /* Button container */
trevieze 14:b174ec6e3ca0 194 UG_BUTTON button_4; /* Button container */
trevieze 14:b174ec6e3ca0 195 UG_OBJECT obj_buff_wnd_2 [MAX_OBJECTS] ; /* Object buffer */
trevieze 14:b174ec6e3ca0 196 UG_WindowCreate ( &window_2 , obj_buff_wnd_2 , MAX_OBJECTS, window_2_callback);
trevieze 14:b174ec6e3ca0 197 UG_WindowSetTitleTextFont ( &window_2 , &FONT_8X8 ) ;
trevieze 14:b174ec6e3ca0 198 UG_WindowSetTitleText ( &window_2 , "e-Compass" ) ;
trevieze 14:b174ec6e3ca0 199 UG_WindowSetBackColor( &window_2 , C_GRAY ) ;
trevieze 14:b174ec6e3ca0 200 UG_ButtonCreate (&window_2, &button_3, BTN_ID_2, 10 , 230 , 115 , 290 );
trevieze 14:b174ec6e3ca0 201 UG_ButtonCreate (&window_2, &button_4, BTN_ID_3, 125 , 230 , 225 , 290 );
trevieze 14:b174ec6e3ca0 202 UG_ButtonSetBackColor (&window_2 ,BTN_ID_2 , C_BLUE ) ;
trevieze 14:b174ec6e3ca0 203 UG_ButtonSetForeColor (&window_2 ,BTN_ID_2 , C_WHITE ) ;
trevieze 14:b174ec6e3ca0 204 UG_ButtonSetBackColor (&window_2 ,BTN_ID_3 , C_BLUE ) ;
trevieze 14:b174ec6e3ca0 205 UG_ButtonSetForeColor (&window_2 ,BTN_ID_3 , C_WHITE ) ;
trevieze 14:b174ec6e3ca0 206 UG_ButtonSetFont (&window_2 , BTN_ID_2 , &FONT_8X8) ;
trevieze 14:b174ec6e3ca0 207 UG_ButtonSetFont (&window_2 , BTN_ID_3 , &FONT_8X8) ;
trevieze 14:b174ec6e3ca0 208 UG_ButtonSetText (&window_2 , BTN_ID_2 , "Prev" );
trevieze 14:b174ec6e3ca0 209 UG_ButtonSetText (&window_2 , BTN_ID_3 , "Next" );
trevieze 15:27e0a1721d13 210 /*Create the image */
trevieze 15:27e0a1721d13 211 //UG_IMAGE image_1;
trevieze 15:27e0a1721d13 212 //UG_ImageCreate(&window_2 ,&image_1 ,IMG_ID_0 ,(UG_WindowGetInnerWidth(&
trevieze 15:27e0a1721d13 213 // window_2)>>1) - (compass.width>>1) ,10 ,0 ,0) ;
trevieze 15:27e0a1721d13 214 //UG_ImageSetBMP(&window_2, IMG_ID_0 ,&compass) ;
trevieze 15:27e0a1721d13 215
trevieze 14:b174ec6e3ca0 216
trevieze 14:b174ec6e3ca0 217 /* Window 3 GSP */
trevieze 14:b174ec6e3ca0 218 UG_WINDOW window_3 ; /* Window */
trevieze 14:b174ec6e3ca0 219 UG_BUTTON button_5; /* Button container */
trevieze 14:b174ec6e3ca0 220 UG_BUTTON button_6; /* Button container */
trevieze 14:b174ec6e3ca0 221 UG_OBJECT obj_buff_wnd_3 [MAX_OBJECTS] ; /* Object buffer */
trevieze 14:b174ec6e3ca0 222 UG_WindowCreate ( &window_3 , obj_buff_wnd_3 , MAX_OBJECTS, window_3_callback);
trevieze 14:b174ec6e3ca0 223 UG_WindowSetTitleTextFont ( &window_3 , &FONT_8X8 ) ;
trevieze 14:b174ec6e3ca0 224 UG_WindowSetTitleText ( &window_3 , "GPS Waypoints" ) ;
trevieze 14:b174ec6e3ca0 225 UG_WindowSetBackColor( &window_3 , C_GRAY ) ;
trevieze 14:b174ec6e3ca0 226 UG_ButtonCreate (&window_3, &button_5, BTN_ID_4, 10 , 230 , 115 , 290 );
trevieze 14:b174ec6e3ca0 227 UG_ButtonCreate (&window_3, &button_6, BTN_ID_5, 125 , 230 , 225 , 290 );
trevieze 14:b174ec6e3ca0 228 UG_ButtonSetBackColor (&window_3 ,BTN_ID_4 , C_BLUE ) ;
trevieze 14:b174ec6e3ca0 229 UG_ButtonSetForeColor (&window_3 ,BTN_ID_4 , C_WHITE ) ;
trevieze 14:b174ec6e3ca0 230 UG_ButtonSetBackColor (&window_3 ,BTN_ID_5 , C_BLUE ) ;
trevieze 14:b174ec6e3ca0 231 UG_ButtonSetForeColor (&window_3 ,BTN_ID_5 , C_WHITE ) ;
trevieze 14:b174ec6e3ca0 232 UG_ButtonSetFont (&window_3 , BTN_ID_4 , &FONT_8X8) ;
trevieze 14:b174ec6e3ca0 233 UG_ButtonSetFont (&window_3 , BTN_ID_5 , &FONT_8X8) ;
trevieze 14:b174ec6e3ca0 234 UG_ButtonSetText (&window_3 , BTN_ID_4 , "Prev" );
trevieze 14:b174ec6e3ca0 235 UG_ButtonSetText (&window_3 , BTN_ID_5 , "Next" );
trevieze 17:4f10efd72d9d 236
trevieze 15:27e0a1721d13 237 while (1) {
trevieze 15:27e0a1721d13 238
trevieze 15:27e0a1721d13 239 cb1();
trevieze 15:27e0a1721d13 240
trevieze 15:27e0a1721d13 241 TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 242 TFT.foreground(White);
trevieze 15:27e0a1721d13 243 TFT.background(UG_WindowGetBackColor(&window_1));
trevieze 15:27e0a1721d13 244 //check if we recieved a new message from GPS, if so, attempt to parse it,
trevieze 7:8aa9cdab4a07 245 if (refresh_Timer.read_ms() >= refresh_Time) {
trevieze 7:8aa9cdab4a07 246 refresh_Timer.reset();
trevieze 15:27e0a1721d13 247
trevieze 15:27e0a1721d13 248 switch ( pageid ) {
trevieze 15:27e0a1721d13 249 case PAGE1: {
trevieze 15:27e0a1721d13 250 if (!pageinit) {
trevieze 15:27e0a1721d13 251 UG_WindowHide(&window_2);
trevieze 15:27e0a1721d13 252 UG_WindowHide(&window_3);
trevieze 15:27e0a1721d13 253 UG_WindowShow(&window_1);
trevieze 15:27e0a1721d13 254 UG_Update();
trevieze 15:27e0a1721d13 255 }
trevieze 15:27e0a1721d13 256 pageinit = 1;
trevieze 15:27e0a1721d13 257 if (bmp180.init() != 0) {
trevieze 15:27e0a1721d13 258 //pc.printf("Error communicating with BMP180\n");
trevieze 15:27e0a1721d13 259 } else {
trevieze 15:27e0a1721d13 260 //pc.printf("Initialized BMP180\n");
trevieze 15:27e0a1721d13 261 bmp180.startTemperature();
trevieze 15:27e0a1721d13 262 wait(0.1); // Wait for conversion to complete
trevieze 15:27e0a1721d13 263 float temp;
trevieze 15:27e0a1721d13 264 if(bmp180.getTemperature(&temp) != 0) {
trevieze 15:27e0a1721d13 265 //pc.printf("Error getting temperature\n");
trevieze 14:b174ec6e3ca0 266 }
trevieze 15:27e0a1721d13 267 TFT.set_font((unsigned char*) Arial12x12);
trevieze 15:27e0a1721d13 268 TFT.locate(10, 65) ;
trevieze 15:27e0a1721d13 269 TFT.printf("Temperature");
trevieze 15:27e0a1721d13 270 TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 271 TFT.locate(10, 80);
trevieze 15:27e0a1721d13 272 TFT.printf("%.1f*", ((temp* 9.0) / 5.0 + 32));
trevieze 15:27e0a1721d13 273 }
trevieze 15:27e0a1721d13 274 int ftemp = humid.sample_ftemp();
trevieze 15:27e0a1721d13 275 int humidity = humid.sample_humid();
trevieze 15:27e0a1721d13 276 TFT.set_font((unsigned char*) Arial12x12);
trevieze 15:27e0a1721d13 277 TFT.locate(150, 65) ;
trevieze 15:27e0a1721d13 278 TFT.printf("Humidity");
trevieze 15:27e0a1721d13 279 TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 280 TFT.locate(150, 80) ;
trevieze 15:27e0a1721d13 281 TFT.printf("%d%%",humidity);
trevieze 15:27e0a1721d13 282 if (MyGPS.dataready()) {
trevieze 15:27e0a1721d13 283 MyGPS.read();
trevieze 15:27e0a1721d13 284 TFT.locate(10, 35) ;
trevieze 15:27e0a1721d13 285 TFT.foreground(UG_WindowGetBackColor(&window_1));
trevieze 15:27e0a1721d13 286 TFT.printf("No GPS Data");
trevieze 15:27e0a1721d13 287 TFT.foreground(White);
trevieze 15:27e0a1721d13 288 TFT.set_font((unsigned char*) Arial12x12);
trevieze 15:27e0a1721d13 289 TFT.locate(12, 25) ;
trevieze 15:27e0a1721d13 290 TFT.printf("Time");
trevieze 15:27e0a1721d13 291 TFT.locate(150, 25) ;
trevieze 15:27e0a1721d13 292 TFT.printf("Date");
trevieze 15:27e0a1721d13 293 TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 294 TFT.locate(10, 40) ;
trevieze 15:27e0a1721d13 295 TFT.printf("%d:%d:%d", MyGPS.buffer.hours, MyGPS.buffer.minutes, MyGPS.buffer.seconds);
trevieze 15:27e0a1721d13 296 TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 297 TFT.locate(150, 40) ;
trevieze 15:27e0a1721d13 298 TFT.printf("%d-%d-%d", MyGPS.buffer.month, MyGPS.buffer.day, MyGPS.buffer.year);
trevieze 15:27e0a1721d13 299 TFT.set_font((unsigned char*) SCProSB31x55);
trevieze 15:27e0a1721d13 300 TFT.locate(125, 180) ;
trevieze 15:27e0a1721d13 301 TFT.printf("%.1f", MyGPS.buffer.speed);
trevieze 15:27e0a1721d13 302 TFT.locate(10, 180);
trevieze 15:27e0a1721d13 303 TFT.printf("%d", 6); //Cadence
trevieze 15:27e0a1721d13 304 TFT.set_font((unsigned char*) Arial12x12);
trevieze 15:27e0a1721d13 305 TFT.locate(45, 212) ;
trevieze 15:27e0a1721d13 306 TFT.printf("rpm");
trevieze 15:27e0a1721d13 307 TFT.locate(10, 170) ;
trevieze 15:27e0a1721d13 308 TFT.printf("Cadence");
trevieze 15:27e0a1721d13 309 TFT.locate(207, 212) ;
trevieze 15:27e0a1721d13 310 TFT.printf("mph");
trevieze 15:27e0a1721d13 311 TFT.locate(125, 170) ;
trevieze 15:27e0a1721d13 312 TFT.printf("Speed");
trevieze 15:27e0a1721d13 313 TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 314 //TFT.locate(10, 50) ;
trevieze 15:27e0a1721d13 315 //double waypoint = nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon)/double(1609.344);
trevieze 15:27e0a1721d13 316 //TFT.printf("%.1fMI From Perry", waypoint);
trevieze 15:27e0a1721d13 317 } else {
trevieze 15:27e0a1721d13 318 TFT.locate(10, 26) ;
trevieze 15:27e0a1721d13 319 TFT.printf("No GPS Data");
trevieze 15:27e0a1721d13 320 //pc.printf("NMEA has no valid data");
trevieze 15:27e0a1721d13 321 }
trevieze 15:27e0a1721d13 322 break;
trevieze 15:27e0a1721d13 323 }
trevieze 15:27e0a1721d13 324 case PAGE2: {
trevieze 15:27e0a1721d13 325 if (!pageinit) {
trevieze 15:27e0a1721d13 326 UG_WindowHide(&window_1);
trevieze 15:27e0a1721d13 327 UG_WindowHide(&window_3);
trevieze 15:27e0a1721d13 328 UG_WindowShow(&window_2);
trevieze 15:27e0a1721d13 329 UG_Update();
trevieze 17:4f10efd72d9d 330 if (imu.read_calib_status() > 0x0) {
trevieze 17:4f10efd72d9d 331 TFT.drawXBitmap(20,35,compass,compass_width,compass_height,C_WHITE);
trevieze 17:4f10efd72d9d 332 float angle = euler_angles.h; // Convert radians to degrees for more a more usual result
trevieze 17:4f10efd72d9d 333 // For the screen -X = up and +X = down and -Y = left and +Y = right, so does not follow coordinate conventions
trevieze 17:4f10efd72d9d 334 float dx = (radius * cos((angle-90)*PI/180)) + centreX; // calculate X position for the screen coordinates - can be confusing!
trevieze 17:4f10efd72d9d 335 float dy = (radius * sin((angle-90)*PI/180)) + centreY; // calculate Y position for the screen coordinates - can be confusing!
trevieze 17:4f10efd72d9d 336 arrow(last_dx,last_dy, centreX, centreY, 2,2,UG_WindowGetBackColor(&window_2)); // Erase last arrow
trevieze 17:4f10efd72d9d 337 arrow(dx,dy, centreX, centreY, 2, 2,C_WHITE); // Draw arrow in new position
trevieze 17:4f10efd72d9d 338 last_dx = dx;
trevieze 17:4f10efd72d9d 339 last_dy = dy;
trevieze 17:4f10efd72d9d 340 }
trevieze 15:27e0a1721d13 341 }
trevieze 15:27e0a1721d13 342 pageinit = 1;
trevieze 15:27e0a1721d13 343 break;
trevieze 15:27e0a1721d13 344 }
trevieze 15:27e0a1721d13 345 case PAGE3: {
trevieze 15:27e0a1721d13 346 if (!pageinit) {
trevieze 15:27e0a1721d13 347 UG_WindowHide(&window_1);
trevieze 15:27e0a1721d13 348 UG_WindowHide(&window_2);
trevieze 15:27e0a1721d13 349 UG_WindowShow(&window_3);
trevieze 15:27e0a1721d13 350 UG_Update();
trevieze 15:27e0a1721d13 351 }
trevieze 15:27e0a1721d13 352 pageinit = 1;
trevieze 15:27e0a1721d13 353 break;
trevieze 15:27e0a1721d13 354 }
trevieze 15:27e0a1721d13 355 }
trevieze 14:b174ec6e3ca0 356 }
trevieze 15:27e0a1721d13 357 /*
trevieze 15:27e0a1721d13 358 TFT.locate(140, 260) ;
trevieze 15:27e0a1721d13 359 TFT.printf("%.1fft", MyGPS.buffer.altitude/0.3048);
trevieze 15:27e0a1721d13 360 TFT.locate(4, 280) ;
trevieze 15:27e0a1721d13 361 int degree;
trevieze 15:27e0a1721d13 362 int minutes;
trevieze 15:27e0a1721d13 363 int seconds;
trevieze 15:27e0a1721d13 364 degree = (int)abs(MyGPS.buffer.longitude);
trevieze 15:27e0a1721d13 365 minutes = (int) ( (abs(MyGPS.buffer.longitude) - (double)degree) * 60.0);
trevieze 15:27e0a1721d13 366 seconds = (int) ( (abs(MyGPS.buffer.longitude) - (double)degree - (double)minutes / 60.0) * 60.0 * 60.0 );
trevieze 15:27e0a1721d13 367 TFT.printf("%d %d' %d\" %c lon", degree, minutes,seconds, MyGPS.buffer.lonc);
trevieze 15:27e0a1721d13 368 TFT.locate(4, 300) ;
trevieze 15:27e0a1721d13 369 TFT.locate(4, 300) ;
trevieze 15:27e0a1721d13 370 degree = (int)abs(MyGPS.buffer.latitude);
trevieze 15:27e0a1721d13 371 minutes = (int) ( (abs(MyGPS.buffer.latitude) - (double)degree) * 60.0);
trevieze 15:27e0a1721d13 372 seconds = (int) ( (abs(MyGPS.buffer.latitude) - (double)degree - (double)minutes / 60.0) * 60.0 * 60.0 );
trevieze 15:27e0a1721d13 373 TFT.printf("%d %d' %d\" %c lat", degree, minutes,seconds, MyGPS.buffer.latc);
trevieze 15:27e0a1721d13 374
trevieze 15:27e0a1721d13 375
trevieze 15:27e0a1721d13 376
trevieze 15:27e0a1721d13 377 //pc.printf("Dist to Perry %.4f ", nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon));
trevieze 15:27e0a1721d13 378
trevieze 15:27e0a1721d13 379
trevieze 15:27e0a1721d13 380 }
trevieze 15:27e0a1721d13 381
trevieze 15:27e0a1721d13 382
trevieze 15:27e0a1721d13 383 if (imu.chip_ready() == 0){
trevieze 15:27e0a1721d13 384 pc.printf("Bosch BNO055 is NOT avirable!!\r\n");
trevieze 15:27e0a1721d13 385 } else {
trevieze 15:27e0a1721d13 386
trevieze 15:27e0a1721d13 387 if (imu.read_calib_status() > 0x0){
trevieze 15:27e0a1721d13 388 TFT.foreground(White);
trevieze 15:27e0a1721d13 389 TFT.locate(4, 260) ;
trevieze 15:27e0a1721d13 390 TFT.printf("No Data");
trevieze 15:27e0a1721d13 391 TFT.foreground(Blue);
trevieze 15:27e0a1721d13 392 imu.get_Euler_Angles(&euler_angles);
trevieze 15:27e0a1721d13 393 TFT.locate(4, 260) ;
trevieze 15:27e0a1721d13 394 TFT.printf("%.1f @ %.1f",euler_angles.h, euler_angles.p);
trevieze 15:27e0a1721d13 395 //pc.printf("H %d",(int)euler_angles.h);
trevieze 15:27e0a1721d13 396 //pc.printf("R %.1f",euler_angles.r);
trevieze 15:27e0a1721d13 397 //pc.printf("P %.1f",euler_angles.p);
trevieze 15:27e0a1721d13 398
trevieze 15:27e0a1721d13 399 } else {
trevieze 15:27e0a1721d13 400 TFT.locate(4, 260) ;
trevieze 15:27e0a1721d13 401 TFT.printf("No Data");
trevieze 15:27e0a1721d13 402 }
trevieze 15:27e0a1721d13 403 }
trevieze 15:27e0a1721d13 404
trevieze 17:4f10efd72d9d 405
trevieze 15:27e0a1721d13 406
trevieze 15:27e0a1721d13 407
trevieze 15:27e0a1721d13 408 }
trevieze 15:27e0a1721d13 409 */
trevieze 15:27e0a1721d13 410 }
trevieze 10:869a102dd31c 411 }
trevieze 10:869a102dd31c 412
trevieze 15:27e0a1721d13 413 void arrow(int x2, int y2, int x1, int y1, int alength, int awidth, int colour)
trevieze 15:27e0a1721d13 414 {
trevieze 15:27e0a1721d13 415 float distance;
trevieze 15:27e0a1721d13 416 int dx, dy, x2o,y2o,x3,y3,x4,y4,k;
trevieze 15:27e0a1721d13 417 distance = sqrt(pow((double)(x1 - x2),2) + pow((double)(y1 - y2), 2));
trevieze 15:27e0a1721d13 418 dx = x2 + (x1 - x2) * alength / distance;
trevieze 15:27e0a1721d13 419 dy = y2 + (y1 - y2) * alength / distance;
trevieze 15:27e0a1721d13 420 k = awidth / alength;
trevieze 15:27e0a1721d13 421 x2o = x2 - dx;
trevieze 15:27e0a1721d13 422 y2o = dy - y2;
trevieze 15:27e0a1721d13 423 x3 = y2o * k + dx;
trevieze 15:27e0a1721d13 424 y3 = x2o * k + dy;
trevieze 15:27e0a1721d13 425 x4 = dx - y2o * k;
trevieze 15:27e0a1721d13 426 y4 = dy - x2o * k;
trevieze 15:27e0a1721d13 427 TFT.line(x1, y1, x2, y2, colour);
trevieze 15:27e0a1721d13 428 TFT.line(x1, y1, dx, dy, colour);
trevieze 15:27e0a1721d13 429 TFT.line(x3, y3, x4, y4, colour);
trevieze 15:27e0a1721d13 430 TFT.line(x3, y3, x2, y2, colour);
trevieze 15:27e0a1721d13 431 TFT.line(x2, y2, x4, y4, colour);
trevieze 12:1a9c0f9d7128 432 TFT.set_font((unsigned char*) Arial12x12);
trevieze 15:27e0a1721d13 433 TFT.foreground(Blue);
trevieze 15:27e0a1721d13 434 TFT.background(White);
trevieze 17:4f10efd72d9d 435 //TFT.locate((centreX-2),(centreY-24));
trevieze 17:4f10efd72d9d 436 //TFT.printf("N");
trevieze 17:4f10efd72d9d 437 //TFT.locate((centreX-2),(centreY+17));
trevieze 17:4f10efd72d9d 438 //TFT.printf("S");
trevieze 17:4f10efd72d9d 439 //TFT.locate((centreX+19),(centreY-3));
trevieze 17:4f10efd72d9d 440 //TFT.printf("E");
trevieze 17:4f10efd72d9d 441 //TFT.locate((centreX-23),(centreY-3));
trevieze 17:4f10efd72d9d 442 //TFT.printf("W");
trevieze 17:4f10efd72d9d 443 //TFT.set_font((unsigned char*) ArialR20x20);
trevieze 15:27e0a1721d13 444 }
Rhyme 0:cd5e3d371b54 445
trevieze 15:27e0a1721d13 446 void Draw_Compass_Rose(void)
trevieze 15:27e0a1721d13 447 {
trevieze 15:27e0a1721d13 448 int dxo, dyo, dxi, dyi;
trevieze 15:27e0a1721d13 449 TFT.circle(centreX,centreY,radius,Blue); // Draw compass circle
trevieze 15:27e0a1721d13 450 for (float i = 0; i <360; i = i + 22.5) {
trevieze 15:27e0a1721d13 451 dxo = radius * cos(i*3.14/180);
trevieze 15:27e0a1721d13 452 dyo = radius * sin(i*3.14/180);
trevieze 15:27e0a1721d13 453 dxi = dxo * 0.95;
trevieze 15:27e0a1721d13 454 dyi = dyo * 0.95;
trevieze 15:27e0a1721d13 455 TFT.line(dxi+centreX,dyi+centreY,dxo+centreX,dyo+centreY,Blue);
trevieze 15:27e0a1721d13 456 }
trevieze 10:869a102dd31c 457 TFT.set_font((unsigned char*) Arial12x12);
trevieze 15:27e0a1721d13 458 TFT.foreground(Blue);
trevieze 15:27e0a1721d13 459 TFT.background(White);
trevieze 10:869a102dd31c 460 TFT.locate((centreX-2),(centreY-24));
trevieze 15:27e0a1721d13 461 TFT.printf("N");
trevieze 15:27e0a1721d13 462 TFT.locate((centreX-2),(centreY+17));
trevieze 15:27e0a1721d13 463 TFT.printf("S");
trevieze 15:27e0a1721d13 464 TFT.locate((centreX+19),(centreY-3));
trevieze 15:27e0a1721d13 465 TFT.printf("E");
trevieze 15:27e0a1721d13 466 TFT.locate((centreX-23),(centreY-3));
trevieze 15:27e0a1721d13 467 TFT.printf("W");
trevieze 14:b174ec6e3ca0 468 }
trevieze 14:b174ec6e3ca0 469
trevieze 14:b174ec6e3ca0 470 void ili9341_pset(UG_S16 ul_x,UG_S16 ul_y, UG_COLOR ul_color)
trevieze 14:b174ec6e3ca0 471 {
trevieze 14:b174ec6e3ca0 472 TFT.pixel(ul_x, ul_y, ul_color);
trevieze 14:b174ec6e3ca0 473 }
trevieze 14:b174ec6e3ca0 474
trevieze 14:b174ec6e3ca0 475 void window_1_callback( UG_MESSAGE* msg )
trevieze 14:b174ec6e3ca0 476 {
trevieze 15:27e0a1721d13 477 if ( msg->type == MSG_TYPE_OBJECT ) {
trevieze 15:27e0a1721d13 478 if ( msg->id == OBJ_TYPE_BUTTON ) {
trevieze 15:27e0a1721d13 479 switch ( msg->sub_id ) {
trevieze 15:27e0a1721d13 480 case BTN_ID_0: {
trevieze 14:b174ec6e3ca0 481 pageid--;
trevieze 14:b174ec6e3ca0 482 if (pageid < 1) {
trevieze 15:27e0a1721d13 483 pageid = 3;
trevieze 15:27e0a1721d13 484 }
trevieze 15:27e0a1721d13 485 pageinit = 0;
trevieze 14:b174ec6e3ca0 486 break;
trevieze 14:b174ec6e3ca0 487 }
trevieze 15:27e0a1721d13 488 case BTN_ID_1: {
trevieze 14:b174ec6e3ca0 489 pageid++;
trevieze 14:b174ec6e3ca0 490 if (pageid > 3) {
trevieze 15:27e0a1721d13 491 pageid = 1;
trevieze 15:27e0a1721d13 492 }
trevieze 15:27e0a1721d13 493 pageinit = 0;
trevieze 14:b174ec6e3ca0 494 break;
trevieze 14:b174ec6e3ca0 495 }
trevieze 14:b174ec6e3ca0 496 }
trevieze 14:b174ec6e3ca0 497 }
trevieze 14:b174ec6e3ca0 498 }
trevieze 14:b174ec6e3ca0 499 }
trevieze 14:b174ec6e3ca0 500
trevieze 14:b174ec6e3ca0 501 void window_2_callback( UG_MESSAGE* msg )
trevieze 14:b174ec6e3ca0 502 {
trevieze 15:27e0a1721d13 503 if ( msg->type == MSG_TYPE_OBJECT ) {
trevieze 15:27e0a1721d13 504 if ( msg->id == OBJ_TYPE_BUTTON ) {
trevieze 15:27e0a1721d13 505 switch ( msg->sub_id ) {
trevieze 15:27e0a1721d13 506 case BTN_ID_2: {
trevieze 14:b174ec6e3ca0 507 pageid--;
trevieze 14:b174ec6e3ca0 508 if (pageid < 1) {
trevieze 15:27e0a1721d13 509 pageid = 3;
trevieze 15:27e0a1721d13 510 }
trevieze 15:27e0a1721d13 511 pageinit = 0;
trevieze 14:b174ec6e3ca0 512 break;
trevieze 14:b174ec6e3ca0 513 }
trevieze 15:27e0a1721d13 514 case BTN_ID_3: {
trevieze 14:b174ec6e3ca0 515 pageid++;
trevieze 14:b174ec6e3ca0 516 if (pageid > 3) {
trevieze 15:27e0a1721d13 517 pageid = 1;
trevieze 14:b174ec6e3ca0 518 }
trevieze 15:27e0a1721d13 519 pageinit = 0;
trevieze 14:b174ec6e3ca0 520 break;
trevieze 14:b174ec6e3ca0 521 }
trevieze 14:b174ec6e3ca0 522 }
trevieze 14:b174ec6e3ca0 523 }
trevieze 14:b174ec6e3ca0 524 }
trevieze 14:b174ec6e3ca0 525 }
trevieze 14:b174ec6e3ca0 526
trevieze 14:b174ec6e3ca0 527 void window_3_callback( UG_MESSAGE* msg )
trevieze 14:b174ec6e3ca0 528 {
trevieze 15:27e0a1721d13 529 if ( msg->type == MSG_TYPE_OBJECT ) {
trevieze 15:27e0a1721d13 530 if ( msg->id == OBJ_TYPE_BUTTON ) {
trevieze 15:27e0a1721d13 531 switch ( msg->sub_id ) {
trevieze 15:27e0a1721d13 532 case BTN_ID_4: {
trevieze 14:b174ec6e3ca0 533 pageid--;
trevieze 14:b174ec6e3ca0 534 if (pageid < 1) {
trevieze 15:27e0a1721d13 535 pageid = 3;
trevieze 15:27e0a1721d13 536 }
trevieze 15:27e0a1721d13 537 pageinit = 0;
trevieze 14:b174ec6e3ca0 538 break;
trevieze 14:b174ec6e3ca0 539 }
trevieze 15:27e0a1721d13 540 case BTN_ID_5: {
trevieze 14:b174ec6e3ca0 541 pageid++;
trevieze 14:b174ec6e3ca0 542 if (pageid > 3) {
trevieze 15:27e0a1721d13 543 pageid = 1;
trevieze 14:b174ec6e3ca0 544 }
trevieze 15:27e0a1721d13 545 pageinit = 0;
trevieze 14:b174ec6e3ca0 546 break;
trevieze 14:b174ec6e3ca0 547 }
trevieze 14:b174ec6e3ca0 548 }
trevieze 14:b174ec6e3ca0 549 }
trevieze 14:b174ec6e3ca0 550 }
trevieze 14:b174ec6e3ca0 551 }
trevieze 14:b174ec6e3ca0 552
trevieze 15:27e0a1721d13 553 void cb1(void)
trevieze 15:27e0a1721d13 554 {
trevieze 14:b174ec6e3ca0 555 point p;
trevieze 14:b174ec6e3ca0 556 TSC.getTouch(p);
trevieze 15:27e0a1721d13 557 if (p.z > __PRESURE) {
trevieze 15:27e0a1721d13 558 UG_TouchUpdate ( p.x, p.y, TOUCH_STATE_PRESSED ) ;
trevieze 15:27e0a1721d13 559 } else {
trevieze 15:27e0a1721d13 560 UG_TouchUpdate (-1, -1, TOUCH_STATE_RELEASED ) ;
trevieze 15:27e0a1721d13 561 }
trevieze 14:b174ec6e3ca0 562 UG_Update();
trevieze 14:b174ec6e3ca0 563 }