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:
Wed May 16 13:25:59 2018 +0000
Revision:
20:3ada4387cc1b
Parent:
18:50520438c129
Child:
21:39ef2fd5c4bf
Commit 5/26/2018 No changes that I am aware of.

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