Curtis Mattull
/
PANEL_GUI_hello_world
basic functional test of FT810 LCD via SPI
Diff: main.cpp
- Revision:
- 22:2bdc80e45f3b
- Parent:
- 21:a50739772892
- Child:
- 23:0045679060e3
--- a/main.cpp Wed Sep 07 23:11:49 2016 +0000 +++ b/main.cpp Sat Sep 17 15:07:57 2016 +0000 @@ -1,15 +1,13 @@ /* Title Block -** Project : datalogger_ft810_bitmap_practice +** Project : PANEL_GUI_BASE ** Engineers : Curtis Mattull -** Processor : MK20 +** Processor : MK22 ** Version : 1.0 ** Compiler : mbed -** Date : 7/26/2016 -** Abstract : This program serves as a learning aid to reading/writing to sd card. - Note : Thare are 2 locations to comment for changing lcd screens: - -line __ within main(), variable: display_type - -line 12 of FT_LCD_TYPE.h, definition: beyondtek +** Date : 9/17/2016 +** Abstract : This program serves as a starting point for most applications requiring a touch screen menu. + Note : */ #include "mbed.h" @@ -22,9 +20,7 @@ #include "FATFileSystem.h" #include "DigitalIn.h" #include "nRF24L01P.h" - - -#define TRANSFER_SIZE 4 // The nRF24L01+ supports transfers from 1 to 32 bytes in size +#include "time.h" /************************ function prototypes @@ -81,14 +77,14 @@ /************************ global objects and variables *************************/ +// create an LCD object +FT800 TFT ( PTD6, PTD7, PTD5, PTE0, PTB19, PTA1 ); +// ( mosi, miso, sclk, ss, intr, pd ); - +// create an RF object nRF24L01P RF ( PTD2, PTD3, PTD1, PTD4, PTC11, PTD0); // ( mosi, miso, sck, csn, ce, irq) -// create an LCD object -FT800 TFT ( PTD6, PTD7, PTD5, PTE0, PTB19, PTA1 ); -// ( mosi, miso, sclk, ss, intr, pd ); ////Create an SDFileSystem object SDFileSystem sd ( PTD2, PTD3, PTD1, PTC4, "sd"); @@ -103,12 +99,13 @@ font_title = 31, font_author = 21; -const ft_char8_t text_menu[32] = {"Curt's test software\0"}, - text_a[32] = {"Plot adc\0"}, - text_b[32] = {"Settings\0"}, - text_c[32] = {"Wireless\0"}, +const ft_char8_t text_menu[32] = {"Main Menu\0"}, + text_a[32] = {"A\0"}, + text_b[32] = {"B\0"}, + text_c[32] = {"C\0"}, text_back[32] = {"Back\0"}, - text_author[32] = {"by Curtis Mattull\0"}; + text_author[32] = {"by Curtis Mattull\0"}, + text_time[32] = {"Run time [s]: \0"}; int16_t i = 0x00; static const uint32_t mask_reg_tracker_tag = 0x0000FFFF; @@ -128,8 +125,8 @@ *************************/ int main() { - static const uint8_t display_type = 0x00; //not beyondtek display -// static const uint8_t display_type = 0x01; +// static const uint8_t display_type = 0x00; //not beyondtek display + static const uint8_t display_type = 0x01; uint8_t error[4] = { 0x00, // sd_test error 0x00, // load_bitmap error 0x00, // bitmap write error @@ -146,11 +143,13 @@ // display_message( error[1], "load jpg success!\0", "load jpg failed!\0"); // TFT.Sleep(100); // Wait ___ to show - RF.powerUp(); - RF.setTransferSize( TRANSFER_SIZE ); - RF.setReceiveMode(); - RF.enable(); - +// RF.powerUp(); +// RF.setTransferSize( TRANSFER_SIZE ); +// RF.setReceiveMode(); +// RF.enable(); + + set_time(0); // Set RTC time to 0 + //draw initial screen main_menu(0x0,0x0); //program should not return from gui_manager... @@ -237,7 +236,7 @@ *************************/ void main_menu(uint32_t tracker, uint8_t tag) { -// TFT.Wr16(REG_PWM_DUTY, 100); + time_t seconds = time(NULL); //start new display list TFT.DLstart(); // start a new display command list @@ -276,9 +275,13 @@ TFT.DL(TAG(0)); // assign TAG value 0 to everything else //title text - TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); + TFT.DL(COLOR_RGB(0, 0, 0)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_menu); // draw Text with font 31 + // time + TFT.Text((TFT.DispWidth/4), TFT.DispHeight*7/8, font_title, OPT_CENTERX, text_time); // draw Text with font 31 + TFT.Number((TFT.DispWidth/2), (TFT.DispHeight*7/8),font_title,OPT_CENTERX, seconds); + //author text TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31 @@ -292,67 +295,27 @@ } - /************************ function: mode_a description: draws mode a screen *************************/ void mode_a(uint32_t tracker, uint8_t tag) { - static const uint8_t plot_lookup[32] = {0x0, 0x0, 0x2, 0x3, 0x0, 0x0, 0x1, 0x0, 0x1, 0x1, 0x2, 0x3, 0x1, 0x0, 0x1, 0x1, - 0x2, 0x2, 0x2, 0x3, 0x2, 0x0, 0x1, 0x2, 0x3, 0x3, 0x2, 0x3, 0x3, 0x0, 0x1, 0x3 }; - static const uint8_t col_div = 10, - row_div = 8; - static const uint8_t col_step = (TFT.DispWidth/col_div), - row_step = (TFT.DispHeight/row_div); - int8_t row = 0, - col = 0; - - // array index values: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - // 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}; - static uint8_t plot_state = 0x00, - plot_combo = 0x00; - - plot_combo = ( plot_state << 3) + tag; // concatenate present_state with tag to form combo input - plot_state = plot_lookup[plot_combo]; // based on present state and touch input, update present state //start new display list TFT.DLstart(); // start a new display command list - TFT.DL(CLEAR_COLOR_RGB(0,0,0)); // set the clear color to dark grey + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to dark grey TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer TFT.DL(TAG(0)); // assign TAG value 0 to everything else - //plot grid - TFT.DL(COLOR_RGB(75,75,75)); - TFT.DL(BEGIN(LINES)); - TFT.DL(LINE_WIDTH(1 * 16)); + - //draw plot grid - //draw row lines - for(row = 0;row < row_div-1; row++) - { - TFT.DL(VERTEX2F(0,row_step*16 + row*row_step*16)); - TFT.DL(VERTEX2F(800*16,row_step*16 + row*row_step*16)); - } + - //draw col lines - for(col = 0;col < col_div-1; col++) - { - TFT.DL(VERTEX2F(col_step*16 + col*col_step*16, 0)); - TFT.DL(VERTEX2F(col_step*16 + col*col_step*16, 480*16)); - } + + -// //bitmaps -// TFT.DL(TAG(0)); // assign TAG value 0 to bitmap -// TFT.DL(BITMAP_SOURCE(RAM_G)); -// TFT.DL(BITMAP_LAYOUT(RGB565,x_size*2,y_size)); -// TFT.DL(BITMAP_SIZE(NEAREST,BORDER,BORDER,x_size,y_size)); -// -// TFT.DL(BEGIN(BITMAPS)); //start drawing bitmaps -// TFT.DL(VERTEX2II(10,10,0,0)); // draw logo image with bit handle 0 -// TFT.DL(END()); - - //buttons + //button colors TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF)); //this sets the button text color TFT.FgColor(0x007CC4); // this sets the button color @@ -360,38 +323,13 @@ TFT.Track( 50, 355, 100, 75, 4); // track aree of button back TFT.DL(TAG(4)); TFT.Button(50, 355, 100, 75, font_button, 4, text_back); // assign TAG value 4 to text_back button - - ////plot square button -// TFT.Track( 200, 355, 100, 75, 6); // track aree of button square -// TFT.DL(TAG(6)); -// TFT.Button(200, 355, 100, 75, font_button, 6, "square"); // assign TAG value 1 to text_back button//back button -// -// //plot triangle button -// TFT.Track( 350, 355, 100, 75, 2); // track aree of button triangle -// TFT.DL(TAG(2)); -// TFT.Button(350, 355, 100, 75, font_button, 2, "triangle"); // assign TAG value 2 to text_back button//back button - - //plot sine button - TFT.Track( 500, 355, 100, 75, 3); // track aree of button sine - TFT.DL(TAG(3)); - TFT.Button(500, 355, 100, 75, font_button, 3, "adc in"); // assign TAG value 3 to text_back button//back button + + //title, author text + TFT.DL(TAG(0)); // assign TAG value 0 to everything else + TFT.DL(COLOR_RGB(0, 0, 0)); + TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_a); // draw Text with font 31 + TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); //author text // draw Text with font 31 - //plot nothing button - TFT.Track( 650, 355, 100, 75, 5); // track aree of button square - TFT.DL(TAG(5)); - TFT.Button(650, 355, 100, 75, font_button, 5, "clear"); // assign TAG value 1 to text_back button//back button - - - TFT.DL(TAG(0)); // assign TAG value 0 to everything else - //author text - TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF)); - TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31 - //plot algorithm - // TFT.DL( BEGIN(LINE_STRIP) ); //works okay.. - TFT.DL( BEGIN(LINE_STRIP) ); - - TFT.DL(LINE_WIDTH(3 * 16)); - (*plot[plot_state])(); // use present_state as operand to draw screen function //display the screen TFT.DL(DISPLAY()); // display the image @@ -407,27 +345,15 @@ description: draws mode b screen. *************************/ void mode_b(uint32_t tracker, uint8_t tag) -{ - static uint8_t val = 128; - +{ //start new display list TFT.DLstart(); // start a new display command list TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer -// //bitmaps -// TFT.DL(TAG(0)); // assign TAG value 0 to bitmap -// TFT.DL(BITMAP_SOURCE(RAM_G)); -// TFT.DL(BITMAP_LAYOUT(RGB565,x_size*2,y_size)); -// TFT.DL(BITMAP_SIZE(NEAREST,BORDER,BORDER,x_size,y_size)); -// -// TFT.DL(BEGIN(BITMAPS)); //start drawing bitmaps -// TFT.DL(VERTEX2II(10,10,0,0)); // draw logo image with bit handle 0 -// TFT.DL(END()); - - //buttons - TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF)); //this sets the button text color + //button colors + TFT.DL(COLOR_RGB(255, 255, 255)); //this sets the button text color TFT.FgColor(0x007CC4); // this sets the button color @@ -436,45 +362,10 @@ TFT.DL(TAG(4)); TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button - //backlight slider - TFT.Track( (TFT.DispWidth*1/3), 200, (TFT.DispWidth*1/3), 50, 1); // track aree of backlight slider - TFT.DL(TAG(1)); - TFT.Slider((TFT.DispWidth*1/3), 200, (TFT.DispWidth*1/3), 50,0, val , 128 ); // assign TAG value 5 to text_back button - -//check if slider is touched - if (tag == 1) { - - val = tracker/512; - - //limit the backlight to <91 - // if(val > 90) -// { -// val = 90; -// } - - TFT.Wr16(REG_PWM_DUTY, (val)); - } - - - TFT.DL(TAG(0)); // assign TAG value 0 to bitmap - //backlight text - TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); - TFT.Text((TFT.DispWidth/2), (TFT.DispHeight*5/8), font_button, OPT_CENTERX, "backlight pwm value:"); // draw Text with font 31 - - //sprintf(buffer, "%.1i", val+1); // write val to buffer -// TFT.Text((TFT.DispWidth*3/4)-20, (TFT.DispHeight*5/8), font_title, OPT_CENTERX, buffer); // draw Text with font 31 - - TFT.Number((TFT.DispWidth*3/4)-40, (TFT.DispHeight*5/8)-15,font_title,0, val); - - + //title,author text TFT.DL(TAG(0)); // assign TAG value 0 to everything else - - //title text - TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); + TFT.DL(COLOR_RGB(0, 0, 0)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_b); // draw Text with font 31 - - //author text - TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31 //display the screen @@ -485,52 +376,20 @@ } - /************************ function: mode_c description: draws mode C screen *************************/ void mode_c(uint32_t tracker, uint8_t tag) { - static char rxData[TRANSFER_SIZE]; - static char temp_buffer[TRANSFER_SIZE]; - int rxDataCnt = 0; - - //ISE40 STATUS DISPLAY - static uint16_t data_raw_a9 = 0x0000; -// data_raw_a9 = ((analog_in9.read_u16()>>7) & 0x1FF ); - - // If we've received anything in the nRF24L01+... - if ( RF.readable() ) - { - // ...read the data into the receive buffer - rxDataCnt = RF.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); - - // Display the receive buffer contents via the host serial link - for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) - { - temp_buffer[i] = rxData[i]; - } - } - //start new display list TFT.DLstart(); // start a new display command list - - TFT.DL(TAG(0)); // assign TAG value 0 to everything else - - TFT.DL(CLEAR_COLOR_RGB(0,0xFF,0)); // set the clear color to green + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer - //message text - TFT.DL(COLOR_RGB(0,0,0)); // set text color to white - TFT.Text((TFT.DispWidth/2), (TFT.DispHeight/4), font_title, OPT_CENTERX, "nRF24L01+ 2.4GHz wireless testing"); // draw Text with font 31 - - TFT.Text((TFT.DispWidth/2), (TFT.DispHeight/2), font_title, OPT_CENTERX, temp_buffer); // draw wireless value with font 31 - - - //buttons - TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF)); //this sets the button text color + //button colors + TFT.DL(COLOR_RGB(255, 255, 255)); //this sets the button text color TFT.FgColor(0x007CC4); // this sets the button color //back button @@ -538,9 +397,10 @@ TFT.DL(TAG(4)); TFT.Button(50, 355, 100, 75, font_button, 4, text_back); // assign TAG value 4 to text_back button + //title, author text TFT.DL(TAG(0)); // assign TAG value 0 to everything else - //author text TFT.DL(COLOR_RGB(0,0,0)); + TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_c); // draw Text with font 31 TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31 //display the screen