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 Aug 04 19:54:48 2017 +0000
Revision:
18:50520438c129
Parent:
15:27e0a1721d13
Child:
20:3ada4387cc1b
Compass is now functioning. With the help of brilliant real software engineers I was able to rescue this program. Thanks everyone!

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