This program test a Gauge bult in FT81x for Automotive SunTrip COmputer -- project undone
Dependencies: DS1820 FT800_3 mbed
main.cpp@0:96d8c18a9fad, 2016-07-09 (annotated)
- Committer:
- SunRiver
- Date:
- Sat Jul 09 15:44:47 2016 +0000
- Revision:
- 0:96d8c18a9fad
no
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SunRiver | 0:96d8c18a9fad | 1 | /* Demo for mbed Library for FTDI FT800 Enbedded Video Engine "EVE" |
SunRiver | 0:96d8c18a9fad | 2 | * by Peter Drescher, DC2PD 2014 |
SunRiver | 0:96d8c18a9fad | 3 | * Released under the MIT License: http://mbed.org/license/mit */ |
SunRiver | 0:96d8c18a9fad | 4 | |
SunRiver | 0:96d8c18a9fad | 5 | #include "mbed.h" |
SunRiver | 0:96d8c18a9fad | 6 | #include "FT_Platform.h" |
SunRiver | 0:96d8c18a9fad | 7 | #include "FT_color.h" |
SunRiver | 0:96d8c18a9fad | 8 | #include "stdio.h" |
SunRiver | 0:96d8c18a9fad | 9 | #include "float.h" |
SunRiver | 0:96d8c18a9fad | 10 | #include "DS1820.h" |
SunRiver | 0:96d8c18a9fad | 11 | |
SunRiver | 0:96d8c18a9fad | 12 | //#include "SDFileSystem.h" |
SunRiver | 0:96d8c18a9fad | 13 | |
SunRiver | 0:96d8c18a9fad | 14 | |
SunRiver | 0:96d8c18a9fad | 15 | #define SAMAPP_DELAY_BTW_APIS (1000) |
SunRiver | 0:96d8c18a9fad | 16 | #define SAMAPP_ENABLE_DELAY() Ft_Gpu_Hal_Sleep(SAMAPP_DELAY_BTW_APIS) |
SunRiver | 0:96d8c18a9fad | 17 | #define SAMAPP_ENABLE_DELAY_VALUE(x) Ft_Gpu_Hal_Sleep(x) |
SunRiver | 0:96d8c18a9fad | 18 | #define DATA_PIN A1 |
SunRiver | 0:96d8c18a9fad | 19 | FT800 TFT(D11,D12,D13,D9,D8,D14); |
SunRiver | 0:96d8c18a9fad | 20 | |
SunRiver | 0:96d8c18a9fad | 21 | |
SunRiver | 0:96d8c18a9fad | 22 | |
SunRiver | 0:96d8c18a9fad | 23 | |
SunRiver | 0:96d8c18a9fad | 24 | |
SunRiver | 0:96d8c18a9fad | 25 | // global Vars |
SunRiver | 0:96d8c18a9fad | 26 | unsigned int r,b,g; |
SunRiver | 0:96d8c18a9fad | 27 | char buffer[50]; |
SunRiver | 0:96d8c18a9fad | 28 | Ticker tick; |
SunRiver | 0:96d8c18a9fad | 29 | unsigned int color = 0,bright = 0; |
SunRiver | 0:96d8c18a9fad | 30 | |
SunRiver | 0:96d8c18a9fad | 31 | |
SunRiver | 0:96d8c18a9fad | 32 | |
SunRiver | 0:96d8c18a9fad | 33 | Serial usart(D1, D0); |
SunRiver | 0:96d8c18a9fad | 34 | DS1820 probe(DATA_PIN); |
SunRiver | 0:96d8c18a9fad | 35 | |
SunRiver | 0:96d8c18a9fad | 36 | // function to convert hue , saturation and value to RGB |
SunRiver | 0:96d8c18a9fad | 37 | // see http://en.wikipedia.org/wiki/HSL_and_HSV |
SunRiver | 0:96d8c18a9fad | 38 | |
SunRiver | 0:96d8c18a9fad | 39 | void hsv2rgb(double H,double S, double V) |
SunRiver | 0:96d8c18a9fad | 40 | { |
SunRiver | 0:96d8c18a9fad | 41 | double f,h,p,q,t; |
SunRiver | 0:96d8c18a9fad | 42 | int i; |
SunRiver | 0:96d8c18a9fad | 43 | if( S == 0.0) { |
SunRiver | 0:96d8c18a9fad | 44 | r = V * 255; |
SunRiver | 0:96d8c18a9fad | 45 | g = V * 255; |
SunRiver | 0:96d8c18a9fad | 46 | b = V * 255; |
SunRiver | 0:96d8c18a9fad | 47 | return; |
SunRiver | 0:96d8c18a9fad | 48 | } |
SunRiver | 0:96d8c18a9fad | 49 | if(H > 480.0) H = 0.0; // check values |
SunRiver | 0:96d8c18a9fad | 50 | if(S > 1.0) S = 1.0; |
SunRiver | 0:96d8c18a9fad | 51 | if(S < 0.0) S = 0.0; |
SunRiver | 0:96d8c18a9fad | 52 | if(V > 1.0) V = 1.0; |
SunRiver | 0:96d8c18a9fad | 53 | if(V < 0.0) V = 0.0; |
SunRiver | 0:96d8c18a9fad | 54 | |
SunRiver | 0:96d8c18a9fad | 55 | h = H / 60.0; |
SunRiver | 0:96d8c18a9fad | 56 | i = (int) h; |
SunRiver | 0:96d8c18a9fad | 57 | f = h - i; |
SunRiver | 0:96d8c18a9fad | 58 | p = V * (1.0 - S); |
SunRiver | 0:96d8c18a9fad | 59 | q = V * (1.0 - (S * f)); |
SunRiver | 0:96d8c18a9fad | 60 | t = V * (1.0 - (S * (1.0 - f))); |
SunRiver | 0:96d8c18a9fad | 61 | |
SunRiver | 0:96d8c18a9fad | 62 | switch(i) { |
SunRiver | 0:96d8c18a9fad | 63 | case 0: |
SunRiver | 0:96d8c18a9fad | 64 | r = V * 255; |
SunRiver | 0:96d8c18a9fad | 65 | g = t * 255; |
SunRiver | 0:96d8c18a9fad | 66 | b = p * 255; |
SunRiver | 0:96d8c18a9fad | 67 | break; |
SunRiver | 0:96d8c18a9fad | 68 | case 1: |
SunRiver | 0:96d8c18a9fad | 69 | r = q * 255; |
SunRiver | 0:96d8c18a9fad | 70 | g = V * 255; |
SunRiver | 0:96d8c18a9fad | 71 | b = p * 255; |
SunRiver | 0:96d8c18a9fad | 72 | break; |
SunRiver | 0:96d8c18a9fad | 73 | case 2: |
SunRiver | 0:96d8c18a9fad | 74 | r = p * 255; |
SunRiver | 0:96d8c18a9fad | 75 | g = V * 255; |
SunRiver | 0:96d8c18a9fad | 76 | b = t * 255; |
SunRiver | 0:96d8c18a9fad | 77 | break; |
SunRiver | 0:96d8c18a9fad | 78 | case 3: |
SunRiver | 0:96d8c18a9fad | 79 | r = p * 255; |
SunRiver | 0:96d8c18a9fad | 80 | g = q * 255; |
SunRiver | 0:96d8c18a9fad | 81 | b = V * 255; |
SunRiver | 0:96d8c18a9fad | 82 | break; |
SunRiver | 0:96d8c18a9fad | 83 | case 4: |
SunRiver | 0:96d8c18a9fad | 84 | r = t * 255; |
SunRiver | 0:96d8c18a9fad | 85 | g = p * 255; |
SunRiver | 0:96d8c18a9fad | 86 | b = V * 255; |
SunRiver | 0:96d8c18a9fad | 87 | break; |
SunRiver | 0:96d8c18a9fad | 88 | case 5: |
SunRiver | 0:96d8c18a9fad | 89 | default: |
SunRiver | 0:96d8c18a9fad | 90 | r = V * 255; |
SunRiver | 0:96d8c18a9fad | 91 | g = p * 255; |
SunRiver | 0:96d8c18a9fad | 92 | b = q * 255; |
SunRiver | 0:96d8c18a9fad | 93 | break; |
SunRiver | 0:96d8c18a9fad | 94 | } |
SunRiver | 0:96d8c18a9fad | 95 | } |
SunRiver | 0:96d8c18a9fad | 96 | |
SunRiver | 0:96d8c18a9fad | 97 | |
SunRiver | 0:96d8c18a9fad | 98 | /***************************************************************************/ |
SunRiver | 0:96d8c18a9fad | 99 | // Rysowanie ekranu demonstracyjnego |
SunRiver | 0:96d8c18a9fad | 100 | /***************************************************************************/ |
SunRiver | 0:96d8c18a9fad | 101 | |
SunRiver | 0:96d8c18a9fad | 102 | ft_void_t Trip_Comp(ft_char8_t *str, ft_float_t temp) |
SunRiver | 0:96d8c18a9fad | 103 | { |
SunRiver | 0:96d8c18a9fad | 104 | //const char* str2 = "FT81x EVE2 FRDM-K64F"; |
SunRiver | 0:96d8c18a9fad | 105 | TFT.DLstart(); // przygotowanie na nową listę nkomend |
SunRiver | 0:96d8c18a9fad | 106 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // kolor tła (biały) |
SunRiver | 0:96d8c18a9fad | 107 | TFT.DL(CLEAR(1,1,1)); // czyszczenie buforów --> color, stencil, tag |
SunRiver | 0:96d8c18a9fad | 108 | |
SunRiver | 0:96d8c18a9fad | 109 | |
SunRiver | 0:96d8c18a9fad | 110 | |
SunRiver | 0:96d8c18a9fad | 111 | TFT.Button(580, 440, 67, 27, 27, OPT_FLAT, "MENU"); |
SunRiver | 0:96d8c18a9fad | 112 | TFT.Button(650, 440, 67, 27, 27, OPT_FLAT | OPT_CENTER, "INFO"); |
SunRiver | 0:96d8c18a9fad | 113 | TFT.Button(720, 440, 67, 27, 27, OPT_FLAT, "GUIDE"); |
SunRiver | 0:96d8c18a9fad | 114 | |
SunRiver | 0:96d8c18a9fad | 115 | //--------------opisy ekranu |
SunRiver | 0:96d8c18a9fad | 116 | TFT.DL(COLOR_RGB(0, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 117 | TFT.Text(400, 180, 28, OPT_CENTER, "KM/H"); |
SunRiver | 0:96d8c18a9fad | 118 | TFT.Text(120, 119, 28, OPT_CENTER, "RPM /1000"); |
SunRiver | 0:96d8c18a9fad | 119 | TFT.Text(680, 330, 28, OPT_CENTER, "Temp"); |
SunRiver | 0:96d8c18a9fad | 120 | |
SunRiver | 0:96d8c18a9fad | 121 | //TFT.Text(378, 154, 27, OPT_CENTER, "KM:"); |
SunRiver | 0:96d8c18a9fad | 122 | TFT.Text(680, 119, 28, OPT_CENTER, "Fuel"); |
SunRiver | 0:96d8c18a9fad | 123 | TFT.Text(400, 30, 30, OPT_CENTER, str); |
SunRiver | 0:96d8c18a9fad | 124 | |
SunRiver | 0:96d8c18a9fad | 125 | TFT.DL(COLOR_RGB(255, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 126 | TFT.Text(400, 440, 27, OPT_CENTER, "ENGINE OFF"); |
SunRiver | 0:96d8c18a9fad | 127 | TFT.DL(COLOR_RGB(0, 255, 0)); |
SunRiver | 0:96d8c18a9fad | 128 | TFT.Text(400, 420, 27, OPT_CENTER, "LIGHT: ON"); |
SunRiver | 0:96d8c18a9fad | 129 | |
SunRiver | 0:96d8c18a9fad | 130 | //GAUGE_0 = OPT_NOBACK | OPT_NOPOINTER; |
SunRiver | 0:96d8c18a9fad | 131 | //GAUGE_1 = OPT_NOBACK | OPT_NOTICKS; |
SunRiver | 0:96d8c18a9fad | 132 | |
SunRiver | 0:96d8c18a9fad | 133 | //--------------prędkosciomierz |
SunRiver | 0:96d8c18a9fad | 134 | TFT.DL(COLOR_RGB(0, 0, 255)); |
SunRiver | 0:96d8c18a9fad | 135 | TFT.Gauge((TFT.DispWidth/2), TFT.DispHeight/2, 208, OPT_NOBACK | OPT_NOPOINTER, 10, 10, 0, 250); |
SunRiver | 0:96d8c18a9fad | 136 | TFT.DL(COLOR_RGB(255, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 137 | TFT.Gauge((TFT.DispWidth/2), TFT.DispHeight/2, 208, OPT_NOBACK | OPT_NOTICKS, 10, 10, 0 , 250); |
SunRiver | 0:96d8c18a9fad | 138 | TFT.Number(400, 370, 31, OPT_CENTER, 0); |
SunRiver | 0:96d8c18a9fad | 139 | |
SunRiver | 0:96d8c18a9fad | 140 | //--------------zegarek |
SunRiver | 0:96d8c18a9fad | 141 | TFT.DL(COLOR_RGB(0, 0, 255)); |
SunRiver | 0:96d8c18a9fad | 142 | TFT.Clock(130, 350, 100, OPT_NOBACK | OPT_NOPOINTER | OPT_NOSECS, 19, 51, 17, 0); |
SunRiver | 0:96d8c18a9fad | 143 | TFT.DL(COLOR_RGB(255, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 144 | TFT.Clock(130, 350, 100, OPT_NOBACK | OPT_NOTICKS, 19, 51, 17, 0); |
SunRiver | 0:96d8c18a9fad | 145 | |
SunRiver | 0:96d8c18a9fad | 146 | |
SunRiver | 0:96d8c18a9fad | 147 | //-------------- RPM |
SunRiver | 0:96d8c18a9fad | 148 | TFT.DL(COLOR_RGB(0, 0, 255)); |
SunRiver | 0:96d8c18a9fad | 149 | TFT.Gauge(120, 150, 130, OPT_NOBACK | OPT_NOPOINTER, 8, 5, 0, 100); |
SunRiver | 0:96d8c18a9fad | 150 | TFT.DL(COLOR_RGB(255, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 151 | TFT.Gauge(120, 150, 130, OPT_NOBACK | OPT_NOTICKS, 8, 5, 0, 100); |
SunRiver | 0:96d8c18a9fad | 152 | TFT.DL(COLOR_RGB(0, 255, 0)); |
SunRiver | 0:96d8c18a9fad | 153 | TFT.Number(120, 220, 31, OPT_CENTER, 0); |
SunRiver | 0:96d8c18a9fad | 154 | |
SunRiver | 0:96d8c18a9fad | 155 | //-------------- FUELL |
SunRiver | 0:96d8c18a9fad | 156 | TFT.DL(COLOR_RGB(0, 0, 255)); |
SunRiver | 0:96d8c18a9fad | 157 | TFT.Gauge(680, 150, 130, OPT_NOBACK | OPT_NOPOINTER, 4, 5, 40, 100); |
SunRiver | 0:96d8c18a9fad | 158 | TFT.DL(COLOR_RGB(255, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 159 | TFT.Gauge(680, 150, 130, OPT_NOBACK | OPT_NOTICKS, 4, 5, 35, 100); |
SunRiver | 0:96d8c18a9fad | 160 | |
SunRiver | 0:96d8c18a9fad | 161 | TFT.DL(COLOR_RGB(0, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 162 | //TFT.Text(15, 257, 16, 0, str); |
SunRiver | 0:96d8c18a9fad | 163 | |
SunRiver | 0:96d8c18a9fad | 164 | |
SunRiver | 0:96d8c18a9fad | 165 | |
SunRiver | 0:96d8c18a9fad | 166 | //------------- TEmperatura |
SunRiver | 0:96d8c18a9fad | 167 | TFT.DL(COLOR_RGB(0, 0, 255)); |
SunRiver | 0:96d8c18a9fad | 168 | TFT.Gauge(680, 350, 100, OPT_NOBACK | OPT_NOPOINTER, 4, 5, 40, 125); |
SunRiver | 0:96d8c18a9fad | 169 | TFT.DL(COLOR_RGB(255, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 170 | TFT.Gauge(680, 350, 100, OPT_NOBACK | OPT_NOTICKS, 4, 5, temp, 125); |
SunRiver | 0:96d8c18a9fad | 171 | |
SunRiver | 0:96d8c18a9fad | 172 | TFT.DL(COLOR_RGB(0, 0, 0)); |
SunRiver | 0:96d8c18a9fad | 173 | TFT.Number(680, 400, 31, OPT_CENTER, temp); |
SunRiver | 0:96d8c18a9fad | 174 | |
SunRiver | 0:96d8c18a9fad | 175 | |
SunRiver | 0:96d8c18a9fad | 176 | |
SunRiver | 0:96d8c18a9fad | 177 | TFT.DL(DISPLAY()); // Wyswietlamy przygotowany screen |
SunRiver | 0:96d8c18a9fad | 178 | TFT.Swap(); |
SunRiver | 0:96d8c18a9fad | 179 | TFT.Flush_Co_Buffer(); // pobieramy komendy z FiFo |
SunRiver | 0:96d8c18a9fad | 180 | |
SunRiver | 0:96d8c18a9fad | 181 | TFT.WaitCmdfifo_empty(); // czekanie na zakończenie operacji |
SunRiver | 0:96d8c18a9fad | 182 | TFT.Sleep(5000); // koniec wyswietlania (15000 = 15sec) |
SunRiver | 0:96d8c18a9fad | 183 | } |
SunRiver | 0:96d8c18a9fad | 184 | |
SunRiver | 0:96d8c18a9fad | 185 | |
SunRiver | 0:96d8c18a9fad | 186 | |
SunRiver | 0:96d8c18a9fad | 187 | |
SunRiver | 0:96d8c18a9fad | 188 | int main() |
SunRiver | 0:96d8c18a9fad | 189 | { |
SunRiver | 0:96d8c18a9fad | 190 | |
SunRiver | 0:96d8c18a9fad | 191 | |
SunRiver | 0:96d8c18a9fad | 192 | usart.baud(38400); |
SunRiver | 0:96d8c18a9fad | 193 | TFT.Flush_Co_Buffer(); |
SunRiver | 0:96d8c18a9fad | 194 | TFT.WaitCmdfifo_empty(); |
SunRiver | 0:96d8c18a9fad | 195 | |
SunRiver | 0:96d8c18a9fad | 196 | |
SunRiver | 0:96d8c18a9fad | 197 | |
SunRiver | 0:96d8c18a9fad | 198 | while(1) |
SunRiver | 0:96d8c18a9fad | 199 | { |
SunRiver | 0:96d8c18a9fad | 200 | probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
SunRiver | 0:96d8c18a9fad | 201 | usart.printf("Temperatura to %3.3f Celsiusza\r\n", probe.temperature()); |
SunRiver | 0:96d8c18a9fad | 202 | Trip_Comp("SunTRIP Computer", probe.temperature()); |
SunRiver | 0:96d8c18a9fad | 203 | |
SunRiver | 0:96d8c18a9fad | 204 | //Demo_Screen2("Temperatura", probe.temperature()); |
SunRiver | 0:96d8c18a9fad | 205 | // wait(1); |
SunRiver | 0:96d8c18a9fad | 206 | } |
SunRiver | 0:96d8c18a9fad | 207 | |
SunRiver | 0:96d8c18a9fad | 208 | |
SunRiver | 0:96d8c18a9fad | 209 | } |
SunRiver | 0:96d8c18a9fad | 210 | |
SunRiver | 0:96d8c18a9fad | 211 | |
SunRiver | 0:96d8c18a9fad | 212 |