Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: RA8875 SDFileSystem mbed
main.cpp
00001 // MW771 Laser Press HMI. 00002 // V.Nemera, 10/07/2016, ver.1.0, C++ 00003 // CPU: mbed NXP LPC1768 (ARM Cortex-M3, 32bit, 90MHz) 00004 //#pragma once 00005 #include "mbed.h" 00006 #include "RA8875.h" 00007 #include "MyFont18x32.h" 00008 #include "BPG_Arial08x08.h" 00009 #include "BPG_Arial10x10.h" 00010 #include "BPG_Arial20x20.h" 00011 #include "BPG_Arial31x32.h" 00012 #include "BPG_Arial63x63.h" 00013 #include "SDFileSystem.h" 00014 #include "stdint.h" 00015 #include <string> 00016 using std::string; 00017 00018 #include "main.h" 00019 #include "comm.h" 00020 00021 int a7, b7, c7, d7; 00022 00023 DigitalOut led1(LED1); 00024 DigitalOut led2(LED2); 00025 DigitalOut led3(LED3); 00026 DigitalOut led4(LED4); 00027 00028 int iLed; 00029 00030 Serial pc(USBTX, USBRX); // pc feedback 00031 00032 extern void main_cycle_add(void); 00033 extern void initHMIio(void); 00034 extern int SetLasComm(int icLC); 00035 extern void flipRS(void); 00036 00037 // These two defines can be enabled, or commented out 00038 #define BIG_SCREEN 00039 //#define CAP_TOUCH 00040 #define LCD_C 16 // color - bits per pixel 00041 00042 #ifdef CAP_TOUCH 00043 RA8875 lcd(p5, p6, p7, p8, NC, p11,p12,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name 00044 #else 00045 RA8875 lcd(p5, p6, p7, p8, NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name 00046 //LocalFileSystem local ("sd"); // access to calibration file for resistive touch. 00047 #endif 00048 00049 #define PC_BAUD 115200 // I like the serial communications to be fast 00050 00051 #ifdef BIG_SCREEN 00052 #define LCD_W 800 00053 #define LCD_H 480 00054 #define DEF_RADIUS 50 // default radius of the fingerprint 00055 #define BL_NORM 25 // Backlight Normal setting (0 to 255) 00056 #else 00057 #define LCD_W 480 00058 #define LCD_H 272 00059 #define DEF_RADIUS 20 // default radius of the fingerprint 00060 #define BL_NORM 25 // Backlight Normal setting (0 to 255) 00061 #endif 00062 00063 #define Gray (color_t)(RGB(187,187,187)) 00064 00065 color_t fingerColor[5] = {Blue, Red, Green, Yellow, Magenta}; 00066 point_t last[5]; // space for tracking 5 touches 00067 int layer = 0; 00068 00069 00070 //SDFileSystem(mosi,miso,sclk,cs,name,cd, SwitchType, int hz); 00071 SDFileSystem sd(p5, p6, p7, p29, "sd", p30, SDFileSystem::SWITCH_NEG_NO, 8000000); 00072 00073 int iPC; 00074 char bufferNL[512]; 00075 //const char *rDr = "/"; 00076 char *rDr = "/"; 00077 00078 Ticker tickRS; //rs232 pc, io, laser 00079 timestamp_t tickTime = 2048; // ticker interval in microSec 00080 00081 //Timer IOwait; //timeout for IO controller RS232 connection 00082 int usMeasure; 00083 00084 point_t lastTP; 00085 00086 const char *cPN[8]; 00087 const char *cWM[3]; 00088 //--------------------------------------------------------------------------------- 00089 TextBox txtBox[] = { 00090 { 290, 15, 348, 57, 310, 20, Gray, Black, "1"}, 00091 { 350, 15, 408, 57, 370, 20, Gray, Black, "2"}, 00092 { 410, 15, 468, 57, 430, 20, Gray, Black, "3"}, 00093 { 470, 15, 528, 57, 490, 20, Gray, Black, "4"}, 00094 { 530, 15, 588, 57, 550, 20, Gray, Black, "5"}, 00095 { 590, 15, 648, 57, 610, 20, Gray, Black, "6"}, 00096 { 650, 15, 708, 57, 670, 20, Gray, Black, "7"}, 00097 { 710, 15, 768, 57, 730, 20, Gray, Black, "8"}, 00098 { 290, 70, 408, 112, 300, 75, Gray, Black, "Circle"}, 00099 { 410, 70, 528, 112, 420, 75, Gray, Black, "Eight"}, 00100 { 530, 70, 648, 112, 540, 75, Gray, Black, "Infinity"} 00101 }; 00102 int TextBoxSize = 11; 00103 int progNumber = 0; //program# 0..7 00104 int wobbleMode = 0; //wobble mode 00105 int Lmode = 0; //laser mode 00106 00107 ProgPar prPar[] = { //default (init) parameters 00108 { 0, 10, 50, 0, 100, 100, 1, 4, 230, 500, 4}, 00109 { 0, 20, 80, 0, 200, 50, 2, 5, 200, 1000, 7}, 00110 { 0, 30, 90, 0, 400, 25, 3, 3, 100, 1500, 1}, 00111 { 0, 40, 100, 0, 500, 10, 4, 5, 50, 1600, 3}, 00112 { 1, 50, 70, 1, 100, 8, 1, 5, 250, 1100, 9}, 00113 { 1, 60, 100, 1, 200, 5, 2, 5, 180, 800, 5}, 00114 { 2, 70, 75, 1, 400, 10, 1, 3, 120, 600, 7}, 00115 { 2, 80, 85, 1, 500, 9, 3, 5, 240, 750, 21} 00116 }; 00117 char nCh[] = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}; 00118 00119 TextBoxR txtBoxR[] = { 00120 { 290, 125, 380, 167, 10, 8, 320, 130, Gray, Black, "10"}, //LPbeg 00121 { 470, 125, 560, 167, 10, 8, 500, 130, Gray, Black, "100"}, //LPend 00122 { 650, 125, 768, 167, 10, 8, 660, 130, Gray, Black, "CW"}, //Lmode 00123 { 290, 180, 380, 222, 10, 8, 320, 185, Gray, Black, "500"}, //Lfreq 00124 { 470, 180, 560, 222, 10, 8, 500, 185, Gray, Black, "10"}, //Lpulse 00125 { 290, 235, 380, 277, 10, 8, 320, 240, Gray, Black, "20"}, //amplBeg 00126 { 470, 235, 560, 277, 10, 8, 500, 240, Gray, Black, "50"}, //amplEnd 00127 { 290, 290, 380, 332, 10, 8, 320, 295, Gray, Black, "250"}, //wobFreq 00128 { 290, 345, 380, 387, 10, 8, 310, 350, Gray, Black, "1500"}, //wobtime 00129 { 470, 345, 560, 387, 10, 8, 500, 350, Gray, Black, "4"}, //amplNum 00130 { 200, 410, 600, 452, 10, 8, 210, 415, Gray, Green, "R E A D Y"}, //status line 00131 { 625, 253, 775, 343, 5, 3, 635, 283, Yellow, Black, " E D I T"}, //edit btn 00132 { 625, 365, 775, 455, 5, 3, 635, 395, Yellow, Black, " M A I N"} //main btn 00133 }; 00134 int TextBoxRSize = 13; 00135 int numTPstatus = 10; // # txtBoxR[10] for status line 00136 int numTPeditBtn = 11; // # txtBoxR[11] for edit btn 00137 int numTPmainBtn = 12; // # txtBoxR[12] for main btn 00138 int numTPvalBtn = 11; // # txtBoxR[11] for values btn 00139 int numTPservBtn = 12; // # txtBoxR[12] for service btn 00140 int numPrPar = 10; // # of integer programm parameters 00141 int numLmode = 2; // # of Lmode parameter 00142 00143 int flagParChanged = 0; 00144 int flagLrsConnected = 0; 00145 int flagLcomProcess = 0; 00146 int flagWeld = 0; //welding in progress 00147 int TPmode = 0; //0-Operate mode, 1-Edit mode, 2-Service mode 00148 int editBtnMode = 0; //0-edit, 1-set 00149 int TPstatus = 0; //index Stat[] 00150 char sTatus[32]; 00151 00152 // Status reported by controller 00153 TPstring Stat[] = {"R E A D Y", //status 0 00154 "IO NOT READY", //status 1 00155 "E-STOP ON", //status 2 00156 "LASER POWER OFF", //status 3 00157 "LASER NOT READY", //status 4 00158 "LASER RS232 NOT READY", //status 5 00159 "SHORT IO COMMAND", //status 6 00160 "WRONG IO COMMAND", //status 7 00161 "", //status 8 00162 "", //status 9 00163 "", //status 10 (do not change it) 00164 "LASER DOES NOT ANSWER", //error 11 00165 "LASER COMMAND ERROR", //error 12 00166 "", //error 13 00167 "", //status 14 00168 "", //status 15 00169 "READY FOR WELDING", //status 16 00170 "WOBBLE HEAD INIT...", //status 17 00171 "WOBBLE HEAD ERROR", //status 18 00172 "IO CONTROLLER ERROR", //status 19 00173 "WELDING IN PROGRESS..", //status 20 00174 "", //status 21 (auto reset e-stop) 00175 }; 00176 int indStat = 0; 00177 00178 // Errors reported by controller 00179 TPstring fErr[] = {"Done!", 00180 "Write error!", 00181 "Failed to close file!", 00182 "Failed to create file!", 00183 "Failed to open file!", 00184 "No card present!", 00185 "Failed mount SD!"}; 00186 //Numpad screen label 00187 TPstring Labels[] = {"Laser power [%] beg", 00188 "Laser power [%] end", 00189 "Laser mode", 00190 "Laser frequency [Hz]", 00191 "Laser pulse length [%]", 00192 "Amplitude [0.1mm] beg.", 00193 "Amplitude [0.1mm] end", 00194 "Wobble frequency [Hz]", 00195 "Welding time [mS]", 00196 "# of amplitude steps", 00197 "File p#"}; 00198 int LabelsIndex = 0; 00199 00200 TextBox txtBoxNP[] = { 00201 { 656, 166, 776, 261, 706, 186, Gray, Black, "0"}, 00202 { 290, 360, 410, 455, 340, 380, Gray, Black, "1"}, 00203 { 412, 360, 532, 455, 462, 380, Gray, Black, "2"}, 00204 { 534, 360, 654, 455, 584, 380, Gray, Black, "3"}, 00205 { 290, 263, 410, 358, 340, 283, Gray, Black, "4"}, 00206 { 412, 263, 532, 358, 462, 283, Gray, Black, "5"}, 00207 { 534, 263, 654, 358, 584, 283, Gray, Black, "6"}, 00208 { 290, 166, 410, 261, 340, 186, Gray, Black, "7"}, 00209 { 412, 166, 532, 261, 462, 186, Gray, Black, "8"}, 00210 { 534, 166, 654, 261, 584, 186, Gray, Black, "9"}, 00211 { 656, 263, 776, 358, 706, 283, Gray, Black, "."}, 00212 { 656, 360, 776, 455, 680, 380, Gray, Black, "BACK"}, 00213 { 656, 69, 776, 164, 695, 89, Gray, Black, "OK"} 00214 }; 00215 int TextBoxNPSize = 13; 00216 int NPinp = 0; 00217 bool flagNPinp = false; 00218 00219 int LPscreen = 0; //0-values, 1-numpad, 2-sevice, 3-main screen 00220 00221 TextBoxR txtBNP = { 300, 120, 640, 162, 10, 8, 320, 130, Gray, Black, ""}; 00222 00223 MinMax miMa[] = { 00224 { 0, 100}, //0-LPbeg 00225 { 0, 100}, //1-LPend 00226 { 0, 1}, //2 00227 { 1, 1000}, //3-Lfreq 00228 { 1, 100}, //4-Lpulse 00229 { 0, 90}, //5-amplBeg 00230 { 0, 90}, //6-amplEnd 00231 { 1, 100}, //7-wFreq 00232 { 1, 5000}, //8-wTime 00233 { 1, 100}, //9-amplNum 00234 { 0, 99} //10-file p# 00235 }; 00236 int miMaSize = 9; 00237 00238 IOPar ioPar; //io controller parameters 00239 00240 //------service------------------------- 00241 TextBoxR txtRServ[] = { 00242 { 625, 365, 775, 455, 10, 8, 650, 395, Yellow, Black, "M A I N"}, //btn main 00243 { 625, 276, 775, 346, 10, 8, 650, 296, Yellow, Black, "S A V E"}, //btn save 00244 { 625, 196, 775, 266, 10, 8, 650, 216, Yellow, Black, "L O A D"}, //btn load 00245 { 625, 116, 775, 186, 10, 8, 650, 136, Yellow, Black, " D I R"}, //btn dir 00246 { 715, 26, 775, 86, 10, 8, 725, 40, Gray, Black, "0"}, //file # 00247 }; 00248 int txtRServSize = 5; 00249 int fileNum = 0; 00250 00251 TextBox txtBoxDir[] = { 00252 { 20, 54, 400, 91, 25, 58, Gray, Black, " "}, 00253 { 20, 93, 400, 130, 25, 97, Gray, Black, " "}, 00254 { 20, 132, 400, 169, 25, 136, Gray, Black, " "}, 00255 { 20, 171, 400, 208, 25, 175, Gray, Black, " "}, 00256 { 20, 210, 400, 247, 25, 214, Gray, Black, " "}, 00257 { 20, 249, 400, 286, 25, 253, Gray, Black, " "}, 00258 { 20, 288, 400, 325, 25, 292, Gray, Black, " "}, 00259 { 20, 327, 400, 364, 25, 331, Gray, Black, " "}, 00260 { 20, 366, 400, 403, 25, 370, Gray, Black, " "} 00261 }; 00262 int TextBoxDirSize = 9; 00263 00264 TextBoxR txtRdir[] = { 00265 { 410, 20, 560, 110, 10, 8, 425, 48, Yellow, Black, "SPLASH"}, //btn splash 00266 { 410, 210, 560, 300, 10, 8, 450, 238, Yellow, Black, " UP"}, //btn up 00267 { 410, 310, 560, 400, 10, 8, 440, 338, Yellow, Black, " DOWN"}, //btn down 00268 }; 00269 int txtRdirSize = 3; 00270 //--------------------------------------------------------------------------------- 00271 void flipUS(void) { 00272 NVIC_DisableIRQ(TIMER3_IRQn); //disable timer3 interrupt 00273 flipRS(); 00274 LPC_TIM3->IR |= 1 << 0; // Clear MR0 interrupt flag 00275 NVIC_EnableIRQ(TIMER3_IRQn); //enable timer3 interrupt 00276 } 00277 00278 void writeTestFile(void) 00279 { 00280 //creating a 1MB test file <Test File.bin> 00281 iPC = pc.printf("Write <Test File.bin> from %iB buffer", sizeof(bufferNL)); 00282 FileHandle* file = sd.open("Test File.bin", O_WRONLY | O_CREAT | O_TRUNC); 00283 if (file != NULL) { 00284 for (int i = 0; i < (1048576 / sizeof(bufferNL)); i++) { 00285 if (file->write(bufferNL, sizeof(bufferNL)) != sizeof(bufferNL)) { 00286 pc.printf("write error!\n"); 00287 return; 00288 } 00289 } 00290 if (file->close()) 00291 pc.printf("failed to close file!\n"); 00292 else 00293 pc.printf("done!\n"); 00294 } else { 00295 printf("failed to create file!\n"); 00296 } 00297 } 00298 00299 void readTestFile(void) 00300 { 00301 //read buffer from the 1MB file created by writeTest() 00302 pc.printf("Read <Test File.bin> to %iB buffer.. ", sizeof(bufferNL)); 00303 FileHandle* file = sd.open("Test File.bin", O_RDONLY); 00304 if (file != NULL) { 00305 file->read(bufferNL, sizeof(bufferNL)); 00306 if (file->close()) 00307 pc.printf("failed to close file!\n"); 00308 else 00309 pc.printf("done!\n"); 00310 } 00311 else { 00312 pc.printf("failed to open file!\n"); 00313 } 00314 } 00315 00316 void fillTestBuffer(void){ 00317 for (int i = 0; i < 40; i++) {bufferNL[i] = (char)48;} 00318 for (int i = 0; i < 440; i++) {bufferNL[i+40] = (char)49;} 00319 for (int i = 0; i < 60; i++) {bufferNL[i+440] = (char)48;} 00320 00321 for (int i = 0; i < 10; i++) { 00322 for (int j = 0; j < 50; j++) { 00323 pc.printf("%c",bufferNL[i * 50 + j]); 00324 } 00325 pc.printf("\n"); 00326 } 00327 } 00328 00329 int connectSD(void){ 00330 //Make sure a card is present 00331 if (!sd.card_present()) { 00332 pc.printf("\nNo card present!\n"); 00333 return 1; 00334 } 00335 //Try to mount the SD card 00336 //pc.printf("\nMounting SD card..."); //%u", aaa); 00337 if (sd.mount() != 0) { 00338 pc.printf("failed mount SD!\n"); 00339 return 2; 00340 } 00341 //pc.printf("success!\n"); 00342 return 0; 00343 } 00344 00345 00346 void disconnectSD(void) { 00347 sd.unmount(); 00348 } 00349 00350 void infoSD(void) 00351 { 00352 //Display the card type 00353 pc.printf("\tCard type: "); 00354 SDFileSystem::CardType cardType = sd.card_type(); 00355 if (cardType == SDFileSystem::CARD_NONE) 00356 pc.printf("None\n"); 00357 else if (cardType == SDFileSystem::CARD_MMC) 00358 pc.printf("MMC\n"); 00359 else if (cardType == SDFileSystem::CARD_SD) 00360 pc.printf("SD\n"); 00361 else if (cardType == SDFileSystem::CARD_SDHC) 00362 pc.printf("SDHC\n"); 00363 else 00364 pc.printf("Unknown\n"); 00365 //Display the card capacity 00366 pc.printf("\tSectors: %u\n", sd.disk_sectors()); 00367 pc.printf("\tCapacity: %.1fMB\n", sd.disk_sectors() / 2048.0); 00368 } 00369 00370 bool readDirSD(char *pDr) 00371 { 00372 bool result = true; 00373 DIR *dir; 00374 struct dirent *ent; 00375 //pc.printf("D- %i\n", pDr); 00376 if ((dir = sd.opendir (pDr)) != NULL) { 00377 // print all the files and directories within directory 00378 while ((ent = readdir (dir)) != NULL) { 00379 pc.printf("%s\r\n", ent->d_name); 00380 } 00381 closedir (dir); 00382 } else { 00383 // could not open directory 00384 pc.printf("Could not open directory"); 00385 result = false; 00386 } 00387 return !result; 00388 } 00389 00390 char dirName[40][40]; 00391 int indName = 0; 00392 string dirS; 00393 00394 bool readDirHmiSD(char *pDr) 00395 { 00396 bool result = true; 00397 DIR *dir; 00398 struct dirent *ent; 00399 if ((dir = sd.opendir (pDr)) != NULL) { 00400 dirS.assign(pDr); 00401 // copy all the files and directories within directory 00402 indName = 0; 00403 while ((ent = readdir (dir)) != NULL) { 00404 strcpy(dirName[indName++], ent->d_name); 00405 } 00406 closedir (dir); 00407 } else { 00408 // could not open directory 00409 pc.printf("Could not open directory"); 00410 result = false; 00411 } 00412 return !result; 00413 } 00414 //ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 00415 int bufferPar[128]; 00416 00417 void saveBufferPar(void){ 00418 //clean bufferPar[] 00419 for (int i = 0; i < 128; i++) { 00420 bufferPar[i] = 0; 00421 } 00422 //save parameters in bufferPar 00423 for (int i = 0; i < 8; i++) { 00424 bufferPar[i*16] = prPar[i].wMode; 00425 bufferPar[i*16+1] = prPar[i].LPbeg; 00426 bufferPar[i*16+2] = prPar[i].LPend; 00427 bufferPar[i*16+3] = prPar[i].Lmode; 00428 bufferPar[i*16+4] = prPar[i].Lfreq; 00429 bufferPar[i*16+5] = prPar[i].Lpulse; 00430 bufferPar[i*16+6] = prPar[i].amplBeg; 00431 bufferPar[i*16+7] = prPar[i].amplEnd; 00432 bufferPar[i*16+8] = prPar[i].wFreq; 00433 bufferPar[i*16+9] = prPar[i].wTime; 00434 bufferPar[i*16+10] = prPar[i].amplNum; 00435 } 00436 //print bufferPar 00437 // /* 00438 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16]);} 00439 pc.printf("wMode\n"); 00440 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+1]);} 00441 pc.printf("LPbeg\n"); 00442 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+2]);} 00443 pc.printf("LPend\n"); 00444 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+3]);} 00445 pc.printf("Lmode\n"); 00446 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+4]);} 00447 pc.printf("Lfreq\n"); 00448 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+5]);} 00449 pc.printf("Lpulse\n"); 00450 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+6]);} 00451 pc.printf("amplBeg\n"); 00452 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+7]);} 00453 pc.printf("amplEnd\n"); 00454 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+8]);} 00455 pc.printf("wFreq\n"); 00456 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+9]);} 00457 pc.printf("wTime\n"); 00458 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+10]);} 00459 pc.printf("amplNum\n"); 00460 for (int j = 0; j < 8; j++) {pc.printf("%i ",bufferPar[j * 16+11]);} 00461 pc.printf("\n"); 00462 // */ 00463 } 00464 00465 void readBufferPar(void){ 00466 //save parameters in prPar 00467 for (int i = 0; i < 8; i++) { 00468 if(bufferPar[i*16] < 0) bufferPar[i*16] = 0; 00469 if(bufferPar[i*16] > 2) bufferPar[i*16] = 2; 00470 prPar[i].wMode = bufferPar[i*16]; 00471 if(bufferPar[i*16+1] < miMa[0].min) bufferPar[i*16+1] = miMa[0].min; 00472 if(bufferPar[i*16+1] > miMa[0].max) bufferPar[i*16+1] = miMa[0].max; 00473 prPar[i].LPbeg = bufferPar[i*16+1]; 00474 if(bufferPar[i*16+2] < miMa[1].min) bufferPar[i*16+2] = miMa[1].min; 00475 if(bufferPar[i*16+2] > miMa[1].max) bufferPar[i*16+2] = miMa[1].max; 00476 prPar[i].LPend = bufferPar[i*16+2]; 00477 if(bufferPar[i*16+3] < miMa[2].min) bufferPar[i*16+3] = miMa[2].min; 00478 if(bufferPar[i*16+3] > miMa[2].max) bufferPar[i*16+3] = miMa[2].max; 00479 prPar[i].Lmode = bufferPar[i*16+3]; 00480 if(bufferPar[i*16+4] < miMa[3].min) bufferPar[i*16+4] = miMa[3].min; 00481 if(bufferPar[i*16+4] > miMa[3].max) bufferPar[i*16+4] = miMa[3].max; 00482 prPar[i].Lfreq = bufferPar[i*16+4]; 00483 if(bufferPar[i*16+5] < miMa[4].min) bufferPar[i*16+5] = miMa[4].min; 00484 if(bufferPar[i*16+5] > miMa[4].max) bufferPar[i*16+5] = miMa[4].max; 00485 prPar[i].Lpulse = bufferPar[i*16+5]; 00486 if(bufferPar[i*16+6] < miMa[5].min) bufferPar[i*16+6] = miMa[5].min; 00487 if(bufferPar[i*16+6] > miMa[5].max) bufferPar[i*16+6] = miMa[5].max; 00488 prPar[i].amplBeg = bufferPar[i*16+6]; 00489 if(bufferPar[i*16+7] < miMa[6].min) bufferPar[i*16+7] = miMa[6].min; 00490 if(bufferPar[i*16+7] > miMa[6].max) bufferPar[i*16+7] = miMa[6].max; 00491 prPar[i].amplEnd = bufferPar[i*16+7]; 00492 if(bufferPar[i*16+8] < miMa[7].min) bufferPar[i*16+8] = miMa[7].min; 00493 if(bufferPar[i*16+8] > miMa[7].max) bufferPar[i*16+8] = miMa[7].max; 00494 prPar[i].wFreq = bufferPar[i*16+8]; 00495 if(bufferPar[i*16+9] < miMa[8].min) bufferPar[i*16+9] = miMa[8].min; 00496 if(bufferPar[i*16+9] > miMa[8].max) bufferPar[i*16+9] = miMa[8].max; 00497 prPar[i].wTime = bufferPar[i*16+9]; 00498 if(bufferPar[i*16+10] < miMa[9].min) bufferPar[i*16+10] = miMa[9].min; 00499 if(bufferPar[i*16+10] > miMa[9].max) bufferPar[i*16+10] = miMa[9].max; 00500 prPar[i].amplNum = bufferPar[i*16+10]; 00501 } 00502 //print prPar 00503 // /* 00504 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].wMode);} 00505 pc.printf("wMode\n"); 00506 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].LPbeg);} 00507 pc.printf("LPbeg\n"); 00508 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].LPend);} 00509 pc.printf("LPend\n"); 00510 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].Lmode);} 00511 pc.printf("Lmode\n"); 00512 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].Lfreq);} 00513 pc.printf("Lfreq\n"); 00514 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].Lpulse);} 00515 pc.printf("Lpulse\n"); 00516 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].amplBeg);} 00517 pc.printf("amplBeg\n"); 00518 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].amplEnd);} 00519 pc.printf("amplEnd\n"); 00520 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].wFreq);} 00521 pc.printf("wFreq\n"); 00522 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].wTime);} 00523 pc.printf("wTime\n"); 00524 for (int j = 0; j < 8; j++) {pc.printf("%i ",prPar[j].amplNum);} 00525 pc.printf("amplNum\n"); 00526 // */ 00527 } 00528 00529 char fileN[20]; 00530 int errOK; 00531 00532 int wrFile(char *fName) 00533 { 00534 errOK = connectSD(); 00535 if(errOK == 0) { 00536 FileHandle* file = sd.open(fName, O_WRONLY | O_CREAT | O_TRUNC); 00537 if (file != NULL) { 00538 if (file->write(bufferPar, sizeof(bufferPar)) != sizeof(bufferPar)) { 00539 pc.printf("write error!\n"); 00540 errOK = 1; 00541 } 00542 if (file->close()) { 00543 pc.printf("failed to close file!\n"); 00544 errOK = 2; 00545 } 00546 else { 00547 pc.printf("done!\n"); 00548 errOK = 0; 00549 } 00550 } 00551 else { 00552 printf("failed to create file!\n"); 00553 errOK = 3; 00554 } 00555 disconnectSD(); 00556 } 00557 else {errOK = errOK + 4;} 00558 return errOK; 00559 } 00560 00561 int writeIniFile(void) 00562 { 00563 for (int i = 0; i < 128; i++) {bufferPar[i] = 0;} //clean bufferPar[] 00564 bufferPar[0] = fileNum; 00565 bufferPar[1] = progNumber; 00566 00567 sprintf(fileN, "p.ini"); 00568 pc.printf("%s\n", fileN); 00569 00570 int resp = wrFile(fileN); 00571 return resp; 00572 } 00573 00574 int writeParFile(int numP) 00575 { 00576 saveBufferPar(); 00577 00578 sprintf(fileN, "p%i.par", numP); 00579 pc.printf("%s\n", fileN); 00580 00581 int resp = wrFile(fileN); 00582 if(resp == 0) {resp = writeIniFile();} 00583 return resp; 00584 } 00585 00586 int rdFile(char *fName) 00587 { 00588 errOK = connectSD(); 00589 if(errOK == 0) { 00590 FileHandle* file = sd.open(fName, O_RDONLY); 00591 if (file != NULL) { 00592 file->read(bufferPar, sizeof(bufferPar)); 00593 if (file->close()) { 00594 pc.printf("failed to close file!\n"); 00595 errOK = 2; 00596 } 00597 else { 00598 pc.printf("done!\n"); 00599 errOK = 0; 00600 } 00601 } 00602 else { 00603 pc.printf("failed to open file!\n"); 00604 errOK = 4; 00605 } 00606 disconnectSD(); 00607 } 00608 else {errOK = errOK + 4;} 00609 return errOK; 00610 } 00611 00612 int readParFile(int numP) 00613 { 00614 sprintf(fileN, "p%i.par", numP); 00615 pc.printf("%s\n", fileN); 00616 00617 int resp = rdFile(fileN); 00618 if(resp == 0) { 00619 readBufferPar(); 00620 resp = writeIniFile(); 00621 } 00622 return resp; 00623 } 00624 00625 void readIniFile(void) 00626 { 00627 sprintf(fileN, "p.ini"); 00628 pc.printf("%s\n", fileN); 00629 00630 int resp = rdFile(fileN); 00631 if(resp == 0) { 00632 if(bufferPar[0] < miMa[10].min) bufferPar[0] = miMa[10].min; 00633 if(bufferPar[0] > miMa[10].max) bufferPar[0] = miMa[10].max; 00634 fileNum = bufferPar[0]; 00635 if(bufferPar[1] < 1) bufferPar[1] = 1; 00636 if(bufferPar[1] > 8) bufferPar[1] = 8; 00637 progNumber = bufferPar[1]; 00638 resp = readParFile(fileNum); 00639 } 00640 } 00641 //ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 00642 00643 //--------------------------------------------- 00644 // When drawing a "fingerprint" under the touch point - the RA8875 00645 // cannot draw an object partially off-screen, so this shrinks the 00646 // fingerprint as the touch approaches the edge of the screen. 00647 // 00648 int ComputeRadius(point_t p) 00649 { 00650 int radius = DEF_RADIUS; 00651 00652 if (p.x < radius) 00653 radius = p.x; 00654 else if (LCD_W - p.x < radius) 00655 radius = LCD_W - p.x; 00656 if (p.y < radius) 00657 radius = p.y; 00658 else if (LCD_H - p.y < radius) 00659 radius = LCD_H - p.y; 00660 return radius; 00661 } 00662 00663 // Calibrate the resistive touch screen, and store the data on the local file system. 00664 void CalibrateTS(void) 00665 { 00666 tpMatrix_t matrix; 00667 RetCode_t r; 00668 Timer testperiod; 00669 00670 r = lcd.TouchPanelCalibrate("Calibrate the touch panel", &matrix); 00671 if (r == noerror) { 00672 if (connectSD() == 0) { 00673 FileHandle* fh = sd.open("tpcal.cfg", O_WRONLY | O_CREAT | O_TRUNC); 00674 if (fh) { 00675 if (fh->write(&matrix, sizeof(tpMatrix_t)) != sizeof(tpMatrix_t)) 00676 { 00677 pc.printf("write error!\n"); 00678 } 00679 if (fh->close()) pc.printf("failed to close file!\n"); 00680 } 00681 else printf("failed to create tpcal.cfg file!\n"); 00682 } 00683 } 00684 else printf("error TP Calibrate: %d\r\n", r); 00685 disconnectSD(); 00686 pc.printf("TS ok\n"); 00687 lcd.cls(); 00688 } 00689 00690 // Try to load a previous resistive touch screen calibration from storage. If it 00691 // doesn't exist, activate the touch screen calibration process. 00692 void InitTS(void) 00693 { 00694 tpMatrix_t matrix; 00695 if (connectSD() == 0) { 00696 FileHandle* fh = sd.open("tpcal.cfg", O_RDONLY); 00697 if (fh) { 00698 if (fh->read(&matrix, sizeof(tpMatrix_t)) != sizeof(tpMatrix_t)) 00699 { 00700 pc.printf("read error!\n"); 00701 //return; 00702 if (fh->close()) pc.printf("failed to close file!\n"); 00703 } 00704 else 00705 { 00706 lcd.TouchPanelSetMatrix(&matrix); 00707 if (fh->close()) pc.printf("failed to close file!\n"); 00708 disconnectSD(); 00709 pc.printf("ok\n"); 00710 return; 00711 } 00712 } 00713 else printf("failed to open tpcal.cfg file!\n"); 00714 } 00715 disconnectSD(); 00716 CalibrateTS(); 00717 } 00718 00719 //------------------------------------------------------- 00720 void lcd800x480Init(void) 00721 { 00722 lcd.init(LCD_W,LCD_H,LCD_C); 00723 //lcd.init(); 00724 lcd.Backlight(0.5f); 00725 //lcd.Backlight_u8(BL_NORM); 00726 00727 lcd.foreground(RGB(255,255,0)); 00728 lcd.background(RGB(0,0,0)); 00729 00730 lcd.SelectUserFont(BPG_Arial08x08); 00731 lcd.puts(300, 0, "www.ipgphotonics.com\r\n"); 00732 00733 lcd.SelectUserFont(BPG_Arial31x32); 00734 00735 lastTP.x = 0; 00736 lastTP.y = 0; 00737 } 00738 00739 void showTPstatus(int k) 00740 { 00741 int i = numTPstatus; 00742 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 00743 lcd.foreground(txtBoxR[i].textColor); 00744 lcd.background(txtBoxR[i].color); 00745 00746 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, " "); 00747 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, Stat[k]); 00748 //pc.printf("q%i\n", k); 00749 } 00750 00751 void showTPeditBtn(int k) 00752 { 00753 int i = numTPeditBtn; 00754 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 00755 lcd.foreground(txtBoxR[i].textColor); 00756 lcd.background(txtBoxR[i].color); 00757 00758 if(k == 0) {lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, " E D I T");} 00759 else {lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, " S E T");} 00760 } 00761 00762 void showTPmainBtn(void) 00763 { 00764 int i = numTPmainBtn; 00765 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 00766 lcd.foreground(txtBoxR[i].textColor); 00767 lcd.background(txtBoxR[i].color); 00768 00769 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, " M A I N"); 00770 } 00771 00772 void showTPvalBtn(void) 00773 { 00774 int i = numTPvalBtn; 00775 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 00776 lcd.foreground(txtBoxR[i].textColor); 00777 lcd.background(txtBoxR[i].color); 00778 00779 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, " VALUES"); 00780 } 00781 00782 void showTPservBtn(void) 00783 { 00784 int i = numTPservBtn; 00785 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 00786 lcd.foreground(txtBoxR[i].textColor); 00787 lcd.background(txtBoxR[i].color); 00788 00789 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, "SERVICE"); 00790 } 00791 00792 void showProgNum(int i) 00793 { 00794 //pc.printf("%i\n", i); 00795 if((i >= 0) && (i < 8)) { //&& (i != progNumber) ) { 00796 //pc.printf(":\n"); 00797 lcd.fillrect(txtBox[progNumber].x1, txtBox[progNumber].y1, txtBox[progNumber].x2, txtBox[progNumber].y2, txtBox[progNumber].color); 00798 lcd.foreground(txtBox[progNumber].textColor); 00799 lcd.background(txtBox[progNumber].color); 00800 lcd.puts(txtBox[progNumber].textX, txtBox[progNumber].textY, txtBox[progNumber].text); 00801 00802 lcd.fillrect(txtBox[i].x1, txtBox[i].y1, txtBox[i].x2, txtBox[i].y2, Green); 00803 lcd.foreground(txtBox[i].textColor); 00804 lcd.background(Green); 00805 lcd.puts(txtBox[i].textX, txtBox[i].textY, txtBox[i].text); 00806 progNumber = i; 00807 } 00808 } 00809 00810 void showWobMode(int i) 00811 { 00812 if((i >= 0) && (i < 3)) { 00813 //pc.printf(";\n"); 00814 int k; 00815 k = wobbleMode + 8; 00816 lcd.fillrect(txtBox[k].x1, txtBox[k].y1, txtBox[k].x2, txtBox[k].y2, txtBox[k].color); 00817 lcd.foreground(txtBox[k].textColor); 00818 lcd.background(txtBox[k].color); 00819 lcd.puts(txtBox[k].textX, txtBox[k].textY, txtBox[k].text); 00820 k = i + 8; 00821 lcd.fillrect(txtBox[k].x1, txtBox[k].y1, txtBox[k].x2, txtBox[k].y2, Green); 00822 lcd.foreground(txtBox[k].textColor); 00823 lcd.background(Green); 00824 lcd.puts(txtBox[k].textX, txtBox[k].textY, txtBox[k].text); 00825 wobbleMode = i; 00826 } 00827 } 00828 00829 void showWobParam(int i) 00830 { 00831 showWobMode(i); 00832 prPar[progNumber].wMode = i; 00833 } 00834 00835 void showProgParam(int k) 00836 { 00837 showProgNum(k); 00838 //fill round text boxes (TextBoxR) 00839 showWobMode(prPar[progNumber].wMode); 00840 for(int i = 0; i < numPrPar; i++) { 00841 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 00842 lcd.foreground(txtBoxR[i].textColor); 00843 lcd.background(txtBoxR[i].color); 00844 if (i == 2) { 00845 if(prPar[progNumber].Lmode == 0) { 00846 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, "CW"); 00847 if(Lmode == 1) { 00848 Lmode = 0; 00849 if(SetLasComm(33) == 1) {TPstatus = 5;} //DPM -disable pulse mode 00850 else { 00851 if(SetLasComm( 1) == 1) {TPstatus = 5;} //STA -read laser status 00852 else TPstatus = 0; 00853 } 00854 } 00855 } 00856 else if(prPar[progNumber].Lmode == 1) { 00857 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, "PULSE"); 00858 if(Lmode == 0) { 00859 Lmode = 1; 00860 if(SetLasComm(32) == 1) {TPstatus = 5;} //EPM -enable pulse mode 00861 else { 00862 if(SetLasComm( 1) == 1) {TPstatus = 5;} //STA -read laser status 00863 else TPstatus = 0; 00864 } 00865 } 00866 } 00867 } 00868 else { 00869 switch (i) { 00870 case 0: {sprintf(txtBoxR[0].text, "%i", prPar[progNumber].LPbeg); break;} 00871 case 1: {sprintf(txtBoxR[1].text, "%i", prPar[progNumber].LPend); break;} 00872 case 3: {sprintf(txtBoxR[3].text, "%i", prPar[progNumber].Lfreq); break;} 00873 case 4: {sprintf(txtBoxR[4].text, "%i", prPar[progNumber].Lpulse); break;} 00874 case 5: {sprintf(txtBoxR[5].text, "%i", prPar[progNumber].amplBeg); break;} 00875 case 6: {sprintf(txtBoxR[6].text, "%i", prPar[progNumber].amplEnd); break;} 00876 case 7: {sprintf(txtBoxR[7].text, "%i", prPar[progNumber].wFreq); break;} 00877 case 8: {sprintf(txtBoxR[8].text, "%i", prPar[progNumber].wTime); break;} 00878 case 9: {sprintf(txtBoxR[9].text, "%i", prPar[progNumber].amplNum); break;} 00879 } 00880 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, txtBoxR[i].text); 00881 } 00882 } 00883 } 00884 00885 void lcd800x480main(int a) 00886 { 00887 lcd.roundrect( 2,10, 798,478, 10,8, Yellow); //full screen 00888 lcd.fillroundrect(3,11, 797,477, 8,6, Black); //do full screen black 00889 lcd.roundrect( 620,360, 780,460, 10,8, Yellow); //around btn edit 00890 lcd.roundrect( 620,248, 780,348, 10,8, Yellow); //around btn service 00891 lcd.roundrect( 5,62, 615,405, 10,8, Yellow); //picture screen 00892 00893 lcd.foreground(Yellow); 00894 lcd.background(Black); 00895 lcd.puts(100, 20, "Program #"); 00896 lcd.puts(20, 415, "STATUS:"); 00897 00898 //fill text boxes (TextBox) 00899 for(int i = 0; i < 8; i++) { 00900 lcd.fillrect(txtBox[i].x1, txtBox[i].y1, txtBox[i].x2, txtBox[i].y2, txtBox[i].color); 00901 lcd.foreground(txtBox[i].textColor); 00902 lcd.background(txtBox[i].color); 00903 lcd.puts(txtBox[i].textX, txtBox[i].textY, txtBox[i].text); 00904 } 00905 showProgNum(a); 00906 //fill round text boxes (TextBoxR) 00907 00908 } 00909 00910 void lcd800x480val(int a) 00911 { 00912 lcd.roundrect( 2,10, 798,478, 10,8, Yellow); //full screen 00913 lcd.fillroundrect(3,11, 797,477, 8,6, Black); //do full screen black 00914 lcd.roundrect( 620,360, 780,460, 10,8, Yellow); //around btn edit 00915 lcd.roundrect( 620,248, 780,348, 10,8, Yellow); //around btn service 00916 00917 lcd.foreground(Yellow); 00918 lcd.background(Black); 00919 lcd.puts(10, 20, "Program #"); 00920 lcd.puts(10, 75, "Wobble mode"); 00921 lcd.puts(10, 130, "Laser power [%] beg"); 00922 lcd.puts(390, 130, " end"); 00923 lcd.puts(570, 130, "mode"); 00924 lcd.puts(10, 185, "Laser freq.[Hz]"); 00925 lcd.puts(390, 185, "Pulse"); 00926 lcd.puts(575, 185, "[%]"); 00927 lcd.puts(10, 240, "Size [0.1mm] beg."); 00928 lcd.puts(390, 240, " end"); 00929 lcd.puts(10, 295, "Wobble freq.[Hz]"); 00930 lcd.puts(10, 350, "Welding time [mS]"); 00931 lcd.puts(390, 350, "Steps"); 00932 lcd.puts(20, 415, "STATUS:"); 00933 00934 //fill text boxes (TextBox) 00935 for(int i = 0; i < TextBoxSize; i++) { 00936 lcd.fillrect(txtBox[i].x1, txtBox[i].y1, txtBox[i].x2, txtBox[i].y2, txtBox[i].color); 00937 lcd.foreground(txtBox[i].textColor); 00938 lcd.background(txtBox[i].color); 00939 lcd.puts(txtBox[i].textX, txtBox[i].textY, txtBox[i].text); 00940 } 00941 //fill round text boxes (TextBoxR) 00942 showProgParam(a); 00943 } 00944 00945 void lcd800x480NP(int k) 00946 { 00947 lcd.roundrect( 285,65, 781,460, 10,8, Yellow); 00948 lcd.fillroundrect(288,68, 776,455, 5,3, Black); 00949 00950 lcd.foreground(Yellow); 00951 lcd.background(Black); 00952 lcd.puts(300, 75, Labels[k]); 00953 00954 //fill text boxes (TextBox) 00955 for(int i = 0; i < TextBoxNPSize; i++) { 00956 lcd.fillrect(txtBoxNP[i].x1, txtBoxNP[i].y1, txtBoxNP[i].x2, txtBoxNP[i].y2, txtBoxNP[i].color); 00957 lcd.foreground(txtBoxNP[i].textColor); 00958 lcd.background(txtBoxNP[i].color); 00959 lcd.puts(txtBoxNP[i].textX, txtBoxNP[i].textY, txtBoxNP[i].text); 00960 } 00961 //fill round text box 00962 lcd.fillroundrect(txtBNP.x1, txtBNP.y1, txtBNP.x2, txtBNP.y2, txtBNP.r1, txtBNP.r2, txtBNP.color); 00963 lcd.foreground(txtBNP.textColor); 00964 lcd.background(txtBNP.color); 00965 *txtBNP.text = '\0'; 00966 lcd.puts(txtBNP.textX, txtBNP.textY, txtBNP.text); 00967 } 00968 00969 void lcd800x480Serv(void) 00970 { 00971 lcd.roundrect( 2,10, 798,478, 10,8, Yellow); //full screen 00972 lcd.fillroundrect(3,11, 797,477, 8,6, Black); //do full screen black 00973 lcd.roundrect( 620,360, 780,460, 10,8, Yellow); //around main btn 00974 lcd.roundrect( 620,20, 780,348, 10,8, Yellow); //around file btns 00975 lcd.roundrect( 20,418, 600,460, 10,8, Yellow); //around status line 00976 00977 lcd.foreground(Yellow); 00978 lcd.background(Black); 00979 lcd.puts(623, 40, "File p#"); 00980 00981 //fill round text box 00982 int i; 00983 i = txtRServSize-1; 00984 sprintf(txtRServ[i].text, "%i", fileNum); 00985 for(i = 0; i < txtRServSize; i++) { 00986 lcd.fillroundrect(txtRServ[i].x1, txtRServ[i].y1, txtRServ[i].x2, txtRServ[i].y2, txtRServ[i].r1, txtRServ[i].r2, txtRServ[i].color); 00987 lcd.foreground(txtRServ[i].textColor); 00988 lcd.background(txtRServ[i].color); 00989 lcd.puts(txtRServ[i].textX, txtRServ[i].textY, txtRServ[i].text); 00990 } 00991 } 00992 00993 void lcd800x480dirB(void) 00994 { 00995 lcd.fillrect(20, 15, 565, 405, Black); 00996 } 00997 00998 void lcd800x480dir(char *pDr) 00999 { 01000 int i; 01001 01002 lcd.fillrect(20, 15, 565, 405, Black); //clean area 01003 lcd.roundrect(20,15, 400,52, 10,8, Yellow); //around dir name 01004 lcd.roundrect(405,15, 565,405, 10,8, Yellow); //around buttons 01005 01006 lcd.foreground(Yellow); 01007 lcd.background(Black); 01008 lcd.puts(25, 19, rDr); 01009 01010 //fill round text box 01011 for(i = 0; i < txtRdirSize; i++) { 01012 lcd.fillroundrect(txtRdir[i].x1, txtRdir[i].y1, txtRdir[i].x2, txtRdir[i].y2, txtRdir[i].r1, txtRdir[i].r2, txtRdir[i].color); 01013 lcd.foreground(txtRdir[i].textColor); 01014 lcd.background(txtRdir[i].color); 01015 lcd.puts(txtRdir[i].textX, txtRdir[i].textY, txtRdir[i].text); 01016 } 01017 //fill text boxes (TextBox) 01018 for(i = 0; i < TextBoxDirSize; i++) { 01019 lcd.fillrect(txtBoxDir[i].x1, txtBoxDir[i].y1, txtBoxDir[i].x2, txtBoxDir[i].y2, txtBoxDir[i].color); 01020 lcd.foreground(txtBoxDir[i].textColor); 01021 lcd.background(txtBoxDir[i].color); 01022 //lcd.puts(txtBoxDir[i].textX, txtBoxDir[i].textY, txtBoxDir[i].text); 01023 } 01024 } 01025 01026 void showMain(int i) { 01027 lcd800x480main(i); 01028 showTPvalBtn(); 01029 showTPservBtn(); 01030 showTPstatus(TPstatus); 01031 LPscreen = 3; 01032 } 01033 01034 void showVal(int i) { 01035 lcd800x480val(i); 01036 showTPeditBtn(editBtnMode); 01037 showTPmainBtn(); 01038 showTPstatus(TPstatus); 01039 } 01040 01041 void showNP(int i) { 01042 lcd800x480NP(i); 01043 } 01044 01045 void showService(void) { 01046 lcd800x480Serv(); 01047 } 01048 01049 void statServErr(int stS) { 01050 lcd.foreground(Gray); 01051 lcd.background(Black); 01052 lcd.puts(30, 423, " "); 01053 lcd.puts(30, 423, Stat[stS]); 01054 } 01055 01056 void statServ(int stS) { 01057 lcd.foreground(Gray); 01058 lcd.background(Black); 01059 lcd.puts(30, 423, " "); 01060 lcd.puts(30, 423, fErr[stS]); 01061 } 01062 01063 void dirOpenHmi(char *pDr) { 01064 if(connectSD() == 0) { 01065 readDirHmiSD(pDr); 01066 } 01067 disconnectSD(); 01068 01069 lcd800x480dir(rDr); 01070 if(indName > 9) { 01071 for(int i=0; i<9; i++) { 01072 lcd.puts(txtBoxDir[i].textX, txtBoxDir[i].textY, dirName[i]); 01073 } 01074 } 01075 else { 01076 for(int i=0; i<indName; i++) { 01077 lcd.puts(txtBoxDir[i].textX, txtBoxDir[i].textY, dirName[i]); 01078 } 01079 } 01080 for(int i=0; i<indName; i++) { 01081 pc.printf("%s\n", dirName[i]); 01082 } 01083 pc.printf(">>%i\n", indName); 01084 } 01085 01086 int flagDirOpen = 0; 01087 01088 void btnServ(int k) { 01089 int retSt; 01090 switch (k) { 01091 case 0: //btn main 01092 showMain(progNumber); 01093 LPscreen = 3; //main screen 01094 pc.printf("\n>"); 01095 break; 01096 case 1: //btn save 01097 retSt = writeParFile(fileNum); 01098 statServ(retSt); 01099 pc.printf("\ns>%i ", retSt); 01100 break; 01101 case 2: //btn load 01102 retSt = readParFile(fileNum); 01103 statServ(retSt); 01104 pc.printf("\nl>%i ", retSt); 01105 flagParChanged = 0; 01106 break; 01107 case 3: //btn dir 01108 if(flagDirOpen ==0) { 01109 flagDirOpen = 1; 01110 dirOpenHmi(rDr); 01111 } 01112 else { 01113 flagDirOpen = 0; 01114 lcd800x480dirB(); 01115 } 01116 break; 01117 case 4: //txtBox file# 01118 showNP(10); 01119 LabelsIndex = 10; 01120 NPinp = 0; 01121 flagNPinp = false; 01122 LPscreen = 1; //LP screen 01123 01124 pc.printf("\nf "); 01125 break; 01126 } 01127 } 01128 /* 01129 RetCode_t showBitmap(loc_t x, loc_t y, uint32_t fileOffset, FILE * Image) 01130 { 01131 BITMAPINFOHEADER BMP_Info; 01132 RGBQUAD * colorPalette = NULL; 01133 int colorCount; 01134 uint8_t * lineBuffer = NULL; 01135 color_t * pixelBuffer = NULL; 01136 uint16_t BPP_t; 01137 dim_t PixelWidth, PixelHeight; 01138 unsigned int i, offset; 01139 int padd,j; 01140 01141 // Now, Read the bitmap info header 01142 Image->read(&BMP_Info, sizeof(BMP_Info)); 01143 HexDump0("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info)); 01144 BPP_t = BMP_Info.biBitCount; 01145 pc.printf("biBitCount %04X", BPP_t); 01146 if (BPP_t != 1 && BPP_t != 4 && BPP_t != 8 && BPP_t != 16 && BPP_t != 24) { // Support 4, 8, 16, 24-bits per pixel 01147 Image->close(); 01148 pc.printf("not_supported_format"); 01149 return(not_supported_format); 01150 } 01151 if (BMP_Info.biCompression != 0) { // Only the "no comporession" option is supported. 01152 Image->close(); 01153 pc.printf("not_supported_format"); 01154 return(not_supported_format); 01155 } 01156 PixelHeight = BMP_Info.biHeight; 01157 PixelWidth = BMP_Info.biWidth; 01158 pc.printf("(%d,%d) (%d,%d) (%d,%d)", x,y, PixelWidth,PixelHeight, width(), height()); 01159 if (PixelHeight > 340 || PixelWidth > 608 { 01160 Image->close(); 01161 pc.printf("image_too_big"); 01162 return(image_too_big); 01163 } 01164 if (BMP_Info.biBitCount <= 8) { 01165 int paletteSize; 01166 // Read the color palette 01167 colorCount = 1 << BMP_Info.biBitCount; 01168 paletteSize = sizeof(RGBQUAD) * colorCount; 01169 colorPalette = (RGBQUAD *)malloc(paletteSize); 01170 if (colorPalette == NULL) { 01171 Image->close(); 01172 pc.printf("not_enough_ram"); 01173 return(not_enough_ram); 01174 } 01175 Image->read(colorPalette, paletteSize); 01176 HexDump0("Color Palette", (uint8_t *)colorPalette, paletteSize); 01177 } 01178 01179 int lineBufSize = ((BPP_t * PixelWidth + 7)/8); 01180 pc.printf("BPP_t %d, PixelWidth %d, lineBufSize %d", BPP_t, PixelWidth, lineBufSize); 01181 lineBuffer = (uint8_t *)malloc(lineBufSize); 01182 if (lineBuffer == NULL) { 01183 free(colorPalette); 01184 fclose(Image); 01185 return(not_enough_ram); 01186 } 01187 pixelBuffer = (color_t *)malloc(PixelWidth * sizeof(color_t)); 01188 if (pixelBuffer == NULL) { 01189 free(lineBuffer); 01190 if (colorPalette) 01191 free(colorPalette); 01192 Image->close(); 01193 pc.printf("not_enough_ram"); 01194 return(not_enough_ram); 01195 } 01196 01197 padd = (lineBufSize % 4); 01198 if (padd) 01199 padd = 4 - padd; 01200 01201 // Define window for top to bottom and left to right so writing auto-wraps 01202 rect_t restore = windowrect; 01203 window(x,y, PixelWidth,PixelHeight); 01204 SetGraphicsCursor(x, y); 01205 //StartGraphicsStream 01206 WriteCommand(0x40,0x00); // Graphics write mode 01207 WriteCommand(0x02); // Prepare for streaming data 01208 01209 //start_data = BMP_Info.bfOffBits; 01210 //HexDump("Raw Data", (uint8_t *)&start_data, 32); 01211 pc.printf("(%d,%d) (%d,%d), [%d,%d]", x,y, PixelWidth,PixelHeight, lineBufSize, padd); 01212 for (j = PixelHeight - 1; j >= 0; j--) { //Lines bottom up 01213 offset = fileOffset + j * (lineBufSize + padd); // start of line 01214 //fseek(Image, offset, SEEK_SET); 01215 Image->read(lineBuffer, lineBufSize); // read a line - slow ! 01216 //INFO("offset: %6X", offset); 01217 //HexDump("Line", lineBuffer, lineBufSize); 01218 for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT 01219 if (BPP_t == 1) { 01220 uint8_t dPix = lineBuffer[i/8]; 01221 uint8_t bMask = 0x80 >> (i % 8); 01222 uint8_t bit = (bMask & dPix) ? 0 : 1; 01223 //INFO("%02X & %02X ? => %02X", dPix, bMask, bit); 01224 pixelBuffer[i] = RGBQuadToRGB16(colorPalette, bit); 01225 } else if (BPP_t == 4) { 01226 uint8_t dPix = lineBuffer[i/2]; 01227 if ((i & 1) == 0) 01228 dPix >>= 4; 01229 dPix &= 0x0F; 01230 pixelBuffer[i] = RGBQuadToRGB16(colorPalette, dPix); 01231 } else if (BPP_t == 8) { 01232 pixelBuffer[i] = RGBQuadToRGB16(colorPalette, lineBuffer[i]); 01233 } else if (BPP_t == 16) { 01234 pixelBuffer[i] = lineBuffer[i]; 01235 } else if (BPP_t == 24) { 01236 color_t color; 01237 color = RGB(lineBuffer[i*3+2], lineBuffer[i*3+1], lineBuffer[i*3+0]); 01238 pixelBuffer[i] = color; 01239 } 01240 } 01241 pixelStream(pixelBuffer, PixelWidth, x, y++); 01242 } 01243 window(restore); 01244 free(pixelBuffer); // don't leak memory 01245 free(lineBuffer); 01246 if (colorPalette) 01247 free(colorPalette); 01248 return (noerror); 01249 } 01250 01251 static void HexDump0(const char * title, const uint8_t * p, int count) 01252 { 01253 int i; 01254 char buf[100] = "0000: "; 01255 01256 if (*title) 01257 for (i=0; i<count; ) { 01258 sprintf(buf + strlen(buf), "%02X ", *(p+i)); 01259 if ((++i & 0x0F) == 0x00) { 01260 if (i < count) 01261 sprintf(buf, "%04X: ", i); 01262 else 01263 buf[0] = '\0'; 01264 } 01265 } 01266 } 01267 01268 void showPic(void) { 01269 const char Name_BMP[] = "/local/48027224.bmp"; 01270 01271 if (connectSD() == 0) { 01272 FileHandle* fh = sd.open(Name_BMP, O_RDONLY); 01273 if (fh) { 01274 if (fh->read(&BMP_Header, sizeof(BMP_Header)) != sizeof(BMP_Header)) 01275 { 01276 pc.printf("read error!\n"); 01277 if (fh->close()) pc.printf("failed to close file!\n"); 01278 } 01279 else 01280 { 01281 pc.printf("bfType %04X", BMP_Header.bfType); 01282 HexDump0("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header)); 01283 if (BMP_Header.bfType != BF_TYPE) { 01284 fh->close(); 01285 pc.printf("not_bmp_format"); 01286 } 01287 pc.printf("bfOffits %04X", BMP_Header.bfOffBits); 01288 RetCode_t rt = showBitmap(5, 62, BMP_Header.bfOffBits, fh); 01289 pc.printf("==%i\n", rt); 01290 if (fh->close()) pc.printf("failed to close file!\n"); 01291 } 01292 } 01293 else { 01294 pc.printf("file_not_found"); 01295 } 01296 } 01297 disconnectSD(); 01298 01299 01300 char fqfn[50]; 01301 int i = 0; 01302 01303 if (fh->read(&matrix, sizeof(tpMatrix_t)) != sizeof(tpMatrix_t)) 01304 { 01305 pc.printf("read error!\n"); 01306 //return; 01307 if (fh->close()) pc.printf("failed to close file!\n"); 01308 } 01309 else 01310 { 01311 lcd.TouchPanelSetMatrix(&matrix); 01312 if (fh->close()) pc.printf("failed to close file!\n"); 01313 disconnectSD(); 01314 pc.printf("ok\n"); 01315 return; 01316 } 01317 } 01318 else printf("failed to open tpcal.cfg file!\n"); 01319 } 01320 disconnectSD(); 01321 01322 01323 INFO("Screen Capture... "); 01324 for (i=1; i< 100; i++) { 01325 snprintf(fqfn, sizeof(fqfn), "/local/Screen%02d.bmp", i); 01326 FILE * fh = fopen(fqfn, "rb"); 01327 if (!fh) { 01328 lcd.PrintScreen(0,0,lcd.width(),lcd.height(),fqfn); 01329 INFO(" as /local/Screen%02d.bmp", i); 01330 return i; 01331 } else { 01332 fclose(fh); // close this and try the next 01333 } 01334 } 01335 return 0; 01336 01337 RetCode_t r = lcd.PrintScreen(5,62,615,405,"/sd/local/48027224.bmp"); 01338 } 01339 */ 01340 LocalFileSystem local("local"); 01341 void showPic(void) { 01342 RetCode_t r = lcd.RenderImageFile(8, 66, "/local/Rio24.bmp"); 01343 } 01344 01345 int indDirFirst = 0; 01346 int indDirCheck = 0; 01347 01348 void btnDir(int k) { 01349 int nn = indName; 01350 switch (k) { 01351 case 0: //btn splash 01352 showMain(progNumber); 01353 LPscreen = 3; //main screen 01354 01355 showPic(); 01356 01357 break; 01358 case 1: //btn up 01359 if(nn > 9) { 01360 lcd800x480dir(rDr); 01361 if((indDirFirst) > 8) indDirFirst = indDirFirst - 8; 01362 else indDirFirst = 0; 01363 for(int i=0; i<9; i++) { 01364 lcd.puts(txtBoxDir[i].textX, txtBoxDir[i].textY, dirName[indDirFirst + i]); 01365 } 01366 } 01367 break; 01368 case 2: //btn down 01369 if(nn > 9) { 01370 lcd800x480dir(rDr); 01371 if((nn - indDirFirst) > 16) indDirFirst = indDirFirst + 8; 01372 else indDirFirst = nn - 9; 01373 for(int i=0; i<9; i++) { 01374 lcd.puts(txtBoxDir[i].textX, txtBoxDir[i].textY, dirName[indDirFirst + i]); 01375 } 01376 } 01377 break; 01378 } 01379 } 01380 01381 int indDirText = 0; 01382 char ccD[40]; 01383 01384 void btnDirText(int k) { 01385 int nn = indDirText - 1; 01386 01387 if(indDirText != 0) { 01388 lcd.fillrect(txtBoxDir[nn].x1, txtBoxDir[nn].y1, txtBoxDir[nn].x2, txtBoxDir[nn].y2, txtBoxDir[nn].color); 01389 lcd.foreground(txtBoxDir[nn].textColor); 01390 lcd.background(txtBoxDir[nn].color); 01391 lcd.puts(txtBoxDir[nn].textX, txtBoxDir[nn].textY, dirName[indDirFirst + nn]); 01392 } 01393 indDirText = k + 1; 01394 nn = k; 01395 lcd.fillrect(txtBoxDir[k].x1, txtBoxDir[k].y1, txtBoxDir[k].x2, txtBoxDir[k].y2, Yellow); 01396 lcd.foreground(txtBoxDir[k].textColor); 01397 lcd.background(Yellow); 01398 lcd.puts(txtBoxDir[k].textX, txtBoxDir[k].textY, dirName[indDirFirst + k]); 01399 01400 if (strchr(dirName[indDirFirst + k], '.') == NULL) { 01401 //pc.printf("<%s>", dirName[indDirFirst + k]); 01402 dirS.append(dirName[indDirFirst + k]); 01403 //pc.printf("<%s>", dirS.c_str()); 01404 strcpy(&ccD[0], dirS.c_str()); 01405 //pc.printf("<%s>", ccD); 01406 dirOpenHmi(ccD); 01407 // clean directory 01408 for(int i =indName; i<40; i++) { 01409 strcpy(&dirName[indName++][0], " "); 01410 } 01411 01412 } 01413 } 01414 01415 void txtBoxNPadd(int i) { 01416 if(i < 10) { 01417 NPinp =10 * NPinp + i; 01418 if(NPinp > miMa[LabelsIndex].max) {NPinp = miMa[LabelsIndex].max;} 01419 01420 lcd.fillroundrect(txtBNP.x1, txtBNP.y1, txtBNP.x2, txtBNP.y2, txtBNP.r1, txtBNP.r2, txtBNP.color); 01421 lcd.foreground(txtBNP.textColor); 01422 lcd.background(txtBNP.color); 01423 sprintf(txtBNP.text, "%i", NPinp); 01424 lcd.puts(txtBNP.textX, txtBNP.textY, txtBNP.text); 01425 flagNPinp = true; 01426 } 01427 if(i == 11) { 01428 lcd.fillroundrect(txtBNP.x1, txtBNP.y1, txtBNP.x2, txtBNP.y2, txtBNP.r1, txtBNP.r2, txtBNP.color); 01429 lcd.foreground(txtBNP.textColor); 01430 lcd.background(txtBNP.color); 01431 NPinp = NPinp / 10; 01432 if(NPinp == 0) { 01433 lcd.puts(txtBNP.textX, txtBNP.textY, ""); 01434 flagNPinp = false; 01435 } 01436 else { 01437 sprintf(txtBNP.text, "%i", NPinp); 01438 lcd.puts(txtBNP.textX, txtBNP.textY, txtBNP.text); 01439 } 01440 } 01441 if(i == 12) { 01442 if(TPmode == 1) { 01443 if(flagNPinp == true) { 01444 if(NPinp < miMa[LabelsIndex].min) {NPinp = miMa[LabelsIndex].min;} 01445 switch (LabelsIndex) { 01446 case 0: {prPar[progNumber].LPbeg = NPinp; break;} 01447 case 1: {prPar[progNumber].LPend = NPinp; break;} 01448 case 3: {prPar[progNumber].Lfreq = NPinp; break;} 01449 case 4: {prPar[progNumber].Lpulse = NPinp; break;} 01450 case 5: {prPar[progNumber].amplBeg = NPinp; break;} 01451 case 6: {prPar[progNumber].amplEnd = NPinp; break;} 01452 case 7: {prPar[progNumber].wFreq = NPinp; break;} 01453 case 8: {prPar[progNumber].wTime = NPinp; break;} 01454 case 9: {prPar[progNumber].amplNum = NPinp; break;} 01455 } 01456 sprintf(txtBoxR[LabelsIndex].text, "%i", NPinp); 01457 } 01458 showVal(progNumber); 01459 LPscreen = 0; //value screen 01460 flagParChanged = 0; 01461 } 01462 else if(TPmode == 2) { 01463 if(flagNPinp == true) { 01464 if(NPinp < miMa[LabelsIndex].min) {NPinp = miMa[LabelsIndex].min;} 01465 switch (LabelsIndex) { 01466 case 10: {fileNum = NPinp; break;} 01467 } 01468 sprintf(txtRServ[4].text, "%i", NPinp); 01469 } 01470 showService(); 01471 LPscreen = 2; //service screen 01472 01473 } 01474 } 01475 } 01476 01477 void testTP(void) { 01478 TouchCode_t touch; 01479 01480 touch = lcd.TouchPanelReadable(); // any touch to report? 01481 if (touch) { 01482 uint8_t id = lcd.TouchID(); // 'id' tracks the individual touches 01483 TouchCode_t ev = lcd.TouchCode(); // 'ev'ent 0-no_touch,1-touch,2-held,3-release,4-no_cal 01484 point_t xy = lcd.TouchCoordinates(); // and of course the (x,y) coordinates 01485 01486 pc.printf("%2d,%d:(%4d,%4d)\n", id, ev, xy.x, xy.y); 01487 int lastRadius, newRadius; 01488 lastRadius = ComputeRadius(lastTP); // To erase the last fingerprint 01489 newRadius = ComputeRadius(xy); // Shrink near edge of screen 01490 lcd.circle(xy, newRadius, Red); // draw new fingerprint 01491 lcd.circle(lastTP, lastRadius, Black); // erase old fingerprint 01492 lastTP = xy; 01493 01494 led2 = 1; 01495 wait_ms(100); 01496 led2 = 0; 01497 } 01498 } 01499 01500 void checkTP(void) { 01501 TouchCode_t touch; 01502 01503 touch = lcd.TouchPanelReadable(); // any touch to report? 01504 //pc.printf("TP\n"); 01505 if (touch) { 01506 uint8_t id = lcd.TouchID(); // 'id' tracks the individual touches 01507 TouchCode_t ev = lcd.TouchCode(); // 'ev'ent 0-no_touch,1-touch,2-held,3-release,4-no_cal 01508 point_t xy = lcd.TouchCoordinates(); // and of course the (x,y) coordinates 01509 01510 //printf("(%4d,%4d)\n", xy.x, xy.y); 01511 pc.printf("%d,%d:(%4d,%4d)\n", TPmode, LPscreen, xy.x, xy.y); 01512 01513 if(LPscreen == 0) { //value screen 01514 //8 program# 01515 for(int i = 0; i < TextBoxSize; i++) { 01516 if((xy.x > txtBox[i].x1)&(xy.x < txtBox[i].x2)&(xy.y > txtBox[i].y1)&(xy.y < txtBox[i].y2)) { 01517 pc.printf("%i\n", i); 01518 if(i<8) {showProgParam(i); flagParChanged = 0; goto checkTPend;} 01519 else {if(editBtnMode == 1) {showWobParam(i-8); flagParChanged = 0; goto checkTPend;}} //edit mode, 3 wob.mode 01520 } 01521 } 01522 // text boxes 01523 if(editBtnMode == 1) { 01524 for(int i = 0; i < numPrPar; i++) { 01525 if((xy.x > txtBoxR[i].x1)&(xy.x < txtBoxR[i].x2)&(xy.y > txtBoxR[i].y1)&(xy.y < txtBoxR[i].y2)) { 01526 pc.printf("%i\n", i); 01527 if(i == numLmode) { 01528 lcd.fillroundrect(txtBoxR[i].x1, txtBoxR[i].y1, txtBoxR[i].x2, txtBoxR[i].y2, txtBoxR[i].r1, txtBoxR[i].r2, txtBoxR[i].color); 01529 lcd.foreground(txtBoxR[i].textColor); 01530 lcd.background(txtBoxR[i].color); 01531 if(Lmode == 0) { 01532 Lmode = 1; 01533 prPar[progNumber].Lmode = 1; 01534 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, "PULSE"); 01535 if(SetLasComm(32) == 1) {TPstatus = 5;} //EPM -enable pulse mode 01536 else { 01537 if(SetLasComm( 1) == 1) {TPstatus = 5;} //STA -read laser status 01538 else TPstatus = 0; 01539 } 01540 } 01541 else { 01542 Lmode = 0; 01543 prPar[progNumber].Lmode = 0; 01544 lcd.puts(txtBoxR[i].textX, txtBoxR[i].textY, "CW"); 01545 if(SetLasComm(33) == 1) {TPstatus = 5;} //DPM -disable pulse mode 01546 else { 01547 if(SetLasComm( 1) == 1) {TPstatus = 5;} //STA -read laser status 01548 else TPstatus = 0; 01549 } 01550 } 01551 flagParChanged = 0; 01552 } 01553 else { 01554 showNP(i); 01555 LabelsIndex = i; 01556 NPinp = 0; 01557 flagNPinp = false; 01558 LPscreen = 1; //LP screen 01559 } 01560 goto checkTPend; 01561 } 01562 } 01563 } 01564 //btn Edit 01565 if((xy.x > txtBoxR[numTPeditBtn].x1)&(xy.x < txtBoxR[numTPeditBtn].x2)&(xy.y > txtBoxR[numTPeditBtn].y1)&(xy.y < txtBoxR[numTPeditBtn].y2)) { 01566 if(TPmode == 1) { 01567 showTPeditBtn(0); //set operate mode 01568 TPmode = 0; 01569 editBtnMode = 0; 01570 } 01571 else { 01572 showTPeditBtn(1); //set edit mode 01573 TPmode = 1; 01574 editBtnMode = 1; 01575 } 01576 goto checkTPend; 01577 } 01578 //btn Main 01579 if((xy.x > txtBoxR[numTPmainBtn].x1)&(xy.x < txtBoxR[numTPmainBtn].x2)&(xy.y > txtBoxR[numTPmainBtn].y1)&(xy.y < txtBoxR[numTPmainBtn].y2)) { 01580 pc.printf("MainBtn"); 01581 01582 showMain(progNumber); 01583 TPmode = 0; 01584 LPscreen = 3; 01585 } 01586 //status line 01587 if((xy.x > txtBoxR[numTPstatus].x1)&(xy.x < txtBoxR[numTPstatus].x2)&(xy.y > txtBoxR[numTPstatus].y1)&(xy.y < txtBoxR[numTPstatus].y2)) { 01588 showTPstatus(10); //clean status line 01589 } 01590 goto checkTPend; 01591 } 01592 else if(LPscreen == 1) { //numpad screen 01593 if(xy.x < txtBoxNP[1].x1) { //touch left from form 01594 showVal(progNumber); 01595 LPscreen = 0; //values screen 01596 pc.printf("<<"); 01597 goto checkTPend; 01598 } 01599 //btn 0..9, ok, back 01600 for(int i = 0; i < 13; i++) { 01601 if((xy.x > txtBoxNP[i].x1)&(xy.x < txtBoxNP[i].x2)&(xy.y > txtBoxNP[i].y1)&(xy.y < txtBoxNP[i].y2)) { 01602 pc.printf("%i\n", i); 01603 txtBoxNPadd(i); 01604 goto checkTPend; 01605 } 01606 } 01607 01608 } 01609 else if(LPscreen == 2) { //service screen 01610 for(int i = 0; i < txtRServSize; i++) { 01611 if((xy.x > txtRServ[i].x1)&(xy.x < txtRServ[i].x2)&(xy.y > txtRServ[i].y1)&(xy.y < txtRServ[i].y2)) { 01612 btnServ(i); 01613 break; 01614 } 01615 } 01616 if(flagDirOpen != 0) { 01617 for(int i = 0; i < txtRdirSize; i++) { 01618 if((xy.x > txtRdir[i].x1)&&(xy.x < txtRdir[i].x2)&&(xy.y > txtRdir[i].y1)&&(xy.y < txtRdir[i].y2)) { 01619 btnDir(i); 01620 break; 01621 } 01622 } 01623 for(int i = 0; i < TextBoxDirSize; i++) { 01624 if((xy.x > txtBoxDir[i].x1)&&(xy.x < txtBoxDir[i].x2)&&(xy.y > txtBoxDir[i].y1)&&(xy.y < txtBoxDir[i].y2)) { 01625 btnDirText(i); 01626 break; 01627 } 01628 } 01629 } 01630 } 01631 else if(LPscreen == 3) { //main screen 01632 //8 program# 01633 for(int i = 0; i < TextBoxSize; i++) { 01634 if((xy.x > txtBox[i].x1)&(xy.x < txtBox[i].x2)&(xy.y > txtBox[i].y1)&(xy.y < txtBox[i].y2)) { 01635 pc.printf("%i\n", i); 01636 if(i<8) {showProgNum(i); flagParChanged = 0; goto checkTPend;} 01637 } 01638 } 01639 //btn Values 01640 if((xy.x > txtBoxR[numTPvalBtn].x1)&(xy.x < txtBoxR[numTPvalBtn].x2)&(xy.y > txtBoxR[numTPvalBtn].y1)&(xy.y < txtBoxR[numTPvalBtn].y2)) { 01641 pc.printf("ValuesBtn"); 01642 01643 showVal(progNumber); 01644 TPmode = 0; 01645 LPscreen = 0; 01646 } 01647 //btn Service 01648 if((xy.x > txtBoxR[numTPservBtn].x1)&(xy.x < txtBoxR[numTPservBtn].x2)&(xy.y > txtBoxR[numTPservBtn].y1)&(xy.y < txtBoxR[numTPservBtn].y2)) { 01649 pc.printf("ServiceBtn"); 01650 01651 showService(); 01652 TPmode = 2; 01653 LPscreen = 2; 01654 } 01655 //status line 01656 if((xy.x > txtBoxR[numTPstatus].x1)&(xy.x < txtBoxR[numTPstatus].x2)&(xy.y > txtBoxR[numTPstatus].y1)&(xy.y < txtBoxR[numTPstatus].y2)) { 01657 showTPstatus(10); //clean status line 01658 } 01659 } 01660 checkTPend: 01661 led2 = 1; 01662 wait_ms(100); 01663 led2 = 0; 01664 01665 while(touch) { 01666 touch = lcd.TouchPanelReadable(); // any touch to report? 01667 wait_ms(1); 01668 } 01669 } 01670 } 01671 //ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 01672 01673 void LasCommInit(void) { 01674 if(LPscreen == 2) statServErr(10); //service screen, status " " 01675 else showTPstatus(10); // main screen, status " " 01676 01677 if(SetLasComm(52) == 1) {c7=52; goto met1;} //RERR -Resets any resettable errors 01678 if(SetLasComm(54) == 1) {c7=54; goto met1;} //EMOFF -Stop Emission 01679 if(SetLasComm(41) == 1) {c7=41; goto met1;} //DMOD -disable external modulation input 01680 if(SetLasComm(47) == 1) {c7=47; goto met1;} //DEABC -disable external aiming beam control input 01681 if(SetLasComm(34) == 1) {c7=34; goto met1;} //ABN -aiming beam on 01682 //if(SetLasComm(35) == 1) {c7=35; goto met1;} //ABF -aiming beam off 01683 //if(SetLasComm(46) == 1) {c7=46; goto met1;} //EEABC -enable external aiming beam control input 01684 if(SetLasComm(39) == 1) {c7=39; goto met1;} //DGM -disable gate mode 01685 if(SetLasComm(36) == 1) {c7=36; goto met1;} //EEC -enable external analog power control input 01686 if(SetLasComm(40) == 1) {c7=40; goto met1;} //EMOD -enable external modulation input 01687 if(SetLasComm(42) == 1) {c7=42; goto met1;} //ELE -enable external emission input 01688 if(SetLasComm( 1) == 1) {c7=1; goto met1;} //STA -read laser status 01689 c7 = 99; 01690 if(LPscreen == 2) statServErr(0); //service screen, status READY 01691 else showTPstatus(0); // main screen, status READY 01692 return; 01693 01694 met1: 01695 if(LPscreen == 2) statServErr(5); //service screen 01696 else showTPstatus(5); // main screen 01697 } 01698 01699 void initIOparam(void) { 01700 for(int i=0; i<4; i++) { 01701 ioPar.o3[i] = '\0'; 01702 ioPar.o2[i] = '\0'; 01703 ioPar.o1[i] = '\0'; 01704 ioPar.i3[i] = '\0'; 01705 ioPar.i2[i] = '\0'; 01706 ioPar.i1[i] = '\0'; 01707 ioPar.aiLPow[i] = '\0'; 01708 ioPar.aiLCur[i] = '\0'; 01709 ioPar.aiLTemp[i] = '\0'; 01710 ioPar.aiLBR[i] = '\0'; 01711 } 01712 } 01713 01714 uint8_t bitOstate = 0x80; //d7=1 need set/reset, d6=1-set,0-reset, d5-d0 bit number 01715 uint8_t ioReq = 0; //0-no request, 1-inp.request, 2-out.request 01716 01717 //============================================================================== 01718 int main() 01719 { 01720 a7=0; 01721 b7=0; 01722 c7=0; 01723 01724 //Configure CRC, large frames, and write validation 01725 sd.crc(true); 01726 sd.large_frames(true); 01727 sd.write_validation(true); 01728 01729 pc.baud(PC_BAUD); // 01730 01731 pc.printf("\nRA8875 Touch Screen. Date: " __DATE__ " " __TIME__ "\r\n"); 01732 //wait_ms(5000); 01733 //pc.printf("\n>>\n"); 01734 //wait_ms(5000); 01735 01736 initHMIio(); 01737 initIOparam(); 01738 01739 lcd800x480Init(); 01740 //showMain(progNumber+1); 01741 tickRS.attach_us(&flipUS, tickTime); // the address of the function to be attached (flip) to ticker 01742 01743 wait_ms(5000); 01744 LasCommInit(); 01745 01746 fillTestBuffer(); 01747 if(connectSD() == 0) { 01748 infoSD(); 01749 //writeTestFile(); 01750 readTestFile(); 01751 01752 readDirSD(rDr); 01753 01754 //RetCode_t r = lcd.RenderImageFile(0, 0, "/sd/local/48027208.bmp"); 01755 //printf("returned %d\r\n", r); 01756 //wait(3); 01757 //r = lcd.RenderJpegFile(0, 0, "/sd/local/p480272.jpg"); 01758 //printf("returned %d\r\n", r); 01759 01760 disconnectSD(); 01761 } 01762 pc.printf("a7=%i b7=%i c7=%i d7=%i\n", a7, b7, c7, d7); 01763 01764 InitTS(); 01765 readIniFile(); 01766 showMain(progNumber); 01767 //int x, y, z; 01768 01769 while(true) 01770 { 01771 //testTP(); 01772 if(flagWeld == 0) checkTP(); 01773 01774 main_cycle_add(); 01775 01776 iLed++; 01777 if(iLed > 500) { 01778 led1 = !led1; 01779 iLed = 0; 01780 } 01781 wait_ms(1); 01782 } 01783 } 01784
Generated on Sun Jul 17 2022 03:41:51 by
1.7.2