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 18:50:19 2018 +0000
Revision:
21:39ef2fd5c4bf
Parent:
20:3ada4387cc1b
Child:
22:39a8e5c47f3c
Adding averaging to touchscreen analog data. See if it functions better.

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