FRDM-K64F fork of David Smart's RA8875 TFT Display with onscreen QWERTY touch keypad Demo

Dependencies:   Keypad RA8875 SDFileSystem mbed

Fork of RA8875_Demo by FRDM-K64F Code Share

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"           
00003 #include "RA8875.h"         
00004 #include "Keypad.h"
00005 
00006 #include "MyFont18x32.h"
00007 #include "BPG_Arial08x08.h"
00008 #include "BPG_Arial10x10.h"
00009 #include "BPG_Arial20x20.h"
00010 #include "BPG_Arial31x32.h"
00011 #include "BPG_Arial63x63.h"
00012 
00013 #include "SDFileSystem.h" 
00014 #include "FATFileSystem.h" 
00015 
00016 
00017 
00018 //LocalFileSystem local("local");     // Because I want <PrintScreen>
00019 // Localfile system is not avail on K64F, but SD card is.
00020 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
00021 
00022 Serial pc(USBTX, USBRX);            // And a little feedback
00023 
00024 RA8875 lcd(PTD2, PTD3, PTD1, PTD0, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name
00025 Keypad kp(lcd);                                  // Associate Virtual keypad with the RA8875 TFT
00026 
00027 
00028 void CalibrateTS(void)
00029 {
00030     FILE * fh;
00031     tpMatrix_t matrix;
00032     RetCode_t r;
00033  
00034     r = lcd.TouchPanelCalibrate("Calibrate the touch panel", &matrix);
00035     if (r == noerror) {
00036         fh = fopen("/sd/tpcal.cfg", "wb");
00037         if (fh) {
00038             fwrite(&matrix, sizeof(tpMatrix_t), 1, fh);
00039             fclose(fh);
00040         } else {
00041         }
00042     } else {
00043     }
00044 }
00045  
00046  
00047 void InitTS(void)
00048 {
00049     FILE * fh;
00050     tpMatrix_t matrix;
00051  
00052     fh = fopen("/sd/tpcal.cfg", "rb");
00053     if (fh) {
00054         fread(&matrix, sizeof(tpMatrix_t), 1, fh);
00055         fclose(fh);
00056         lcd.TouchPanelSetMatrix(&matrix);
00057         pc.printf("Touch Panel calibration set\r\n");
00058     } else {
00059         CalibrateTS();
00060     }
00061 }
00062  
00063 
00064 int main()
00065 {
00066     char name1[20], name2[20];
00067  
00068     pc.baud(115200);                            
00069     pc.printf("\r\nDev Keypad - Build " __DATE__ " " __TIME__ "\r\n");
00070  
00071     lcd.init();
00072     lcd.foreground(Yellow);
00073     lcd.background(Black);
00074     lcd.puts(0,0, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
00075     InitTS();
00076     while(1) {
00077         lcd.foreground(Yellow);
00078         lcd.background(Black);
00079         lcd.cls();
00080         lcd.puts(0,20, "Enter username and password\r\n");
00081         if (kp.GetString(name1, 20, "Username:")) {
00082      pc.printf("PrintScreen activated ...\r\n");
00083     RetCode_t r = lcd.PrintScreen(0,0,480,272,"/sd/file2.bmp");
00084     pc.printf("  PrintScreen returned %d\r\n", r);
00085             lcd.printf("username: %s\r\n", name1);
00086              if (kp.GetString(name2, 20, "Password:", '*')) {
00087                 lcd.printf("password: %s\r\n", name2);
00088                 kp.Erase();
00089                 lcd.foreground(BrightRed);
00090                 lcd.background(Black);
00091                 lcd.cls();
00092                 lcd.SetTextFontSize(2);
00093                 lcd.SetTextCursor(0,30);
00094                 lcd.printf("username: %s\r\npassword: %s\r\n", name1, name2);
00095                 lcd.SetTextFontSize();
00096                 
00097                
00098             }
00099         } else {
00100             kp.Erase();
00101             pc.printf("<esc>\r\n");
00102         }
00103         wait(5);
00104     }
00105 }
00106