Works

Dependencies:   BMP180 BNO055_fusion Fonts GPSISR HTU21D SDFileSystem UniGraphic mbed uGUI

Fork of Bicycl_Computer_NUCLEO-F411RE by Darren Ulrich

Committer:
trevieze
Date:
Fri May 25 14:25:01 2018 +0000
Revision:
16:e81bd672196b
Parent:
15:b174ec6e3ca0
Works

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