x

Dependencies:   AP3000 ARM_RTC Beep BurstSPI FRAMSPI FT813 I2CEEBlockDevice I2CList MCP79412 NMEA0183 PCA9745B SDBlockDevice SPIFBlockDevice SystemClock WDT nmea_parser

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 // string::substr
00003 //#include <iostream>
00004 //#include <string>
00005 
00006 #include "main.h"
00007 
00008 #include "AP3000.h"
00009 #include "SetupPage.h"
00010 
00011 // https://github.com/ARMmbed/sd-driver
00012 // https://github.com/ARMmbed/mbed-os-example-fat-filesystem/blob/master/main.cpp
00013 // https://github.com/RudolphRiedel/FT800-FT813
00014 // https://github.com/RudolphRiedel/FT800-FT813/blob/master/FT8_commands.c
00015 // https://os.mbed.com/components/EVE-FT800/
00016 // https://os.mbed.com/users/dreschpe/code/FT800_2/file/16e22c789f7d/FT_CoPro_Cmds.cpp/
00017 // https://os.mbed.com/users/dreschpe/code/FT800_RGB_demo2/
00018 // https://os.mbed.com/users/dreschpe/code/FT800_RGB_demo2/docs/tip/main_8cpp_source.html
00019 // https://os.mbed.com/users/dreschpe/code/FT800_2/file/16e22c789f7d/FT_CoPro_Cmds.cpp/
00020 // https://os.mbed.com/users/dreschpe/code/FT800_JPG/
00021 // https://os.mbed.com/users/dreschpe/code/FT800_JPG/file/c603024cbd1d/main.cpp/
00022 // https://os.mbed.com/users/cpm219/code/FT810/rev/2d0ef4830603/
00023 // https://os.mbed.com/users/davidchilds/code/FT810_RGB_demo/file/7a29cc1298ef/main.cpp/
00024 // https://os.mbed.com/users/mozillain/code/FT810/
00025 // https://os.mbed.com/teams/The-Best/code/FT800_3/rev/a69ac4d39afd/
00026 // https://www.mikrocontroller.net/topic/395608
00027 // https://os.mbed.com/users/cpm219/code/FT810/docs/ca6a7c6a2f4b/FT__GPU__Hal_8cpp_source.html
00028 // https://os.mbed.com/users/mozillain/code/FT810/file/74108436751e/src/FT_Hal_Utils.cpp/
00029 // https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-fat-filesystem/rev/ab69df6f1c47/
00030 // https://os.mbed.com/questions/79055/How-can-I-get-a-library-for-a-SD-card-re/
00031 // https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/storage/filesystem/
00032 // Existing block devices:
00033 // SDBlockDevice - block device for SD cards.
00034 // SPIFBlockDevice - block device for NOR based SPI flash devices.
00035 // I2CEEBlockDevice - block device for EEPROM based I2C devices.
00036 // HeapBlockDevice - block device backed by the heap for quick testing.
00037 // https://github.com/armmbed/sd-driver
00038 // https://github.com/ARMmbed/spif-driver
00039 // https://github.com/ARMmbed/i2cee-driver
00040 // https://www.mikroe.com/flash-click
00041 // https://www.tindie.com/products/Bazinga/micron-1gb-serial-nor-flash-memory-breakout/
00042 // https://os.mbed.com/teams/Embedded-Artists/wiki/LPC4088DM-Using-Images
00043 // https://github.com/ARMmbed/spif-driver
00044 // http://nl.farnell.com/integrated-silicon-solution-issi/is25lp128-jble/nor-flash-memory-128mbit-133mhz/dp/2787056 € 2,36
00045 // http://nl.farnell.com/cypress-semiconductor/s25fl128lagmfv010/flash-memory-128mbit-133mhz-soic/dp/2771141 € 3,81
00046 // http://nl.farnell.com/spansion/s25fl256sagmfi011/memory-flash-256mb-16soic/dp/2340545?st=Flash%20Memory%20NOR
00047 // http://nl.farnell.com/cypress-semiconductor/s25fl512sagmfi011/memory-flash-512mbit-16soic/dp/2136298?st=Flash%20Memory%20NOR%20512mbit
00048 // http://nl.farnell.com/cypress-semiconductor/s25fl128lagmfm010/flash-memory-aec-q100-128mbit/dp/2771145 € 5,54
00049 // https://os.mbed.com/users/Decimus/code/FRAMSPI/
00050 // http://www.ftdicommunity.com/index.php?board=3.0
00051 // https://github.com/nopnop2002/STM32_GD2/blob/master/STM32_GD2.cpp
00052 // http://www.ftdichip.com/Support/Documents/AppNotes/AN_269_FT_App_Signature.pdf
00053 // http://forum.arduino.cc/index.php?topic=296126.0
00054 // https://www.youtube.com/watch?v=2FKN5UdqCKg
00055 // https://os.mbed.com/users/Sissors/code/BurstSPI/
00056 
00057 
00058 //#define BAUD_RATE 9600
00059 //// NUCLEO-F746ZG
00060 //#define USB_TX          SERIAL_TX   // PD_8  USART3 TX
00061 //#define USB_RX          SERIAL_RX   // PD_9  USART3 RX
00062 //
00063 //#define BUFFER_SIZE 8192
00064 //
00065 //#define BUTTON_ACCEPT_ALARM_TAG 1
00066 //#define BUTTON_ACCEPT_HORN_TAG 2
00067 //#define BUTTON_SET_TAG 3
00068 //#define BUTTON_DIM_TAG 4
00069 //
00070 //#define TFT_MOSI PA_7
00071 //#define TFT_MISO PA_6
00072 //#define TFT_SCLK PA_5
00073 //#define TFT_CS   PC_7
00074 //#define TFT_INT  PB_4
00075 //#define TFT_PD   PA_4
00076 //
00077 //// Pinout on Nucleo-F746ZG
00078 //#define SD_MOSI  PE_14
00079 //#define SD_MISO  PE_13
00080 //#define SD_SCLK  PE_12
00081 //#define SD_CS    PE_11
00082 //
00083 //#define SF_MOSI  PB_15
00084 //#define SF_MISO  PC_2
00085 //#define SF_SCLK  PB_13
00086 //#define SF_CS    PB_12
00087 //
00088 //#define EE_SDA PB_9
00089 //#define EE_SCL PB_8
00090 //#define EE_ADDR 0xa0
00091 //#define EE_SIZE 32*1024
00092 //#define EE_BLOCK_SIZE 16
00093 //
00094 //#define MBED_CONF_SD_SPI_TRANSFER_FREQ 40000000
00095 //
00096 //#define INDICATOR_RUN_STATUS_OFF 0
00097 //#define INDICATOR_RUN_STATUS_RUNNING 1
00098 //#define INDICATOR_RUN_STATUS_WARNING 2
00099 //#define INDICATOR_RUN_STATUS_OFF_RED 3
00100 //
00101 //#define INDICATOR_ALARM_STATUS_OFF 0
00102 //#define INDICATOR_ALARM_STATUS_WARNING 1
00103 //#define INDICATOR_ALARM_STATUS_FAILURE 2
00104 //
00105 Serial pc(USBTX, USBRX);
00106 
00107 DigitalOut myled(LED1);
00108 
00109 // Setup the watchdog timer
00110 WDT wdt;
00111 
00112 FT813 TFT(TFT_MOSI, TFT_MISO, TFT_SCLK, TFT_CS, TFT_INT, TFT_PD);  // mosi, miso, sck, ss, int, pd     // the FT813 is connected to SPI 11-13
00113 
00114 // PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel=NC, int mode=0
00115 //QSPI qspi(PF_8, PF_9, PF_7, PF_6, PF_10, PB_10);
00116 DigitalOut myledPF8(PF_8);
00117 
00118 //HeapBlockDevice bd(128 * 512, 512);
00119 
00120 // Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard socket.
00121 SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS, MBED_CONF_SD_SPI_TRANSFER_FREQ);
00122 
00123 // Create flash device on SPI bus with PTE5 as chip select
00124 SPIFBlockDevice spif(SF_MOSI, SF_MISO, SF_SCLK, SF_CS, 100000); // mosi, miso, sclk, cs, freq
00125 
00126 // Create EEPROM device on I2C bus with 32kbytes of memory
00127 //I2CEEBlockDevice ee(EE_SDA, EE_SCL, EE_ADDR, EE_SIZE, EE_BLOCK_SIZE); // sda, scl, addr, size, block, freq
00128 
00129 //I2C i2c(EE_SDA, EE_SCL); // sda, scl
00130 //
00131 //I2CList I2C_List(EE_SDA, EE_SCL); // sda, scl
00132 
00133 //SPI spi(SF_MOSI, SF_MOSI, SF_SCLK); // mosi, miso, sclk
00134 //FRAMSPI fram(spi, SF_CS);
00135 
00136 BurstSPI bspi(SF_MOSI, SF_MISO, SF_SCLK); // PinName mosi, PinName miso, PinName sclk
00137 SPI      rspi(SF_MOSI, SF_MISO, SF_SCLK); // PinName mosi, PinName miso, PinName sclk
00138 
00139 FATFileSystem fs("fs");
00140 
00141 //AP3000 ap3000(&TFT);
00142 
00143 Timer timer;
00144 
00145 NMEA0183 nmea0183;
00146 
00147 MCP79412 rtc(EE_SDA, EE_SCL); // sda, scl
00148 
00149 uint8_t setting_block_size;
00150 
00151 struct t_setting {
00152     uint8_t version;
00153     char name[32];
00154     double value;
00155 } setting = {
00156     1,
00157     "Hello World!",
00158     3.1415926536
00159 };
00160 
00161 //struct button {
00162 //    uint8_t accept_alarm_pressed;
00163 //    uint8_t accept_horn_pressed;
00164 //    uint8_t set_pressed;
00165 //    uint8_t dim_pressed;
00166 //};
00167 //
00168 //struct indicator {
00169 //    uint8_t md_main_running;
00170 //    uint8_t rb_main_phase_fail;
00171 //    uint8_t rb_main_main_power;
00172 //    uint8_t rb_main_ctrl_power;
00173 //    uint8_t rb_main_oil_press;
00174 //    uint8_t rb_main_hydr_lock;
00175 //    uint8_t rb_main_overload;
00176 //    uint8_t rb_main_oil_level;
00177 //    uint8_t rb_main_oil_filter;
00178 //    uint8_t rb_main_oil_temp;
00179 //    
00180 //    uint8_t md_aux_running;
00181 //    uint8_t rb_aux_phase_fail;
00182 //    uint8_t rb_aux_main_power;
00183 //    uint8_t rb_aux_ctrl_power;
00184 //    uint8_t rb_aux_oil_press;
00185 //    uint8_t rb_aux_hydr_lock;
00186 //    uint8_t rb_aux_overload;
00187 //    uint8_t rb_aux_oil_level;
00188 //    uint8_t rb_aux_oil_filter;
00189 //    uint8_t rb_aux_oil_temp;
00190 //    
00191 //    uint8_t rb_fu_failure;
00192 //    uint8_t rb_used;
00193 //    uint8_t rb_main_most_used;
00194 //    uint8_t rb_aux_most_used;    
00195 //};
00196 //
00197 //struct button my_button;
00198     
00199 typedef struct {
00200     char name[64];
00201     uint16_t fmt;
00202     uint16_t w;
00203     uint16_t h;
00204 } image;
00205 
00206 //image images[128];
00207 
00208 uint16_t imageCount = 0;
00209 
00210     ft_int16_t x_size,y_size;
00211     int err;
00212 
00213 void return_error(int ret_val){
00214   if (ret_val)
00215     printf("\033[1;31mFailure. %d\033[0m\n", ret_val);
00216   else
00217     printf("\033[1;32mdone.\033[0m\n");
00218 }
00219 
00220 void errno_error(void* ret_val){
00221   if (ret_val == NULL)
00222     printf(" \033[1;31mFailure. %d\033[0m\n", errno);
00223   else
00224     printf(" \033[1;32mdone.\033[0m\n");
00225 }
00226 
00227 // global Vars
00228 unsigned int r,b,g;
00229 
00230 
00231 //int getImageIndexFromName(char *name) {
00232 //    for (int i = 0; i < imageCount; i++) {
00233 //        if(strstr(images[i].name, name) != NULL) {
00234 //            return i;
00235 //        }
00236 //    }
00237 //    return -1;
00238 //}
00239 
00240 
00241 // function to convert hue , saturation and  value to RGB
00242 // see http://en.wikipedia.org/wiki/HSL_and_HSV
00243 void hsv2rgb(float H, float S, float V)
00244 {
00245     float f, h, p, q, t;
00246     int i;
00247     if( S == 0.0) {
00248         r = V * 255;  
00249         g = V * 255;
00250         b = V * 255;
00251         return;
00252     }
00253     if(H > 360.0) H = 0.0;   // check values
00254     if(S > 1.0) S = 1.0; 
00255     if(S < 0.0) S = 0.0;
00256     if(V > 1.0) V = 1.0;
00257     if(V < 0.0) V = 0.0;
00258     
00259     h = H / 60.0;
00260     i = (int) h;
00261     f = h - i;
00262     p = V * (1.0 - S);
00263     q = V * (1.0 - (S * f));
00264     t = V * (1.0 - (S * (1.0 - f)));
00265  
00266     switch(i) {
00267         case 0:
00268             r = V * 255;  
00269             g = t * 255;
00270             b = p * 255;
00271             break;
00272         case 1:
00273             r = q * 255;
00274             g = V * 255;
00275             b = p * 255;
00276             break;
00277         case 2:
00278             r = p * 255;
00279             g = V * 255;
00280             b = t * 255;
00281             break;
00282         case 3:
00283             r = p * 255;
00284             g = q * 255;
00285             b = V * 255;
00286             break;
00287         case 4:
00288             r = t * 255;
00289             g = p * 255;
00290             b = V * 255;
00291             break;
00292         case 5:
00293         default:
00294             r = V * 255;
00295             g = p * 255;
00296             b = q * 255;
00297             break;
00298     }  
00299 }
00300 
00301 
00302 /***************************************************************************/
00303 /* Show a Screen with Text for 5 seconds                                   */
00304 /* A spinner shows the delay                                               */
00305 /***************************************************************************/
00306 
00307 ft_void_t Start_Screen(ft_char8_t *str)
00308 {
00309     TFT.DLstart();                              // start a new display command list
00310     TFT.DL(CLEAR_COLOR_RGB(0xff, 0xff, 0xff));       // set the clear color to white
00311     TFT.DL(CLEAR(1, 1, 1));                       // clear buffers -> color buffer,stencil buffer, tag buffer
00312     
00313     TFT.DL(COLOR_RGB(0x80, 0x80, 0x00));          // set current color
00314     TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
00315     TFT.DL(COLOR_RGB(0xFF, 0x00, 0x00));          // change current color
00316     TFT.Spinner((TFT.DispWidth/2), TFT.DispHeight/4, 0, 0);  // draw a animated spinner
00317 
00318     TFT.DL(DISPLAY());                          // Display the image
00319     TFT.Swap();                                 // Swap the current display list
00320     TFT.Flush_Co_Buffer();                      // Download the command list into fifo
00321 
00322     TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
00323     TFT.Sleep(1000);                            // Wait 5 s to show
00324 }
00325 
00326 void screen_cm3000(void)
00327 {
00328     TFT.DLstart();                              // start a new display command list
00329     TFT.DL(CLEAR_COLOR_RGB(0x21, 0x21, 0x21));        // set current color to white
00330     TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
00331     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));        // set current color to white
00332 
00333     // Bitmap
00334     // BACKGROUND-01.png
00335     TFT.DL(TAG(1));                             // assign TAG
00336     //  Narrow On button, 100x132, Address 0-26400
00337     TFT.DL(BEGIN(BITMAPS));                  
00338     TFT.DL(BITMAP_SOURCE(TFT.GetBitmapAddress(0)));
00339     TFT.DL(BITMAP_LAYOUT(ARGB4, 100*2, 132));    // <------- this distorts the colors
00340     TFT.DL(BITMAP_SIZE(NEAREST, BORDER, BORDER, 100, 132));
00341     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff)); // all colors in bitmap at 100%
00342     TFT.DL(VERTEX2II(20, 290, 0, 0));    
00343 
00344 //    TFT.SetRotate(0); // Standard landscape
00345 //    TFT.SetRotate(1); // Rotate 180 to landscape (upside down)
00346 //    TFT.SetRotate(2); // Rotate 90 CCW to portrait
00347 //    TFT.SetRotate(3); // Rotate 90 CW to portrait
00348 //    TFT.SetRotate(4); // Mirror over landscape X
00349 //    TFT.SetRotate(5); // Mirror over landscape Y
00350 //    TFT.SetRotate(6); // Rotate 90 CCW to portrait and mirror over portrait X
00351 //    TFT.SetRotate(7); // Rotate 90 CW to portrait and mirror over portrait X
00352     
00353     TFT.DL(DISPLAY());                          // Display the image
00354     TFT.Swap();                                 // Swap the current display list
00355     TFT.Flush_Co_Buffer();                      // Download the command list into fifo
00356     TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
00357 }
00358 
00359 // construct the screen and downloasd it to the LCD
00360 void screen_1(unsigned int color, unsigned int bright, unsigned int tagoption1, unsigned int tagoption2, unsigned int tagoption3, unsigned int tagoption4)
00361 {
00362     TFT.DLstart();                              // start a new display command list
00363     TFT.DL(CLEAR_COLOR_RGB(0x21, 0x21, 0x21));        // set current color to white
00364     TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
00365     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));        // set current color to white
00366     
00367     // Default widget colors
00368     TFT.SetThemeDefaultColor();
00369 //    TFT.GradColor(COLOR_RGB(0xff, 0xff, 0xff)); // Default 0xffffff
00370 //    TFT.FgColor(COLOR_RGB(0x00, 0x38, 0x70));   // Default 0x003870    0 56 112
00371 //    TFT.BgColor(COLOR_RGB(0x00, 0x20, 0x40));   // Default 0x002040    0 32 64
00372 
00373     TFT.DL(TAG(1));                             // assign TAG value 1
00374 //    TFT.FgColor(COLOR_RGB(0x00, 0x00, 0xff));   // forground color red
00375 //    TFT.BgColor(COLOR_RGB(0x00, 0x00, 0x80));
00376     TFT.Dial(249, 86, 55, 0, color);            // dial for color 
00377     
00378     TFT.DL(TAG(2));                             // assign TAG value 2
00379 //    TFT.FgColor(COLOR_RGB(0x00, 0x00, 0xff));   // forground color red
00380 //    TFT.BgColor(COLOR_RGB(0x00, 0x00, 0x80));
00381     TFT.Slider(196, 215, 236, 21, 0, bright , 255); // slider for brightness 
00382     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));        // set current color to white
00383     TFT.Text(22, 84, 30, 0, "Color");           // text Color
00384     TFT.Text(22, 208, 30, 0, "Brightness");     // text Brightness
00385 
00386     // TFT.Button(ft_int16_t x, ft_int16_t y, ft_int16_t w, ft_int16_t h, ft_int16_t font, ft_uint16_t options, const ft_char8_t* s);
00387     TFT.DL(TAG(3)); // This is tag value for button
00388     // 0 = 3D, OPT_FLAT
00389     TFT.SetThemeColor(COLOR_RGB(0xff, 0x00, 0x00));
00390 //    TFT.GradColor(COLOR_RGB(0xff, 0xff, 0xff));
00391 //    TFT.FgColor(COLOR_RGB(0x70, 0x00, 0x00));
00392 //    TFT.BgColor(COLOR_RGB(0x38, 0x00, 0x00));
00393     TFT.Button(500, 20, 200, 50, 31, tagoption1, "25%");
00394 
00395     TFT.DL(TAG(4)); // This is tag value for button
00396     TFT.SetThemeColor(COLOR_RGB(0x00, 0xff, 0x00));
00397 //    TFT.GradColor(COLOR_RGB(0xff, 0xff, 0xff));
00398 //    TFT.FgColor(COLOR_RGB(0x00, 0x70, 0x00));
00399 //    TFT.BgColor(COLOR_RGB(0x00, 0x40, 0x00));
00400     TFT.Button(500, 80, 200, 50, 31, tagoption2, "50%");
00401     
00402     TFT.DL(TAG(5)); // This is tag value for button
00403     TFT.SetThemeColor(COLOR_RGB(0x00, 0x7f, 0xff));
00404 //    TFT.GradColor(COLOR_RGB(0xff, 0xff, 0xff));
00405 //    TFT.FgColor(COLOR_RGB(0x00, 0x38, 0x70));
00406 //    TFT.BgColor(COLOR_RGB(0x00, 0x20, 0x40));
00407     TFT.Button(500, 140, 200, 50, 31, tagoption3, "75%");
00408 
00409 //    // Default
00410 //    TFT.SetThemeDefaultColor();
00411 ////    TFT.GradColor(COLOR_RGB(0xff, 0xff, 0xff)); // Default 0xffffff
00412 ////    TFT.FgColor(COLOR_RGB(0x00, 0x38, 0x70));   // Default 0x003870
00413 ////    TFT.BgColor(COLOR_RGB(0x00, 0x20, 0x40));   // Default 0x002040
00414 //
00415 //
00416     TFT.DL(POINT_SIZE(100));                    // color point around the dial 
00417     TFT.DL(BEGIN(POINTS));                  
00418     TFT.DL(COLOR_RGB(0x00, 0x0, 0xff));          // color of next point 
00419     TFT.DL(VERTEX2II(183, 47, 0, 0));           // set point x,y 
00420     TFT.DL(COLOR_RGB(0xff, 0x00, 0x00)); 
00421     TFT.DL(VERTEX2II(249, 162, 0, 0));
00422     TFT.DL(COLOR_RGB(0xff, 0x00, 0xff)); 
00423     TFT.DL(VERTEX2II(183, 123, 0, 0));
00424     TFT.DL(COLOR_RGB(0xff, 0xff, 0x00)); 
00425     TFT.DL(VERTEX2II(317, 123, 0, 0));
00426     TFT.DL(COLOR_RGB(0x00, 0xff, 0xff)); 
00427     TFT.DL(VERTEX2II(249, 11, 0, 0));
00428     TFT.DL(COLOR_RGB(0x00, 0xff, 0x00)); 
00429     TFT.DL(VERTEX2II(317, 50, 0, 0));
00430     TFT.DL(SCISSOR_XY(10, 10));                 // define sub area starting at 10,10
00431     TFT.DL(SCISSOR_SIZE(50, 50));               // size 50, 50
00432     hsv2rgb(color / 65536.0 * 360, 1.0, bright / 255.0);  // calculate rgb color from settings 
00433     TFT.DL(CLEAR_COLOR_RGB(r, b, g));           // set filling color to r,g,b
00434     TFT.DL(CLEAR(1, 1, 1));                     // fill the area  
00435     
00436     // Clipping area
00437     TFT.DL(SCISSOR_XY(0, 0));                 // define area starting at 380,220
00438     TFT.DL(SCISSOR_SIZE(480, 800));             // size 480, 800
00439     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff)); 
00440     
00441     // Rectangle
00442     TFT.DL(TAG(6));                             // assign TAG
00443     TFT.DL(COLOR_RGB(0x80, 0x00, 0xff));                 // set current color to red
00444     TFT.Rect(60, 270, 260, 340, 5);
00445 
00446     // Circle
00447     TFT.DL(TAG(7));                             // assign TAG
00448     TFT.DL(COLOR_RGB(0x00, 0xff, 0x00));        // set current color to green
00449     TFT.Point(400, 340, 60);
00450 
00451     // Rectangle
00452     TFT.DL(TAG(8));                             // assign TAG
00453     TFT.DL(COLOR_RGB(r, b, g));                 // set current color to red
00454     TFT.Rect(160, 305, 360, 440, 20);
00455     TFT.DL(COLOR_RGB(0x00, 0x00, 0x00));        // set current color to black
00456     TFT.Rect(165, 310, 355, 435, 10);
00457 
00458     // Line
00459     TFT.DL(TAG(9));                             // assign TAG
00460     TFT.DL(COLOR_RGB(0x00, 0x00, 0xff));        // set current color to blue
00461     TFT.Line(440, 310, 680, 230 + r, 20);
00462     
00463     // Circle
00464     TFT.DL(TAG(10));                             // assign TAG
00465     TFT.DL(COLOR_RGB(0xff, 0x00, 0xff));        // set current color to green
00466     TFT.Point(600, 340, 80);
00467 //    TFT.DL(TAG(10));                             // assign TAG
00468     TFT.DL(COLOR_RGB(0x00, 0x00, 0x00));        // set current color to green
00469     TFT.Point(600, 340, 70);
00470     
00471     // Bitmap
00472     TFT.DL(TAG(11));                             // assign TAG
00473     //  Narrow On button, 100x132, Address 0-26400
00474     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));  // set the clear color to white
00475     TFT.DL(BEGIN(BITMAPS));                  
00476 //    TFT.DL(BITMAP_SOURCE(TFT.GetBitmapAddress(1)));
00477 //    TFT.DL(BITMAP_LAYOUT(ARGB4, 100*2, 132));    // <------- this distorts the colors
00478 //    TFT.DL(BITMAP_SIZE(NEAREST, BORDER, BORDER, 100, 132));
00479 //    TFT.DL(COLOR_RGB(0xff, 0xff, 0xff)); // all colors in bitmap at 100%
00480 //    TFT.DL(VERTEX2II(20, 290, 0, 0));    
00481 
00482 //    int index = 0;
00483     if (tagoption4 == 0) {
00484 //        index = getImageIndexFromName("SwitchOn_100x132");
00485         TFT.ShowBitmapByName("SwitchOn_100x132", 20, 290);
00486     }
00487     else {
00488 //        index = getImageIndexFromName("SwitchOff_100x132");
00489         TFT.ShowBitmapByName("SwitchOff_100x132", 20, 290);
00490     }
00491 //    TFT.ShowBitmapAtAddress(images[index].addr, images[index].fmt, 20, 290, images[index].w, images[index].h);
00492 
00493 
00494 //    TFT.SetRotate(0); // Standard landscape
00495 //    TFT.SetRotate(1); // Rotate 180 to landscape (upside down)
00496 //    TFT.SetRotate(2); // Rotate 90 CCW to portrait
00497 //    TFT.SetRotate(3); // Rotate 90 CW to portrait
00498 //    TFT.SetRotate(4); // Mirror over landscape X
00499 //    TFT.SetRotate(5); // Mirror over landscape Y
00500 //    TFT.SetRotate(6); // Rotate 90 CCW to portrait and mirror over portrait X
00501 //    TFT.SetRotate(7); // Rotate 90 CW to portrait and mirror over portrait X
00502     
00503     TFT.DL(DISPLAY());                          // Display the image
00504     TFT.Swap();                                 // Swap the current display list
00505     TFT.Flush_Co_Buffer();                      // Download the command list into fifo
00506     TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
00507 }
00508 
00509 // construct the screen and downloasd it to the LCD
00510 void screen_2(unsigned int r, unsigned int g, unsigned int b)
00511 {
00512     TFT.DLstart();                              // start a new display command list
00513     TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
00514     TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));        // set current color to white
00515     TFT.DL(TAG(1));                             // assign TAG value 1
00516     TFT.FgColor(COLOR_RGB(0xff, 0x00, 0x00));   // forground color red
00517     TFT.Slider(140, 81, 310, 14, 0, r, 255);    // slider for red
00518     TFT.DL(TAG(2));                             // assign TAG value 2
00519     TFT.FgColor(COLOR_RGB(0x00, 0xff, 0x00));   // forground color green
00520     TFT.Slider(140, 133, 310, 14, 0, g, 255);   // slider for green
00521     TFT.DL(TAG(3));                             // assign TAG value 3
00522     TFT.FgColor(COLOR_RGB(0x00, 0x00, 0xff));   // forground color blue
00523     TFT.Slider(139, 185, 310, 14, 0, b, 255);   // slider for blue
00524     TFT.DL(COLOR_RGB(0xff, 0x00, 0x00));        // set current color to red
00525     TFT.Text(82, 69, 30, 0, "R");               // text R
00526     TFT.DL(COLOR_RGB(0x00, 0xff, 0x00));        // set current color to green
00527     TFT.Text(82, 120, 30, 0, "G");              // text G
00528     TFT.DL(COLOR_RGB(0x00, 0x00, 0xff));        // set current color to blue
00529     TFT.Text(82, 174, 30, 0, "B");              // text B
00530     TFT.DL(SCISSOR_XY(10, 10));                 // define area starting at 10,10
00531     TFT.DL(SCISSOR_SIZE(50, 50));               // size 50,50
00532     TFT.DL(CLEAR_COLOR_RGB(r, g, b));             // set clear color to r,g,b
00533     TFT.DL(CLEAR(1, 1, 1));                     // fill the area
00534     
00535     // Clipping area
00536     TFT.DL(SCISSOR_XY(0, 220));                 // define area starting at 380,220
00537     TFT.DL(SCISSOR_SIZE(799, 259));             // size 50,50
00538     // Rectangle
00539     TFT.DL(COLOR_RGB(0xff, 0x00, 0x00));        // set current color to red
00540     TFT.Rect(160, 290, 360, 440, 20);
00541     TFT.DL(COLOR_RGB(0x00, 0x00, 0x00));        // set current color to black
00542     TFT.Rect(165, 295, 355, 435, 10);
00543     // Circle
00544     TFT.DL(COLOR_RGB(0x00, 0xff, 0x00));        // set current color to green
00545     TFT.Point(400, 260, 40);
00546     // Line
00547     TFT.DL(COLOR_RGB(0x00, 0x00, 0xff));        // set current color to blue
00548     TFT.Line(440, 270, 680, 400, 20);
00549     
00550     TFT.DL(DISPLAY());                          // Display the image
00551     TFT.Swap();                                 // Swap the current display list
00552     TFT.Flush_Co_Buffer();                      // Download the command list into fifo
00553     TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
00554 }
00555 
00556 void substring(char *s, char *d, int pos, int len) //usage: substring(Src, Dst, Pos, Len);
00557 {
00558 //usage: substring(Source, Destination, pos, len);
00559     char *t;
00560  
00561     s=s+pos;
00562     t=s+len;
00563     while (s!=t) {
00564         *d=*s;
00565         s++;
00566         d++;
00567     }
00568     *d='\0';
00569 }
00570 
00571 int main() {
00572     pc.baud(BAUD_RATE);
00573     printf("\n\n\n");
00574     printf("----------------------------------\n");
00575     printf("20180621_FT800_RGB_demo2\n");
00576     printf("" __DATE__ " " __TIME__ "\n");
00577 #if defined(MBED_MAJOR_VERSION)
00578     printf("Using \033[1;37mMbed OS %d.%d.%d\033[0m\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
00579 #else
00580     printf("Using Mbed OS from master.\n");
00581 #endif
00582     printf("CPU SystemCoreClock: \033[1;37m%d MHz\033[0m\n", SystemCoreClock/1000000);
00583     printf("----------------------------------\n");
00584 
00585     // https://www.unixtimestamp.com/
00586     set_time(1531525845);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
00587 
00588     uint8_t second     = 0;
00589     uint8_t minute     = 0;
00590     uint8_t hour       = 0;
00591     uint8_t dayOfWeek  = 1;      // Will be determined
00592     uint8_t dayOfMonth = 16;
00593     uint8_t month      = 7;
00594     uint8_t year       = 18;
00595     printf("%02d-%02d-%02d %02d:%02d:%02d\n", dayOfMonth, month, year, hour, minute, second);
00596     
00597 //    struct tm *t;
00598 //    *t = rtc.setSystemDateTime(second, minute, hour, dayOfMonth, month, year);
00599 //    printf("-> Debug %d %02d-%02d-%03d %02d:%02d:%02d\n", t->tm_wday, t->tm_mday, t->tm_mon, t->tm_year, t->tm_hour, t->tm_min, t->tm_sec);
00600 
00601     struct tm t;
00602     t = rtc.setSystemDateTime(second, minute, hour, dayOfMonth, month, year);
00603     printf("-> Debug %d %02d-%02d-%03d %02d:%02d:%02d\n", t.tm_wday, t.tm_mday, t.tm_mon, t.tm_year, t.tm_hour, t.tm_min, t.tm_sec);
00604 
00605     time_t secondsEpoch = time(NULL);
00606     
00607     printf("Time as seconds since January 1, 1970 = %d\n", secondsEpoch);
00608     
00609     printf("Time as a basic string = %s", ctime(&secondsEpoch));
00610     
00611     char buffer[32];
00612     strftime(buffer, 32, "%a %d-%m-%Y %H:%M:%S\n", localtime(&secondsEpoch));
00613     printf("Time: %s", buffer);
00614 //    wait(5);
00615     secondsEpoch = time(NULL);
00616     strftime(buffer, 32, "%a %d-%m-%Y %H:%M:%S\n", localtime(&secondsEpoch));
00617     printf("Time: %s", buffer);
00618 
00619     printf("year %d\n", year);
00620     time_t seconds2 = rtc.convertDateTimeToTimestamp(second, minute, hour, dayOfMonth, month, year);
00621     printf("seconds2 %d\n", seconds2);
00622 
00623     uint8_t Weekday = rtc.getWeekdayFromDate(dayOfMonth, month, year);
00624     printf("Weekday %d\n", Weekday);
00625     
00626     rtc.setRtcFromTm(&t);
00627 
00628 //    uint8_t second = 0;
00629 //    uint8_t minute = 18;
00630 //    uint8_t hour = 1;
00631 //    uint8_t dayOfWeek = 6;
00632 //    uint8_t dayOfMonth = 14;
00633 //    uint8_t month = 7;
00634 //    uint8_t year = 18;
00635 //    printf("%02d-%02d-%02d %02d:%02d:%02d\n", dayOfMonth, month, year, hour, minute, second);
00636 //    rtc.setSystemDateTime(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
00637 //    wait(5);
00638     rtc.getSystemDateTime(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
00639     printf("%d %02d-%02d-%02d %02d:%02d:%02d\n", dayOfWeek, dayOfMonth, month, year, hour, minute, second);
00640 //    wait(5);
00641     rtc.getSystemDateTime(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
00642     printf("%d %02d-%02d-%02d %02d:%02d:%02d\n", dayOfWeek, dayOfMonth, month, year, hour, minute, second);
00643     
00644 
00645 // https://os.mbed.com/questions/77039/Use-external-clock-signal-HSE-in-Nucleo-/
00646 
00647 
00648 
00649     switch (__HAL_RCC_GET_SYSCLK_SOURCE())
00650     {
00651 //    case RCC_SYSCLKSOURCE_STATUS_MSI:
00652 //        printf("MSI used as system clock.\r\n");
00653 //        break;
00654     case RCC_SYSCLKSOURCE_STATUS_HSI:
00655         printf("HSI used as system clock.\r\n");
00656         break;
00657     case RCC_SYSCLKSOURCE_STATUS_HSE:
00658         printf("HSE used as system clock.\r\n");
00659         break;
00660     case RCC_SYSCLKSOURCE_STATUS_PLLCLK:
00661         printf("PLL used as system clock.\r\n");
00662 //        if ((RCC->CFGR & RCC_CFGR_PLLSRC) == RCC_CFGR_PLLSRC_HSE) {
00663 //            printf("HSE oscillator clock selected as PLL input clock.\r\n");
00664 //        }
00665 //        else {
00666 //            printf("HSI16 oscillator clock selected as PLL input clock.\r\n");
00667 //        }
00668         break;
00669     }
00670  
00671      printf("HCE Information: \r\n");
00672  
00673     if (READ_BIT(RCC->CR, RCC_CR_HSEON)){
00674         printf("RCC_CR_HSEON = 1 \r\n");
00675     }
00676     else{
00677         printf("RCC_CR_HSEON = 0 \r\n");
00678     }
00679  
00680     if (READ_BIT(RCC->CR, RCC_CR_HSEBYP)){
00681         printf("RCC_CR_HSEBYP = 1 \r\n");
00682     }
00683     else{
00684         printf("RCC_CR_HSEBYP = 0 \r\n");
00685     }
00686  
00687     if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) {
00688         printf("RCC_FLAG_HSERDY = 1 \r\n");
00689     }
00690     else {
00691         printf("RCC_FLAG_HSERDY = 0 \r\n");
00692     }
00693  
00694  
00695     printf("\n");
00696 //    I2C_List.List();
00697 
00698 //    printf("Searching for I2C devices...\n");
00699 //    int count = 0;
00700 //    for (int address=0; address<256; address+=2) {
00701 //        if (!i2c.write(address, NULL, 0)) { // 0 returned is ok
00702 //            count++;
00703 //            printf("%2d: 0x%02X\n", count, address);
00704 //        }
00705 //    }
00706 //    printf("%d I2C devices found\n", count);    
00707 
00708     wdt.Configure(WDT_TIMEOUT);  
00709 
00710     timer.start();
00711     double my_time = timer.read();
00712 
00713     int error = 0;
00714     printf("Welcome to the FAT32 filesystem example.\n");
00715     
00716 //    printf("Formatting a FAT, SD-Card filesystem... "); // "Formatting a FAT, RAM-backed filesystem... "
00717 //    fflush(stdout);
00718 //    error = FATFileSystem::format(&sd);
00719 //    return_error(error);
00720     
00721     printf("Mounting the filesystem on \"/fs\"... ");
00722     fflush(stdout);
00723     // Initialize the SD card device and print the memory layout
00724     sd.init();
00725     error = fs.mount(&sd);
00726     return_error(error);
00727     printf("sd size: %llu Bytes.\n",         sd.size());
00728 //    printf("sd read size: %llu\n",    sd.get_read_size());
00729 //    printf("sd program size: %llu\n", sd.get_program_size());
00730 //    printf("sd erase size: %llu\n",   sd.get_erase_size());
00731 
00732 //    // Initialize the SPI flash device and print the memory layout
00733 //    spif.init();
00734 //    printf("spif size: %llu\n",         spif.size());
00735 //    printf("spif read size: %llu\n",    spif.get_read_size());
00736 //    printf("spif program size: %llu\n", spif.get_program_size());
00737 //    printf("spif erase size: %llu\n",   spif.get_erase_size());
00738 
00739 //    printf("Mounting the filesystem on \"/eefs\"... ");
00740     fflush(stdout);
00741 
00742 //    // Initialize the EEPROM and print the memory layout
00743 //    ee.init();
00744 ////    error = eefs.mount(&i2cee);
00745 ////    return_error(error);
00746 //    printf("ee size: %llu Bytes.\n",         ee.size());
00747 //    printf("ee read size: %llu\n",    ee.get_read_size());
00748 //    printf("ee program size: %llu\n", ee.get_program_size());
00749 //    printf("ee erase size: %llu\n",   ee.get_erase_size());
00750 
00751 //    printf("Send 1000 SPI packets as fast as possible...\n");
00752 //    uint8_t data[1000];
00753 //    for (int i = 0; i<1000; i++)
00754 //        data[i] = (uint8_t) (i & 0xff);
00755 //     //Send 1000 SPI packets as fast as possible
00756 //    bspi.setFormat();
00757 //    timer.reset();
00758 //    for (int i = 0; i<1000; i++)
00759 //        bspi.fastWrite(data[i]);
00760 //    my_time = timer.read();
00761 //    bspi.clearRX();
00762 //    printf("Time: %f.\n", my_time);
00763 //
00764 //    rspi.format(8, 0);                  // 8 bit spi mode 0
00765 //    rspi.frequency(54000000);
00766 //    timer.reset();
00767 //    for (int i = 0; i<1000; i++)
00768 //        rspi.write(data[i]);
00769 //    my_time = timer.read();
00770 //    printf("Time: %f.\n", my_time);
00771 
00772 //    printf("----------\n");
00773 //    printf("EEPROM string...\n");
00774 //    timer.reset();
00775 //    // --- Save a string into EEPROM and read it back ---
00776 //    uint8_t block_size = 32;
00777 //    ee.erase(0, block_size);
00778 //    // Write "Hello World!" to the first block
00779 //    char hello[] = "Hello World!";
00780 //    printf("Save \"%s\"\n", hello);
00781 //    char *buffer = (char*)malloc(block_size);
00782 //    sprintf(buffer, "%s", hello);
00783 //    // Program EEPROM
00784 //    ee.program(buffer, 0, block_size);
00785 //    sprintf(buffer, "empty\n"); // empty buffer, not nessesary but helps when debugging
00786 //    // Read back what was stored
00787 //    ee.read(buffer, 0, block_size);
00788 //    printf("Read \"%s\"\n", buffer);
00789 //    my_time = timer.read();
00790 //    printf("Time: %f.\n", my_time);
00791 //
00792 //
00793 //    printf("----------\n");
00794 //    printf("EEPROM struct...\n");
00795 //    timer.reset();
00796 //    // --- Save a structure into EEPROM and read it back ---
00797 //    // No. of bytes to be stored, but topped up to be multiplied by block size
00798 //    unsigned int setting_block_size = ceil(sizeof(setting)/(double)EE_BLOCK_SIZE)*EE_BLOCK_SIZE;
00799 //    printf("No. of bytes to be stored: %d\n", setting_block_size);
00800 //    // Temporary buffer
00801 //    char *buffer2 = (char*)malloc(setting_block_size);
00802 //    // Save the struct to EEPROM
00803 //    setting.version = 56;
00804 //    printf("Save struct version: %u, name: %s, value: %3.10lf\n", setting.version, setting.name, setting.value);
00805 //    memcpy(buffer2, &setting, sizeof(setting));
00806 //    // Program EEPROM
00807 //    ee.program(buffer2, 0, setting_block_size);
00808 //    // Read back what was stored
00809 //    t_setting tmp; // Re-make the struct
00810 //    memset(buffer2, 0, sizeof(buffer2)); // empty buffer, not nessesary but helps when debugging
00811 //    // Read the struct from the EEPROM
00812 //    if (ee.read(buffer2, 0, setting_block_size ) == 0) { // get data into buffer
00813 //        // Convert what we read into struct
00814 //        memcpy(&tmp, buffer2, sizeof(tmp)); // copy only size of struct not setting_block_size
00815 //        printf("Read struct version: %u, name: %s, value: %3.10lf\n", tmp.version, tmp.name, tmp.value);
00816 //    } else {
00817 //        printf("Error when reading\n");
00818 //    }
00819 //    my_time = timer.read();
00820 //    printf("Time: %f.\n", my_time);
00821 
00822 //    
00823 //    char filename[] = "/fs/my_text_file.txt";
00824 //    
00825 //    printf("Opening a new file, \"/%s\"...", filename);
00826 //    fflush(stdout);
00827 //    FILE* fd = fopen(filename, "w");
00828 //    errno_error(fd);
00829 //    
00830 //    printf("Writing text to a file:\n");
00831 //    char text[] = "Hello world!\nThis is just some text...\n";
00832 //    printf("\033[1;37m%s\033[0m", text);
00833 //    fprintf(fd, "%s", text);
00834 //
00835 ////    for (int i = 0; i < 10; i++) {
00836 ////        printf("%d/20\n", i);
00837 ////        fprintf(fd, "%d\n", i);
00838 ////    }
00839 ////    printf("Writing decimal numbers to a file (10/10) done.\n");
00840 //    printf("Writing text to a file done.\n");
00841 //    
00842 //    printf("Closing file...");
00843 ////    fflush(stdout);
00844 //    fclose(fd);
00845 //    printf(" done.\r\n");
00846 //    
00847 //    printf("Re-opening file read-only...");
00848 ////    fflush(stdout);
00849 //    fd = fopen(filename, "r");
00850 //    errno_error(fd);
00851 //
00852 //    printf("Dumping file to screen:\n");
00853 //    printf("\033[1;37m");
00854 //    char buff[16] = {0};
00855 //    while (!feof(fd)) {
00856 //        int size = fread(&buff[0], 1, 15, fd);
00857 //        fwrite(&buff[0], 1, size, stdout);
00858 //    }
00859 //    printf("\033[0m");
00860 //    printf("Closing file...");
00861 ////    fflush(stdout);
00862 //    fclose(fd);
00863 //    printf(" done.\r\n");
00864 //    
00865 //    printf("Opening root directory...");
00866 //    fflush(stdout);
00867 //    DIR* dir = opendir("/fs/");
00868 //    errno_error(fd);
00869 //    
00870 //    struct dirent* de;
00871 //    printf("Printing all filenames:\n");
00872 //    printf("\033[1;37m");
00873 //    while((de = readdir(dir)) != NULL) {
00874 //        printf("  %s\r\n", &(de->d_name)[0]);
00875 //    }
00876 //    printf("\033[0m");
00877 //    
00878 //    printf("Closing root directory... ");
00879 //    fflush(stdout);
00880 //    error = closedir(dir);
00881 //    return_error(error);
00882 //    printf("Filesystem Demo complete.\n");
00883 
00884 
00885 //    printf("Start FRAM Demo.\n");
00886 //    char wdata[] = "Hello world!";
00887 //    char rdata[14];
00888 //    fram.write(0, wdata, 13); // 12 symbols + zero terminator
00889 //    fram.read(0, rdata, 13);
00890 //    pc.printf("data: %s", rdata);
00891 //    printf("Done.\n");
00892 
00893 
00894 // Set screen rotation
00895 //    TFT.SetRotate(2); // Rotate 90 CCW to portrait
00896 //    TFT.SetRotate(3); // Rotate 90 CW to portrait
00897 
00898 //    TFT.SetOrientation(FT8_DISPLAY_LANDSCAPE_0);
00899     TFT.SetOrientation(FT8_DISPLAY_PORTRAIT_90CW);   // CM3000
00900 //    TFT.SetOrientation(FT8_DISPLAY_PORTRAIT_90CCW);   // CM3000
00901 
00902 //    ap3000.SetBacklight((uint16_t)255);
00903 
00904 //    TFT.Calibrate();                                    // calibrate the touch screen
00905 //    // Read calibrate registers
00906 //    printf("// Calibration values:\n");
00907 //    printf("    ft_uint32_t canned_calibration_data[] = {\n");
00908 //    for(int i = 0; i < 24; i+=4) {
00909 //        printf("        ");
00910 //        printf("0x%08x", TFT.read_calibrate_reg32(i));
00911 //        if (i < 20)
00912 //            printf(",");
00913 //        printf("\n");
00914 //    }
00915 //    printf("    };\n");
00916 //    printf("    TFT.write_calibrate32(canned_calibration_data);\n");
00917 
00918     // Default
00919 //    ft_uint32_t canned_calibration_data[] = {
00920 //        0x00000000,
00921 //        0x00010000,
00922 //        0x00000000,
00923 //        0xffff0000,
00924 //        0x00000000,
00925 //        0x031f0000
00926 //    };
00927 //    TFT.write_calibrate32(canned_calibration_data);
00928 
00929 
00930     // Landscape 0
00931 //    ft_uint32_t canned_calibration_data[] = {
00932 //        0x000109b0,   // 68016
00933 //        0x0000023d,   // 573
00934 //        0x0000fa64,   // 64100
00935 //        0xffffffcf,   // -49
00936 //        0xfffefc9a,   // -66406
00937 //        0x01ee8754    // 32409428
00938 //    };
00939 //    TFT.write_calibrate32(canned_calibration_data);
00940 
00941     // Calibration rotate 90 CCW to portrait 
00942 //    ft_uint32_t canned_calibration_data[] = {
00943 //        0x00000491,
00944 //        0x0000fd0b,
00945 //        0xfff6f84b,
00946 //        0x00010503,
00947 //        0x000006b7,
00948 //        0xffeeb0b7
00949 //    };
00950 //    TFT.write_calibrate32(canned_calibration_data);
00951 
00952 //    // Calibration rotate 90 CW to portrait 
00953 //    ft_uint32_t canned_calibration_data[] = {
00954 //        0xfffff994,
00955 //        0xffff07d3,
00956 //        0x01e4b85c,
00957 //        0xfffef6f5,
00958 //        0x000002ad,
00959 //        0x032eb4d4
00960 //    };
00961 //    TFT.write_calibrate32(canned_calibration_data);
00962 
00963 //    // Read calibrate registers
00964 //    printf("// Calibration values:\n");
00965 //    printf("    ft_uint32_t canned_calibration_data[] = {\n");
00966 //    for(int i = 0; i < 24; i+=4) {
00967 //        printf("        ");
00968 //        printf("0x%08x", TFT.read_calibrate_reg32(i));
00969 //        if (i < 20)
00970 //            printf(",");
00971 //        printf("\n");
00972 //    }
00973 //    printf("    };\n");
00974 //    printf("    TFT.write_calibrate32(canned_calibration_data);\n");
00975 
00976 
00977 
00978 
00979 
00980 
00981 //
00982 //    TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
00983 //    TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));  // set the clear color to white
00984 //    TFT.DL(SAVE_CONTEXT());
00985 
00986 //    TFT.DL(BEGIN(BITMAPS));
00987 //
00988 //    TFT.DL(BLEND_FUNC(ONE,ZERO));
00989 //    TFT.DL(COLOR_A(0x55));
00990 //    TFT.DL(VERTEX2II(0, 0, 0, 0));
00991 //    TFT.DL(BLEND_FUNC(ONE,ONE));
00992 //    TFT.DL(COLOR_A(0xAA));
00993 //    TFT.DL(VERTEX2II(0, 0, 0, 1));
00994 //    TFT.DL(COLOR_MASK(1,1,1,0));
00995 //    TFT.Scale(4*65536,4*65536);
00996 //    TFT.SetMatrix();
00997 //    TFT.DL(BLEND_FUNC(DST_ALPHA,ZERO));
00998 //    TFT.DL(VERTEX2II(0, 0, 2, 1));
00999 //    TFT.DL(BLEND_FUNC(ONE_MINUS_DST_ALPHA,ONE));
01000 //    TFT.DL(VERTEX2II(0, 0, 2, 0));
01001 //    
01002 //    TFT.DL(RESTORE_CONTEXT());
01003 
01004 
01005 //    // NMEA0183 Test
01006 
01007     int status = nmea0183.CheckParity("$PVMAL,A,R1,F3A8,C000,0030*34");
01008     printf("nmea0183.CheckParity %d\n", status);
01009 
01010 
01011 //image images2[] = {
01012 //    {"/fs/BACKGROUND_01_C_20x20_BL.bin", L8, 20, 20},
01013 //    {"/fs/BACKGROUND_01_C_20x20_BR.bin", L8, 20, 20},
01014 //    {"/fs/BACKGROUND_01_C_20x20_TL.bin", L8, 20, 20},
01015 //    {"/fs/BACKGROUND_01_C_20x20_TR.bin", L8, 20, 20},
01016 //    
01017 //    {"/fs/BACKGROUND_01_H_5x4.bin", L8, 5, 4},
01018 //    {"/fs/BACKGROUND_01_H_10x4.bin", L8, 10, 4},
01019 //    {"/fs/BACKGROUND_01_H_25x4.bin", L8, 25, 4},
01020 //    {"/fs/BACKGROUND_01_H_190x4.bin", L8, 190, 4},
01021 //    {"/fs/BACKGROUND_01_V_4x535.bin", L8, 4, 535},
01022 //    {"/fs/BACKGROUND_01_V_4x21.bin", L8, 4, 21},
01023 //    
01024 //    {"/fs/RegularButtonRed_220x51r.bin", ARGB4, 220, 51},
01025 //    {"/fs/RegularButtonBlk_220x51r4t.bin", ARGB4, 220, 51},
01026 //    {"/fs/RegularButtonGray_220x51r0r10t.bin", ARGB4, 220, 51},
01027 //    {"/fs/RegularButtonRed_220x51r0r10t.bin", ARGB4, 220, 51},
01028 //    {"/fs/RegularButtonYel_220x51r0r10t.bin", ARGB4, 220, 51},
01029 //
01030 //    {"/fs/RegulaButtonrBlk_220x51r0t.bin", ARGB4, 220, 51},
01031 //    {"/fs/RegularButtonGray_220x51r0t.bin", ARGB4, 220, 51},
01032 //    {"/fs/RegularButtonRed_220x51r0t.bin", ARGB4, 220, 51},
01033 //    {"/fs/RegularButtonYel_220x51r0t.bin", ARGB4, 220, 51},
01034 //
01035 //    {"/fs/SwitchOn_234x132_blk.bin", L8, 234, 132},
01036 //    {"/fs/SwitchOff_234x132_blk.bin", L8, 234, 132},
01037 //    {"/fs/SwitchOn_100x132_blk.bin", L8, 100, 132},
01038 //    {"/fs/SwitchOff_100x132_blk.bin", L8, 234, 132},
01039 //    {"/fs/SwitchOn_115x66_t.bin", L8, 115, 66},
01040 //    {"/fs/SwitchOff_115x66_t.bin", L8, 115, 66},
01041 //    
01042 //    {"/fs/MD_DISABLED_230x70.bin", ARGB4, 230, 70},
01043 //    {"/fs/MD_OFF_230x70.bin", ARGB4, 230, 70},
01044 //    {"/fs/MD_OFF_GREY_230x70.bin", ARGB4, 230, 70},
01045 //    {"/fs/MD_RUNNING_230x70.bin", ARGB4, 230, 70},
01046 //    {"/fs/MD_WARNING_230x70.bin", ARGB4, 230, 70},
01047 //    
01048 //    {"/fs/RUN_TIME_C_ON_21_X_21.bin", ARGB4, 21, 21},
01049 //    {"/fs/RUN_TIME_C_OFF_21_X_21.bin", ARGB4, 21, 21},
01050 //    {"/fs/RUN_TIME_L_ON_21_X_21.bin", ARGB4, 21, 21},
01051 //    {"/fs/RUN_TIME_L_OFF_21_X_21.bin", ARGB4, 21, 21},
01052 //    {"/fs/RUN_TIME_R_ON_21_X_21.bin", ARGB4, 21, 21},
01053 //    {"/fs/RUN_TIME_R_OFF_21_X_21.bin", ARGB4, 21, 21}
01054 //};
01055 //    uint16_t entries = sizeof(images2) / sizeof(images2[0]);
01056 //    printf("--- images2[] %d\n", entries);
01057 //    for (int i = 0; i < entries; i++) {
01058 //        printf("%3d - %s, %d, %d, %d\n", i, images2[i].name, images2[i].fmt, images2[i].w, images2[i].h);
01059 //    }
01060 
01061 //    TFT.SetLoadAddress(0);
01062 //    TFT.SetBitmapCount(0);
01063 
01064 
01065 
01066 
01067 
01068 
01069 
01070 
01071 
01072     // ---------------------------------------- Load and show bitmaps ----------------------------------------
01073     
01074 
01075     // Splash Screen
01076 //    printf("--------------\n");
01077 //    printf("loadSplashScreen...\n");
01078 //    timer.reset();
01079 //    loadSplashScreen();
01080 //    my_time = timer.read();
01081 //    printf("Time: %f Sec.\n", my_time);
01082   
01083     printf("--------------\n");
01084     printf("showSplashScreen...\n");
01085     timer.reset();
01086     showSplashScreen();
01087     my_time = timer.read();
01088     printf("Time: %f Sec.\n", my_time);
01089 
01090 //    wait(3);
01091 
01092     printf("--------------\n");
01093     printf("loadBitmaps...\n");
01094     timer.reset();
01095 
01096     loadBitmaps();
01097 
01098     my_time = timer.read();
01099     printf("Time: %f Sec.\n", my_time);
01100 
01101     uint32_t RamUsage = TFT.GetRamUsage();
01102     uint16_t GetRamNoOfBitmaps = TFT.GetRamNoOfBitmaps();
01103     printf("RAM usage: %d Bytes.\n", RamUsage);
01104     printf("RAM no of bitmaps: %d.\n", GetRamNoOfBitmaps);
01105 
01106     printf("--------------\n");
01107     printf("showMainPage...\n");
01108     timer.reset();
01109 
01110     InitAP3000();
01111 
01112 //    button my_button;
01113 //    my_button.accept_alarm_pressed = 0;
01114 //    my_button.accept_horn_pressed = 0;
01115 //    my_button.set_pressed = 0;
01116 //    my_button.dim_pressed = 0;
01117 //
01118 //    indicator my_indicator;
01119 //    my_indicator.rb_used = 1;
01120 //    my_indicator.rb_main_most_used = 1;
01121 //    my_indicator.rb_aux_most_used = 0;
01122 //    
01123 //    // INDICATOR_RUN_STATUS_OFF
01124 //    // INDICATOR_RUN_STATUS_RUNNING
01125 //    // INDICATOR_RUN_STATUS_WARNING
01126 //    // INDICATOR_RUN_STATUS_OFF_RED
01127 //    my_indicator.md_main_running    = INDICATOR_RUN_STATUS_RUNNING;
01128 //    my_indicator.md_aux_running     = INDICATOR_RUN_STATUS_WARNING;
01129 //    
01130 //    // INDICATOR_ALARM_STATUS_OFF
01131 //    // INDICATOR_ALARM_STATUS_WARNING
01132 //    // INDICATOR_ALARM_STATUS_FAILURE
01133 //    my_indicator.rb_main_phase_fail = INDICATOR_ALARM_STATUS_FAILURE;
01134 //    my_indicator.rb_main_main_power = INDICATOR_ALARM_STATUS_FAILURE;
01135 //    my_indicator.rb_main_ctrl_power = INDICATOR_ALARM_STATUS_FAILURE;
01136 //    my_indicator.rb_main_oil_press  = INDICATOR_ALARM_STATUS_FAILURE;
01137 //    my_indicator.rb_main_hydr_lock  = INDICATOR_ALARM_STATUS_OFF;
01138 //    my_indicator.rb_main_overload   = INDICATOR_ALARM_STATUS_WARNING;
01139 //    my_indicator.rb_main_oil_level  = INDICATOR_ALARM_STATUS_WARNING;
01140 //    my_indicator.rb_main_oil_filter = INDICATOR_ALARM_STATUS_WARNING;
01141 //    my_indicator.rb_main_oil_temp   = INDICATOR_ALARM_STATUS_WARNING;
01142 //
01143 //    my_indicator.rb_aux_phase_fail  = INDICATOR_ALARM_STATUS_FAILURE;
01144 //    my_indicator.rb_aux_main_power  = INDICATOR_ALARM_STATUS_FAILURE;
01145 //    my_indicator.rb_aux_ctrl_power  = INDICATOR_ALARM_STATUS_FAILURE;
01146 //    my_indicator.rb_aux_oil_press   = INDICATOR_ALARM_STATUS_FAILURE;
01147 //    my_indicator.rb_aux_hydr_lock   = INDICATOR_ALARM_STATUS_OFF;
01148 //    my_indicator.rb_aux_overload    = INDICATOR_ALARM_STATUS_WARNING;
01149 //    my_indicator.rb_aux_oil_level   = INDICATOR_ALARM_STATUS_WARNING;
01150 //    my_indicator.rb_aux_oil_filter  = INDICATOR_ALARM_STATUS_WARNING;
01151 //    my_indicator.rb_aux_oil_temp    = INDICATOR_ALARM_STATUS_WARNING;
01152 //
01153 //    my_indicator.rb_fu_failure      = INDICATOR_ALARM_STATUS_FAILURE;
01154 
01155     showMainPage();
01156 //    wait(1); 
01157 
01158 //    wait(1); 
01159 
01160     my_time = timer.read();
01161     printf("Time: %f Sec.\n", my_time);
01162 
01163     TFT.Track(  3, 623, 234, 132, BUTTON_ACCEPT_ALARM_TAG);
01164     TFT.Track(243, 623, 234, 132, BUTTON_ACCEPT_HORN_TAG);
01165     TFT.Track(  5, 553, 115,  66, BUTTON_SET_TAG);
01166     TFT.Track(360, 553, 115,  66, BUTTON_DIM_TAG);
01167     TFT.Track( 10, 360, 220, 51, 100);
01168     TFT.Track(250, 360, 220, 51, 101);
01169 
01170     Timer touchTimer;
01171     touchTimer.reset();
01172     touchTimer.start();
01173     
01174 //    setPumpRunningBlinkStatus(MAIN_SYSTEM, STEADY_RUNNING_ON);
01175 //    setPumpRunningBlinkStatus(AUX_SYSTEM, BLINK_WARNING_ON);
01176 //    
01177 //    setAlarmBlinkStatus(MAIN_SYSTEM, OIL_PRESS, BLINK_FAILURE_ON);
01178 //    setAlarmBlinkStatus(AUX_SYSTEM, HYDR_LOCK, BLINK_WARNING_ON);
01179 //    setAlarmBlinkStatus(GLOBAL_SYSTEM, FU_FAILURE, BLINK_FAILURE_ON);
01180     
01181     Timer minutes;
01182     minutes.reset();
01183     minutes.start();
01184     uint32_t noOfMinutes = 0;
01185     
01186     uint32_t secondCount = 0;
01187     Timer seconds;
01188     seconds.reset();
01189     seconds.start();
01190     Timer timerWdt;
01191     timerWdt.reset();
01192     timerWdt.start();
01193     uint16_t tagvalOld = TAGVAL_NONE;
01194     while(1) {
01195         // Watch Dog Timer
01196         if (timerWdt.read() >= 1.0f) {
01197             timerWdt.reset();
01198             wdt.Service();
01199             TFT.SetTouchConfig(VAL_TOUCH_CONFIG);
01200         }
01201         
01202         // Print time (check stability)
01203         if (minutes.read() >= 60.0f) {
01204             minutes.reset();
01205             noOfMinutes++;
01206             secondsEpoch = time(NULL);
01207             strftime(buffer, 32, "%a %d-%m-%Y %H:%M\n", localtime(&secondsEpoch));
01208             printf("Time: %s", buffer);
01209         }
01210         
01211 //        uint16_t tagval = TFT.GetTouchedTag();
01212         uint16_t tagval = TFT.GetTouchTag();
01213         
01214         if(tagval != 0) {                               // touch -> get new values
01215             uint16_t tagX = TFT.GetTouchTagX();
01216             uint16_t tagY = TFT.GetTouchTagY();
01217             uint16_t TouchConfig = TFT.GetTouchConfig();
01218 //            printf("GetTouchTagXY %d %d\n", tagX, tagY);
01219 //            uint16_t tagval1 = TFT.GetTouchedTag(1);
01220             printf("GetTouchTagXY %d %d %04x\n", tagX, tagY, TouchConfig);
01221             // The touch screen is touched, the tag value (touch-id) greater than 0
01222             // However, we can ocasionally get random (invalid) touch id's
01223             // Therfore we validate the touch duration times
01224             // Valid touch events take about 0.15 Sec.
01225             // Invalid touch events take very short, not longer than about 0.025 Sec.
01226             // Now, we can also detect long press
01227             my_time = touchTimer.read();
01228 //            printf("d: %f\n", time);
01229             if ((tagval != tagvalOld) && (my_time >= 0.035)) {
01230                 // Execute below only once, if the touched tag (touch-id) changed
01231                 printf("t %d\n", tagval);
01232                 processButtonPressed(tagval);
01233                 touchTimer.reset();
01234                 showMainPage();
01235                 tagvalOld = tagval;
01236                 wait(0.01);
01237             }
01238         }
01239         else
01240         {
01241             // The touch screen is released, the tag value (touch-id) is 0
01242             if (tagvalOld != TAGVAL_NONE) {
01243                 my_time = touchTimer.read();
01244                 printf("r: %f\n", my_time);
01245                 processButtonReleased();
01246                 showMainPage();
01247                 tagvalOld = TAGVAL_NONE;
01248                 wait(0.01);
01249             }
01250         }
01251         updateAlarmLights();
01252         
01253         // Create alarms at time intervals to test it
01254         if (seconds.read() >= 1.0f) {
01255             seconds.reset();
01256             secondCount++;
01257             
01258             if (secondCount == 2) {
01259                 setPumpRunningBlinkStatus(MAIN_SYSTEM, STEADY_RUNNING_ON);
01260             }
01261             if (secondCount == 4) {
01262                 setAlarmBlinkStatus(MAIN_SYSTEM, OIL_PRESS, BLINK_FAILURE_ON);
01263             }
01264             if (secondCount == 6) {
01265                 setAlarmBlinkStatus(AUX_SYSTEM, HYDR_LOCK, BLINK_WARNING_ON);
01266             }
01267             if (secondCount == 8) {
01268                 setAlarmBlinkStatus(GLOBAL_SYSTEM, FU_FAILURE, BLINK_FAILURE_ON);
01269             }
01270             if (secondCount == 10) {
01271                 setPumpRunningBlinkStatus(AUX_SYSTEM, STEADY_WARNING_ON);
01272             }
01273             if (secondCount == 12) {
01274                 setAlarmBlinkStatus(MAIN_SYSTEM, OIL_PRESS, STEADY_FAILURE_ON);
01275             }
01276             if (secondCount == 14) {
01277                 setAlarmBlinkStatus(AUX_SYSTEM, HYDR_LOCK, STEADY_WARNING_ON);
01278             }
01279             if (secondCount == 16) {
01280                 setAlarmBlinkStatus(GLOBAL_SYSTEM, FU_FAILURE, STEADY_FAILURE_ON);
01281             }
01282             if (secondCount == 18) {
01283                 setPumpInUse(PUMP_IN_USE_MAIN);
01284             }
01285             if (secondCount == 20) {
01286                 setAlarmBlinkStatus(GLOBAL_SYSTEM, FU_FAILURE, BLINK_FAILURE_ON);
01287             }
01288         }
01289         wait(0.01);
01290     }
01291     
01292 //    wait (500);
01293 //}
01294 
01295 
01296 
01297 
01298 
01299 
01300 //    printf("----------\n");
01301 //    for (int i = 0; i < 4; i++)
01302 //    {
01303 //        printf("Show Bitmap from memory...\n");
01304 //        timer.reset();
01305 //        TFT.DLstart();                              // start a new display command list
01306 //    
01307 //        TFT.DL(CLEAR_COLOR_RGB(0x21, 0x21, 0x21));  // set the clear color to white
01308 //        TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
01309 //        TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));  // set the clear color to white
01310 //        
01311 ////    TFT.DL(SAVE_CONTEXT());             
01312 ////    TFT.DL(BITMAP_HANDLE(0));
01313 //
01314 ////    TFT.Png("/fs/BACKGROUND-01.png", 0, 0);
01315 //
01316 //    //    TFT.LoadIdentity();
01317 //        TFT.DL(BEGIN(BITMAPS));                  
01318 //
01319 //
01320 //        //  Narrow On button, 100x132, Address 0-26400
01321 //        TFT.ShowBitmap(1, ARGB4, 125, 20, 100, 132); // bitmap, x, y, w, h
01322 //        // Narrow Off button, 100x132, Address 26400-52800
01323 //        TFT.ShowBitmap(2, ARGB4, 20, 20, 100, 132); // bitmap, x, y, w, h
01324 //        // Wide On button, 182x132, Address 52800-100848
01325 //        TFT.ShowBitmap(3, ARGB4, 416, 20, 182, 132); // bitmap, x, y, w, h
01326 //        // Wide Off button, 182x132, Address 100848-148896
01327 //        TFT.ShowBitmap(4, ARGB4, 230, 20, 182, 132); // bitmap, x, y, w, h
01328 //
01329 ////        TFT.DL(END());                  
01330 //        TFT.DL(DISPLAY());                          // Display the image (erases the other images!)
01331 //        TFT.Swap();                                 // Swap the current display list
01332 //        TFT.Flush_Co_Buffer();                      // Download the command list into fifo
01333 //        TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
01334 //        time = timer.read();
01335 //        printf("Time: %f.\n", time);
01336 //        wait(0.5);
01337 //    
01338 //    
01339 //    
01340 //        printf("Show Bitmap from memory...\n");
01341 //        timer.reset();
01342 //        TFT.DLstart();                              // start a new display command list
01343 //    
01344 //        TFT.DL(CLEAR_COLOR_RGB(0x21, 0x21, 0x21));  // set the clear color to white
01345 //        TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
01346 //        TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));  // set the clear color to white
01347 //        
01348 //    TFT.DL(SAVE_CONTEXT());             
01349 //    TFT.DL(BITMAP_HANDLE(0));
01350 //
01351 //    //    TFT.LoadIdentity();
01352 //        TFT.DL(BEGIN(BITMAPS));                  
01353 //
01354 //        //  Narrow On button, 100x132, Address 0-26400
01355 //        TFT.ShowBitmap(1, ARGB4, 20, 20, 100, 132); // bitmap, x, y, w, h    
01356 //        // Narrow Off button, 100x132, Address 26400-52800
01357 //        TFT.ShowBitmap(2, ARGB4, 125, 20, 100, 132); // bitmap, x, y, w, h
01358 //        // Wide On button, 182x132, Address 52800-100848
01359 //        TFT.ShowBitmap(3, ARGB4, 230, 20, 182, 132); // bitmap, x, y, w, h
01360 //        // Wide Off button, 182x132, Address 100848-148896
01361 //        TFT.ShowBitmap(4, ARGB4, 416, 20, 182, 132); // bitmap, x, y, w, h
01362 //    
01363 ////        TFT.DL(END());                  
01364 //        TFT.DL(DISPLAY());                          // Display the image (erases the other images!)
01365 //        TFT.Swap();                                 // Swap the current display list
01366 //        TFT.Flush_Co_Buffer();                      // Download the command list into fifo
01367 //        TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
01368 //        time = timer.read();
01369 //        printf("Time: %f.\n", time);
01370 //        wait(0.5);
01371 //    }
01372 
01373 
01374 
01375 //    printf("----------\n");
01376 //    printf("Erase screen\n");
01377 //    TFT.DLstart();                              // start a new display command list
01378 //    TFT.DL(CLEAR_COLOR_RGB(0x00, 0x00, 0x00));  // set the clear color to black
01379 //    TFT.DL(CLEAR(1, 1, 1));                     // clear buffers -> color buffer,stencil buffer, tag buffer
01380 //    TFT.DL(COLOR_RGB(0xff, 0xff, 0xff));        // set the color to white
01381 //    TFT.DL(DISPLAY());                          // Display the image
01382 //    TFT.Swap();                                 // Swap the current display list
01383 //    TFT.Flush_Co_Buffer();                      // Download the command list into fifo
01384 //    TFT.WaitCmdfifo_empty();                    // Wait till coprocessor completes the operation
01385 
01386 //    printf("----------\n");
01387 //    printf("JpgSplash...\n");
01388 //    timer.reset();
01389 //    TFT.JpgSplash("/fs/Damen-shipyards-logo_760x157.jpg", 0xff, 0xff, 0xff);
01390 //    time = timer.read();
01391 //    printf("Time: %f.\n", time);
01392 //    wait(1);
01393     
01394 //    printf("RGB DEMO START\n");
01395 //    Start_Screen("RGB DEMO START");                 // Show start screen
01396 //    TFT.Calibrate();                                // calibrate the touch screen
01397 //    /* Set the tracker for the 3 sliders -  define the Area for touching */
01398 //    TFT.Track(131,  63, 330, 48, 1);                // slider r
01399 //    TFT.Track(131, 116, 330, 48, 2);                // slider g
01400 //    TFT.Track(131, 168, 330, 48, 3);                // slider b
01401 //    TFT.Flush_Co_Buffer();                          // Download the commands into fifo
01402 //    TFT.WaitCmdfifo_empty();                        // Wait till coprocessor completes the operation
01403 //    screen_2(r,g,b);                                // paint screen
01404 //    /* the demo is updating the screen in a endless loop                                    */
01405 //    while(1) {
01406 //        ft_uint8_t tagval = 0;
01407 //        TrackRegisterVal = TFT.Rd32(REG_TRACKER);   // check if one of the tree Slider is touched
01408 //        tagval = TrackRegisterVal & 0xff;
01409 //        if(0 != tagval) {                           // touch -> get new rgb value
01410 //            if(1 == tagval) {                       // the red slider is touched
01411 //                r = TrackRegisterVal>>16;           // get the new value
01412 //                r = r *255/65536;                   // scale it down to 255
01413 //            } else if(2 == tagval) {                // the green slider is touched
01414 //                g = TrackRegisterVal>>16;           // get new slider value
01415 //                g = g * 255/65536;                  // scale it down to 255
01416 //            } else if(3 == tagval) {                // the blue slider is touched
01417 //                b = TrackRegisterVal>>16;           // get new slider value
01418 //                b = b * 255/65536;                  // scale it down to 255
01419 //            }
01420 //            screen_2(r, g, b);                        // paint new screen
01421 //            TFT.Sleep(10);                          // wait 10ms for next check
01422 //        }
01423 //    }  // end of display loop
01424 
01425 
01426 
01427 //    unsigned int color = 0;
01428 //    unsigned int bright = 255;
01429 ////    ft_uint32_t TrackRegisterVal = 0;           // touch track
01430 //    uint16_t TrackRegisterVal = 0;           // touch track
01431 //
01432 ////    printf("RGB DEMO2 START\n");
01433 ////    Start_Screen("RGB DEMO2 START");                    // Show start screen
01434 //
01435 //    
01436 //    /* Set the tracker for the dial -  define the Area for touching */
01437 //    printf("Set the tracker for the dial -  define the Area for touching\n");
01438 //  
01439 //  
01440 //    TFT.DL(TAG(2));                             // assign TAG value 2
01441 //    //TFT.FgColor(COLOR_RGB(0x00 ,0xff, 0x00));   // forground color green
01442 //
01443 //    //  TFT.Dial(249, 86, 55, 0, color);            // dial for color 
01444 //    TFT.Track(249, 86, 1, 1, 1);                        // Dial  - dimension 1,1 means rotary
01445 //    // TFT.Slider(196, 215, 236, 21, 0, bright , 255); // slider for brightness 
01446 //    TFT.Track(179, 199, 277, 48, 2);                    // Slider
01447 //    // TFT.Button(500, 63, 200, 50, 31, 0, "Test 1");
01448 //    TFT.Track(500, 20, 200, 50, 3);                     // Button
01449 //    TFT.Track(500, 80, 200, 50, 4);                     // Button
01450 //    TFT.Track(500, 140, 200, 50, 5);                    // Button
01451 //    TFT.Track(20, 290, 100, 132, 11);                   // Bitmap
01452 //    
01453 //    TFT.Flush_Co_Buffer();                              // Download the commands into fifo
01454 //    TFT.WaitCmdfifo_empty();                            // Wait till coprocessor completes the operation
01455 //    int tagoption1 = 0;
01456 //    int tagoption2 = 0;
01457 //    int tagoption3 = 0;
01458 //    int tagoption4 = 0;
01459 //    screen_1(color, bright, tagoption1, tagoption2, tagoption3, tagoption4);                            // paint screen
01460 //    /* the demo is updating the screen in a endless loop */
01461 //    
01462 //    Timer t1;
01463 //    t1.start();
01464 //    t1.reset();
01465 //    
01466 //    tagoption1 = 0;
01467 //    tagoption2 = 0;
01468 //    tagoption3 = 0;
01469 //    tagoption4 = 0;
01470 ////    int tagvalOld = -1;
01471 //     tagvalOld = -1;
01472 //    while(1) {
01473 //        ft_uint8_t tagval = 0;
01474 //        TrackRegisterVal = TFT.Rd32(REG_TRACKER);       // check if one of the tracking fields is touched
01475 //        tagval = TrackRegisterVal & 0xff;
01476 //        if(tagval != 0) {                               // touch -> get new values
01477 //            if (tagval != tagvalOld) {
01478 //                printf("t %d\n", tagval);
01479 //                tagvalOld = tagval;
01480 //            }
01481 //            if(tagval == 1) {                           // the dial touched
01482 //                color = TrackRegisterVal>>16;           // get the new value
01483 //            }
01484 //            else if(tagval == 2) {                    // the slider is touched
01485 //                bright = TrackRegisterVal>>16;          // get new slider value
01486 //                bright = bright * 255/65536;            // scale it down to 255
01487 //                TFT.SetBacklight(bright); // Brightness
01488 //            }
01489 //            else if(tagval == 3) {                    // the button is touched
01490 ////                TFT.SetBacklight(63); // Brightness
01491 //                tagoption1 = OPT_FLAT;
01492 //                bright = 64;
01493 //                TFT.SetBacklight(bright); // Brightness
01494 //            }
01495 //            else if(tagval == 4) {                    // the button is touched
01496 ////                TFT.SetBacklight(63); // Brightness
01497 //                tagoption2 = OPT_FLAT;
01498 //                bright = 128;
01499 //                TFT.SetBacklight(bright); // Brightness
01500 //            }
01501 //            else if(tagval == 5) {                    // the button is touched
01502 ////                TFT.SetBacklight(63); // Brightness
01503 //                tagoption3 = OPT_FLAT;
01504 //                bright = 192;
01505 //                TFT.SetBacklight(bright); // Brightness
01506 //            }
01507 //            else if(tagval == 8) {                    // the button is touched
01508 ////                TFT.SetBacklight(63); // Brightness
01509 ////                tagoption2 = OPT_FLAT;
01510 //                bright = 171;
01511 //                TFT.SetBacklight(bright); // Brightness
01512 //            }
01513 //            else if(tagval == 10) {                    // the button is touched
01514 ////                TFT.SetBacklight(63); // Brightness
01515 ////                tagoption3 = OPT_FLAT;
01516 //                bright = 212;
01517 //                TFT.SetBacklight(bright); // Brightness
01518 //            }
01519 //            else if(tagval == 11) {                    // the button is touched
01520 ////                TFT.SetBacklight(63); // Brightness
01521 ////                tagoption3 = OPT_FLAT;
01522 //                tagoption4 = OPT_FLAT;
01523 //                bright = 230;
01524 //                TFT.SetBacklight(bright); // Brightness
01525 //            }
01526 //            screen_1(color, bright, tagoption1, tagoption2, tagoption3, tagoption4);                    // paint new screen
01527 //            TFT.Sleep(10);                              // wait 10ms for next check
01528 //        }
01529 //        else
01530 //        {
01531 //            tagvalOld = -1;
01532 ////            printf("Tagval %d, tagoption %d\n", tagval, tagoption);
01533 //            if (tagoption1 != 0)
01534 //            {
01535 //                tagoption1 = 0;
01536 //                screen_1(color, bright, tagoption1, tagoption2, tagoption3, tagoption4);                    // paint new screen
01537 //                TFT.Sleep(10);                              // wait 10ms for next check
01538 //            }
01539 //            if (tagoption2 != 0)
01540 //            {
01541 //                tagoption2 = 0;
01542 //                screen_1(color, bright, tagoption1, tagoption2, tagoption3, tagoption4);                    // paint new screen
01543 //                TFT.Sleep(10);                              // wait 10ms for next check
01544 //            }
01545 //            if (tagoption3 != 0)
01546 //            {
01547 //                tagoption3 = 0;
01548 //                screen_1(color, bright, tagoption1, tagoption2, tagoption3, tagoption4);                    // paint new screen
01549 //                TFT.Sleep(10);                              // wait 10ms for next check
01550 //            }
01551 //            if (tagoption4 != 0)
01552 //            {
01553 //                tagoption4 = 0;
01554 //                screen_1(color, bright, tagoption1, tagoption2, tagoption3, tagoption4);                    // paint new screen
01555 //                TFT.Sleep(10);                              // wait 10ms for next check
01556 //            }
01557 //        }
01558 //    }  // end of display loop
01559 //
01560 //    while(1) {
01561 //        myled = !myled; // LED is ON
01562 //        wait(0.5); // 500 ms
01563 //    }
01564 //
01565 //    fs.unmount();
01566 //
01567 //    // Deinitialize the device
01568 //    sd.deinit();
01569 
01570     // Deinitialize the device
01571 //    spif.deinit();
01572 
01573     // Deinitialize the device
01574 //    ee.deinit();
01575 
01576 }