Project
Dependencies: Hotboards_keypad TextLCD eeprom
main.cpp
00001 00002 #include "mbed.h" 00003 #include "LCDDisplay.h" 00004 #include "i2ceeprom.h" 00005 #include "Hotboards_keypad.h" 00006 #include "Hotboards_keypad.h" 00007 00008 // Defines the keys array with it's respective number of rows & cols, 00009 // and with the value of each key 00010 char keys[ 4 ][ 4 ] = { 00011 { '1' , '2' , '3' , 'A' }, 00012 { '4' , '5' , '6' , 'B' }, 00013 { '7' , '8' , '9' , 'C' }, 00014 { '*' , '0' , '#' , 'D' } 00015 }; 00016 00017 // Defines the pins connected to the rows 00018 DigitalInOut rowPins[ 4 ] = {D4,D5,D6,D7 }; 00019 // Defines the pins connected to the cols 00020 DigitalInOut colPins[ 4 ] = { D8,D9,D10,D11}; 00021 //connect to the column pinouts of the keypad 00022 00023 Keypad keypad( makeKeymap( keys ), rowPins, colPins,4,4); 00024 00025 00026 bool PasswordStatus=false; 00027 int mode=0; 00028 00029 00030 00031 DigitalOut GreenLight(PB_1); 00032 DigitalOut YellowLight(PB_15); 00033 DigitalOut RedLight(PB_14); 00034 DigitalOut SpareLight(PB_13); 00035 DigitalOut Buzzer(PC_13); 00036 DigitalOut led1(LED1); 00037 DigitalOut led2(LED2); 00038 DigitalOut led3(LED3); 00039 00040 00041 00042 uint32_t Current_Mode=1; 00043 00044 float G_time=0; 00045 float Y_time=0; 00046 float R_time=0; 00047 00048 00049 uint8_t StartButtonPressed=0; 00050 uint8_t StopButtonPressed=0; 00051 uint8_t ReStartButtonPressed=0; 00052 Timer timer; 00053 Timer timerred; 00054 //Thread EveryOneSec; 00055 00056 void keypadEvent(KeypadEvent key); 00057 bool ReadEachLightTime(uint32_t mode,char *mmss); 00058 bool ReadAllTimesofEachMode(uint32_t MODE,char *Greentime,char *Yellowtime,char *Redtime); 00059 void ExtractTimesinSecs(char *greentime,char *yellowtime,char *redtime,float *grntim,float *yeltim,float *redtim); 00060 void SaveTimes(uint32_t Mode,float GreenTime,float YellowTime,float RedTime); 00061 void CalculateTimeElapsed(float TimeElapsed, char *TimeStr); 00062 bool PasswordAcceptance(); 00063 int ModeSelectTochange(); 00064 void Get_Time_Elapsed_after_Start(float timeInSec, char * str); 00065 void fn(char rkey); 00066 int main() 00067 { 00068 bool start=false; 00069 00070 bool lcdflag=true; 00071 00072 char Timestr[10]={'\0'}; 00073 char Buf[17]={'\0'}; 00074 float timeElapsed=0; 00075 char buff[6]= {'\0'}; 00076 char Buffer[17]= {'\0'}; 00077 Clear_LCD(); 00078 Display_LCD(0,0," Initialising "); 00079 SpareLight=1; 00080 GreenLight=1; 00081 YellowLight=1; 00082 RedLight=1; 00083 wait(1); 00084 Clear_LCD(); 00085 //Current_Mode=1; 00086 // Last_Saved_Mode(); 00087 Display_LCD(0,0,"Select Mode Or"); 00088 Display_LCD(0,1,"Press Start "); 00089 G_time=20; 00090 Y_time=5; 00091 R_time=10; 00092 char key; 00093 00094 00095 Current_Mode = readCurrentMode(); 00096 00097 //WriteCorresspondingTimes(1, 10,20,30); 00098 // ReadCorresspondingTimes(1,&G_time,&Y_time,&R_time); 00099 00100 00101 printf("Current Mode is %d \r\n", Current_Mode); 00102 00103 while(1) { 00104 00105 key=keypad.getKey(); 00106 00107 printf("Key is :%c\r\n",key); 00108 if(key) { 00109 if(key=='*') { 00110 PasswordStatus=PasswordAcceptance(); 00111 } 00112 if(PasswordStatus==true) { 00113 PasswordStatus=false; 00114 mode= ModeSelectTochange(); 00115 if(mode>=1 && mode <=6) { 00116 fn((char)(mode+0x30)); 00117 mode=0; 00118 } else { 00119 Display_LCD(0,0," Invalid Mode "); 00120 Display_LCD(0,1," Mode b/w 1-6 "); 00121 wait(2); 00122 00123 Clear_LCD(); 00124 Display_LCD(0,0,"Select Mode Or"); 00125 Display_LCD(0,1,"Press Start "); 00126 00127 } 00128 } 00129 00130 else if(key=='A') { 00131 printf("Started \r\n"); 00132 StartButtonPressed=1; 00133 StopButtonPressed=0; 00134 ReStartButtonPressed=0; 00135 printf("Started \r\n"); 00136 timer.start(); 00137 00138 } 00139 00140 else if(key=='B') { 00141 StartButtonPressed=0; 00142 StopButtonPressed=1; 00143 ReStartButtonPressed=0; 00144 00145 printf("Stopped \r\n"); 00146 wait(0.2); 00147 } 00148 00149 else if(key=='C') { 00150 StartButtonPressed=0; 00151 StopButtonPressed=0; 00152 ReStartButtonPressed=1; 00153 timer.stop(); 00154 printf("Reset \r\n"); 00155 wait(0.2); 00156 } 00157 00158 else if(key=='D') { 00159 Clear_LCD(); 00160 Display_LCD(0,0,"Choose Mode"); 00161 wait(0.5); 00162 char tempkey=keypad.waitForKey(); 00163 if(tempkey>=0x31 && tempkey<=0x36) { 00164 char Buff[20]= {'\0'}; 00165 sprintf(Buff,"Current Mode %c",tempkey); 00166 Display_LCD(0,1,Buff); 00167 Current_Mode=(int)(tempkey-0x30); 00168 StoreCurrentMode(Current_Mode); 00169 wait(1); 00170 Clear_LCD(); 00171 00172 } else { 00173 Display_LCD(0,0,"Invld Mod Entrd"); 00174 wait(1); 00175 Clear_LCD(); 00176 00177 } 00178 } else 00179 {} 00180 00181 } 00182 00183 00184 // if(Mode1==0) 00185 if(Current_Mode==1) { 00186 // printf("Am here in Mode 1\r\n"); 00187 // G_time=20; 00188 // Y_time=5; 00189 // R_time=10; 00190 00191 ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time); 00192 // printf(" G_time %f, Y Time %f R_time %f :",G_time,Y_time,R_time); 00193 // printf("Current MOde 1 \r\n"); 00194 // Display_LCD(0,1,"Mode: 1"); 00195 00196 00197 Y_time=Y_time+G_time; 00198 R_time=R_time+Y_time; 00199 wait(0.2); 00200 } 00201 00202 // if(Mode2==0) 00203 if(Current_Mode==2) { 00204 00205 // G_time=2; 00206 // Y_time=5; 00207 // R_time=1; 00208 Current_Mode=2; 00209 ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time); 00210 00211 printf("Current MOde 2 \r\n"); 00212 // Display_LCD(0,1,"Mode: 2"); 00213 Y_time=Y_time+G_time; 00214 R_time=R_time+Y_time; 00215 wait(0.1); 00216 } 00217 00218 // if(Mode3==0) 00219 if(Current_Mode==3) { 00220 00221 // G_time=12; 00222 // Y_time=5; 00223 // R_time=10; 00224 Current_Mode=3; 00225 ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time); 00226 printf("Current MOde 3 \r\n"); 00227 // Display_LCD(0,1,"Mode: 3"); 00228 Y_time=Y_time+G_time; 00229 R_time=R_time+Y_time; 00230 wait(0.1); 00231 } 00232 00233 00234 // if(Mode4==0) 00235 if(Current_Mode==4) { 00236 00237 // G_time=20; 00238 // Y_time=5; 00239 // R_time=10; 00240 Current_Mode=4; 00241 ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time); 00242 printf("Current MOde 1 \r\n"); 00243 Display_LCD(0,1,"Mode: 4"); 00244 Y_time=Y_time+G_time; 00245 R_time=R_time+Y_time; 00246 wait(0.2); 00247 } 00248 // 00249 if(Current_Mode==5) { 00250 00251 // G_time=2; 00252 // Y_time=5; 00253 // R_time=1; 00254 Current_Mode=5; 00255 // printf("Current MOde 2 \r\n"); 00256 ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time); 00257 Display_LCD(0,1,"Mode: 5"); 00258 Y_time=Y_time+G_time; 00259 R_time=R_time+Y_time; 00260 wait(0.2); 00261 } 00262 // 00263 // if(Mode6==0) 00264 if(Current_Mode==6) { 00265 00266 // G_time=12; 00267 // Y_time=5; 00268 // R_time=10; 00269 Current_Mode=3; 00270 // printf("Current MOde 3 \r\n"); 00271 ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time); 00272 Display_LCD(0,1,"Mode: 6"); 00273 Y_time=Y_time+G_time; 00274 R_time=R_time+Y_time; 00275 wait(0.2); 00276 } 00277 00278 00279 // if(Start==0) { 00280 // printf("Started \r\n"); 00281 // StartButtonPressed=1; 00282 // StopButtonPressed=0; 00283 // ReStartButtonPressed=0; 00284 // printf("Started ************ %d \r\n",StartButtonPressed); 00285 // printf("Started ############## %d \r\n",StopButtonPressed); 00286 // printf("Started 88888888888888%d \r\n",ReStartButtonPressed); 00287 // 00288 // timer.start(); 00289 // 00290 // } 00291 // if(Stop==0) { 00292 // StartButtonPressed=0; 00293 // StopButtonPressed=1; 00294 // ReStartButtonPressed=0; 00295 // 00296 // printf("Stopped \r\n"); 00297 // wait(0.2); 00298 // 00299 // } 00300 // 00301 // if(Reset==0) { 00302 // StartButtonPressed=0; 00303 // StopButtonPressed=0; 00304 // ReStartButtonPressed=1; 00305 // timer.stop(); 00306 // printf("Reset \r\n"); 00307 // wait(0.2); 00308 // } 00309 00310 00311 if(StartButtonPressed==1 && StopButtonPressed==0 && ReStartButtonPressed==0 ) { 00312 printf(" Read Time %f\r\n",timer.read()); //while 00313 if(timer.read()<=G_time ) { 00314 00315 if(lcdflag==true) { 00316 Clear_LCD(); 00317 lcdflag=false; 00318 00319 } 00320 00321 00322 // timer.start(); 00323 printf(" Read Time %f\r\n",timer.read()); 00324 Display_LCD(0,0," Green Light "); 00325 Get_Time_Elapsed_after_Start(timer.read(),Timestr); 00326 // Display_LCD(0,1,Timestr); 00327 sprintf(Buf," %s ",Timestr); 00328 Display_LCD(0,1,Buf); 00329 memset(Buf,'\0',16); 00330 GreenLight=0; 00331 YellowLight=1; 00332 RedLight=1; 00333 00334 } else if( timer.read()>G_time && timer.read()<=Y_time ) { 00335 Display_LCD(0,0," Yellow Light "); 00336 Get_Time_Elapsed_after_Start(timer.read(),Timestr); 00337 sprintf(Buf," %s ",Timestr); 00338 Display_LCD(0,1,Buf); 00339 memset(Buf,'\0',16); 00340 GreenLight=1; 00341 YellowLight=0; 00342 RedLight=1; 00343 wait(0.1); 00344 printf(" Read Time %f\r\n",timer.read()); 00345 } 00346 00347 else if( timer.read()>Y_time && timer.read()<=R_time ) { 00348 Display_LCD(0,0," Red Light "); 00349 Get_Time_Elapsed_after_Start(timer.read(),Timestr); 00350 // Display_LCD(0,1,Timestr); 00351 sprintf(Buf," %s ",Timestr); 00352 Display_LCD(0,1,Buf); 00353 memset(Buf,'\0',16); 00354 GreenLight=1; 00355 YellowLight=1; 00356 RedLight=0; 00357 timerred.start(); 00358 00359 00360 printf(" Read Time %f\r\n",timer.read()); 00361 } 00362 else if( timer.read()>R_time ) 00363 { 00364 GreenLight=1; 00365 YellowLight=1; 00366 RedLight=1; 00367 timeElapsed=timer.read(); 00368 timer.stop(); 00369 printf("Total Time = %f\r\n",timeElapsed); 00370 00371 CalculateTimeElapsed(timeElapsed,buff); 00372 00373 sprintf(Buffer,"Total Time %s",buff); 00374 00375 Display_LCD(0,0,Buffer); 00376 memset(Buffer,'\0',17); 00377 timeElapsed=timerred.read(); 00378 timerred.stop(); 00379 CalculateTimeElapsed(timeElapsed,buff); 00380 memset(Buffer,'\0',17); 00381 sprintf(Buffer,"Tim af Red %s",buff); 00382 Display_LCD(0,1,Buffer); 00383 memset(Buffer,'\0',17); 00384 00385 StartButtonPressed=0; 00386 StopButtonPressed=1; 00387 ReStartButtonPressed=0; 00388 00389 00390 } 00391 00392 //else if(timer.read()>R_time) { 00393 // Display_LCD(0,0,"Time Lmt Excded "); 00394 // GreenLight=1; 00395 // YellowLight=1; 00396 // RedLight=1; 00397 // wait(0.2); 00398 // 00399 // 00400 // } 00401 00402 } 00403 // timeElapsed=timer.read(); 00404 // CalculateTimeElapsed(timeElapsed,buff); 00405 if(StartButtonPressed==0 && StopButtonPressed==1 && ReStartButtonPressed==0 ) { 00406 timeElapsed=timer.read(); 00407 timer.stop(); 00408 00409 printf("Total Time = %f\r\n",timeElapsed); 00410 00411 CalculateTimeElapsed(timeElapsed,buff); 00412 00413 sprintf(Buffer,"Total Time %s",buff); 00414 00415 Display_LCD(0,0,Buffer); 00416 memset(Buffer,'\0',17); 00417 timeElapsed=timerred.read(); 00418 timerred.stop(); 00419 CalculateTimeElapsed(timeElapsed,buff); 00420 memset(Buffer,'\0',17); 00421 sprintf(Buffer,"Tim af Red %s",buff); 00422 Display_LCD(0,1,Buffer); 00423 memset(Buffer,'\0',17); 00424 00425 wait(0.1); 00426 /******************************************* 00427 * If you want to use Reset Button Comment these lines 00428 * Presently it is with auto reset 00429 ******************************************/ 00430 ReStartButtonPressed=1; 00431 StartButtonPressed=0; 00432 StopButtonPressed=0; 00433 // /******************************************/ 00434 } 00435 if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==1 ) { 00436 00437 // Display_LCD(0,0,"Done Resetting"); 00438 StartButtonPressed=0; 00439 StopButtonPressed=0; 00440 ReStartButtonPressed=0; 00441 // Clear_LCD(); 00442 00443 } 00444 if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==0 ) { 00445 GreenLight=1; 00446 YellowLight=1; 00447 RedLight=1; 00448 timer.reset(); 00449 timerred.reset(); 00450 // printf(" Last Line\r\n"); 00451 // Display_LCD(0,0,"Select Mode Or"); 00452 // Display_LCD(0,1,"Press Start "); 00453 00454 lcdflag=true; 00455 } 00456 00457 } 00458 } 00459 00460 00461 void ReadTimes() 00462 { 00463 char rkey; 00464 char Str[5]= {'\0'}; 00465 char Star[5]= {'\0'}; 00466 char text[5]= {'\0'}; 00467 char GreenTime[6]= {'\0'}; 00468 char YellowTime[6]= {'\0'}; 00469 char RedTime[6]= {'\0'}; 00470 bool Staus=false; 00471 rkey=keypad.waitForKey(); 00472 00473 switch(rkey) { 00474 00475 case '1': 00476 00477 { 00478 Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime); 00479 if(Staus==true) { 00480 00481 float GTIME=0,YTIME=0,RTIME=0; 00482 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00483 SaveTimes(1,GTIME,YTIME,RTIME); 00484 printf(" Times %f %f %f \r\n",GTIME,YTIME,RTIME); 00485 } 00486 Staus=false; 00487 } 00488 break; 00489 case '2': { 00490 Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime); 00491 if(Staus==true) { 00492 00493 float GTIME=0,YTIME=0,RTIME=0; 00494 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00495 printf(" Times %f %f %f \r\n",GTIME,YTIME,RTIME); 00496 SaveTimes(2,GTIME,YTIME,RTIME); 00497 } 00498 Staus=false; 00499 } 00500 break; 00501 case '3': { 00502 Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime); 00503 if(Staus==true) { 00504 00505 float GTIME=0,YTIME=0,RTIME=0; 00506 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00507 SaveTimes(3,GTIME,YTIME,RTIME); 00508 } 00509 Staus=false; 00510 } 00511 00512 break; 00513 case '4': { 00514 Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime); 00515 if(Staus==true) { 00516 00517 float GTIME=0,YTIME=0,RTIME=0; 00518 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00519 SaveTimes(4,GTIME,YTIME,RTIME); 00520 } 00521 Staus=false; 00522 } 00523 00524 break; 00525 case '5': { 00526 Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime); 00527 if(Staus==true) { 00528 00529 float GTIME=0,YTIME=0,RTIME=0; 00530 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00531 SaveTimes(5,GTIME,YTIME,RTIME); 00532 } 00533 Staus=false; 00534 } 00535 00536 break; 00537 00538 case '6': { 00539 Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime); 00540 if(Staus==true) { 00541 00542 float GTIME=0,YTIME=0,RTIME=0; 00543 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00544 SaveTimes(6,GTIME,YTIME,RTIME); 00545 } 00546 Staus=false; 00547 } 00548 00549 break; 00550 default: { 00551 printf("No Mode\r\n"); 00552 Clear_LCD(); 00553 Display_LCD(0,0," InValid Mode "); 00554 } 00555 } 00556 00557 00558 } 00559 00560 bool ReadEachLightTime(uint32_t mode,char *mmss,char *lightTimeName) 00561 { 00562 Clear_LCD(); 00563 char Buffer[17]= {'\0'}; 00564 char Buffer1[17]="Entr Time Mode:"; 00565 char Buffer2[17]="Tim MM:SS"; 00566 00567 uint8_t index1=0; 00568 char key='\0'; 00569 char str[6]= {'\0'}; 00570 Clear_LCD(); 00571 sprintf(Buffer,"%s%d",Buffer1,mode); 00572 Display_LCD(0,0,Buffer); 00573 memset(Buffer,'\0',16); 00574 sprintf(Buffer,"%s %s",lightTimeName,Buffer2); 00575 Display_LCD(0,1,Buffer); 00576 00577 wait(3); 00578 Clear_LCD(); 00579 Display_LCD(0,0,"Press # Set "); 00580 Display_LCD(0,1,"Prss * to Exit "); 00581 00582 key=keypad.waitForKey(); 00583 if(key=='#') { 00584 Clear_LCD(); 00585 Display_LCD(0,0,"MM:SS "); 00586 Display_LCD(0,1,"MM:SS "); 00587 index1=0; 00588 while(index1==0 ||(index1<=4 && key !='#' && key!='*')) { 00589 key=keypad.waitForKey(); 00590 str[index1]=key; 00591 if(index1==2) { 00592 str[index1]=':'; 00593 index1++; 00594 str[index1]=key; 00595 } 00596 index1++; 00597 Display_LCD(0,0,"MM:SS "); 00598 Display_LCD(0,1,"MM:SS "); 00599 Display_LCD(0,1,str); 00600 } 00601 Clear_LCD(); 00602 Display_LCD(0,0,"Saving Mode "); 00603 Display_LCD(0,1,str); 00604 memcpy(mmss,str,5); 00605 mmss[6]='\0'; 00606 wait(1); 00607 Clear_LCD(); 00608 00609 return true; 00610 } else if(key=='*') { 00611 Display_LCD(0,0,"Mode Not Set "); 00612 Display_LCD(0,1,"Retains PrevMode"); 00613 wait (2); 00614 Clear_LCD(); 00615 return false; 00616 } 00617 } 00618 00619 00620 bool ReadAllTimesofEachMode(uint32_t MODE,char *Greentime,char *Yellowtime,char *Redtime) 00621 { 00622 bool Greenflag=false,Yellowflag=false,Redflag=false; 00623 Greenflag=ReadEachLightTime(MODE,Greentime,"Green"); 00624 00625 if(Greenflag==true) { 00626 00627 Yellowflag=ReadEachLightTime(MODE,Yellowtime,"Yellow"); 00628 if(Yellowflag==true) { 00629 00630 Redflag=ReadEachLightTime(MODE,Redtime,"Red"); 00631 if(Redflag==true) { 00632 return true; 00633 } else { 00634 return false; 00635 } 00636 } else { 00637 return false; 00638 } 00639 00640 } else 00641 return false; 00642 } 00643 00644 00645 void ExtractTimesinSecs(char *greentime,char *yellowtime,char *redtime,float *grntim,float *yeltim,float *redtim) 00646 { 00647 int mins,secs; 00648 if( greentime[2]==':') { 00649 mins=(( greentime[0]-0x30)*10)+(greentime[1]-0x30); 00650 secs=((greentime[3]-0x30)*10)+(greentime[4]-0x30); 00651 } 00652 *grntim=mins*60+secs; 00653 if( yellowtime[2]==':') { 00654 mins=(( yellowtime[0]-0x30)*10)+(yellowtime[1]-0x30); 00655 secs=((yellowtime[3]-0x30)*10)+(yellowtime[4]-0x30); 00656 } 00657 *yeltim=mins*60+secs; 00658 if( redtime[2]==':') { 00659 mins=(( redtime[0]-0x30)*10)+(redtime[1]-0x30); 00660 secs=((redtime[3]-0x30)*10)+(redtime[4]-0x30); 00661 } 00662 *redtim=mins*60+secs; 00663 } 00664 00665 void SaveTimes(uint32_t Mode,float GreenTime,float YellowTime,float RedTime) 00666 { 00667 bool flag=false; 00668 flag=WriteCorresspondingTimes(Mode, GreenTime,YellowTime,RedTime); 00669 00670 if(flag==true) { 00671 Clear_LCD(); 00672 Display_LCD(0,0," Mode Save "); 00673 Display_LCD(0,1," Success "); 00674 wait(1); 00675 } else { 00676 Clear_LCD(); 00677 Display_LCD(0,0," Mode Save "); 00678 Display_LCD(0,1," Failure "); 00679 00680 wait(1); 00681 } 00682 00683 } 00684 00685 void CalculateTimeElapsed(float TimeElapsed, char *TimeStr) 00686 { 00687 memset(TimeStr,'\0',sizeof TimeStr); 00688 int mins=(int)TimeElapsed/60; 00689 int secs=(int)TimeElapsed%60; 00690 sprintf(TimeStr,"%2d:%02d",mins,secs); 00691 } 00692 00693 00694 bool PasswordAcceptance() 00695 { 00696 Clear_LCD(); 00697 Display_LCD(0,0,"Enter Password "); 00698 char PasswordStr[5]= {'\0'}; 00699 char temp='\0'; 00700 temp=keypad.waitForKey(); 00701 PasswordStr[0]=temp; 00702 Display_LCD(0,1,PasswordStr); 00703 temp=keypad.waitForKey(); 00704 PasswordStr[1]=temp; 00705 Display_LCD(0,1,PasswordStr); 00706 temp=keypad.waitForKey(); 00707 PasswordStr[2]=temp; 00708 Display_LCD(0,1,PasswordStr); 00709 temp=keypad.waitForKey(); 00710 PasswordStr[3]=temp; 00711 Display_LCD(0,1,PasswordStr); 00712 printf("Password Str %s\r\n",PasswordStr); 00713 00714 if(PasswordStr[0]=='1' && PasswordStr[1] =='1' && PasswordStr[2]=='1' && PasswordStr[3]=='1') { 00715 Display_LCD(0,0,"Accepted "); 00716 printf("Accepted\r\n"); 00717 return true; 00718 } 00719 return false; 00720 } 00721 00722 00723 int ModeSelectTochange() 00724 { 00725 Clear_LCD(); 00726 Display_LCD(0,0,"Select Mode 1-6 "); 00727 char str[2]= {'\0'}; 00728 char temp='\0'; 00729 temp=keypad.waitForKey(); 00730 if(temp>=0x31 && temp<=0x36) { 00731 Display_LCD(0,1,"Mode Is: "); 00732 str[0]=temp; 00733 Display_LCD(9,1,str); 00734 wait(1); 00735 return (temp-0x30); 00736 } 00737 Display_LCD(0,0,"Invalid Mode"); 00738 return -1; 00739 00740 } 00741 00742 void fn(char rkey) 00743 { 00744 char GreenTime[10]= {'\0'},YellowTime[10]= {'\0'},RedTime[10]= {'\0'}; 00745 bool Staus=false; 00746 switch(rkey) 00747 00748 { 00749 case '1': 00750 00751 { 00752 Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime); 00753 if(Staus==true) { 00754 00755 float GTIME=0,YTIME=0,RTIME=0; 00756 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00757 SaveTimes(1,GTIME,YTIME,RTIME); 00758 Display_LCD(0,0,"Done Saving "); 00759 Display_LCD(0,1,"Mode Saved"); 00760 wait(1); 00761 Clear_LCD(); 00762 } 00763 Staus=false; 00764 } 00765 break; 00766 case '2': { 00767 Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime); 00768 if(Staus==true) { 00769 00770 float GTIME=0,YTIME=0,RTIME=0; 00771 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00772 SaveTimes(2,GTIME,YTIME,RTIME); 00773 Display_LCD(0,0,"Done Saving "); 00774 Display_LCD(0,1,"Mode Saved"); 00775 wait(1); 00776 Clear_LCD(); 00777 } 00778 Staus=false; 00779 } 00780 break; 00781 case '3': { 00782 Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime); 00783 if(Staus==true) { 00784 float GTIME=0,YTIME=0,RTIME=0; 00785 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00786 00787 printf("GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME %s %s %s : %f %f %f \r\n ",GreenTime,YellowTime,RedTime,GTIME,YTIME,RTIME); 00788 SaveTimes(3,GTIME,YTIME,RTIME); 00789 00790 Display_LCD(0,0,"Done Saving "); 00791 Display_LCD(0,1,"Mode Saved"); 00792 wait(1); 00793 Clear_LCD(); 00794 } 00795 Staus=false; 00796 } 00797 00798 break; 00799 case '4': { 00800 Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime); 00801 if(Staus==true) { 00802 00803 float GTIME=0,YTIME=0,RTIME=0; 00804 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00805 SaveTimes(4,GTIME,YTIME,RTIME); 00806 Display_LCD(0,0,"Done Saving "); 00807 Display_LCD(0,1,"Mode Saved"); 00808 wait(1); 00809 Clear_LCD(); 00810 } 00811 Staus=false; 00812 } 00813 00814 break; 00815 case '5': { 00816 Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime); 00817 if(Staus==true) { 00818 00819 float GTIME=0,YTIME=0,RTIME=0; 00820 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00821 // SaveTimes(5,GTIME,YTIME,RTIME); 00822 Display_LCD(0,0,"Done Saving "); 00823 Display_LCD(0,1,"Mode Saved"); 00824 wait(1); 00825 Clear_LCD(); 00826 } 00827 Staus=false; 00828 } 00829 00830 break; 00831 00832 case '6': { 00833 Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime); 00834 if(Staus==true) { 00835 float GTIME=0,YTIME=0,RTIME=0; 00836 ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME); 00837 SaveTimes(6,GTIME,YTIME,RTIME); 00838 Display_LCD(0,0,"Done Saving "); 00839 Display_LCD(0,1,"Mode Saved"); 00840 wait(1); 00841 Clear_LCD(); 00842 } 00843 Staus=false; 00844 } 00845 break; 00846 default: 00847 Display_LCD(0,0,"No Mode saved"); 00848 Display_LCD(0,1,"Retns Prev Mode"); 00849 wait(1); 00850 Clear_LCD(); 00851 printf("No Mode\r\n"); 00852 } 00853 00854 } 00855 00856 00857 00858 00859 void Get_Time_Elapsed_after_Start(float timeInSec, char * str) 00860 { 00861 memset(str,'\0',6); 00862 uint8_t min=(int) timeInSec/60; 00863 uint8_t Secs=(int) timeInSec%60; 00864 00865 if(min<10) 00866 { 00867 str[0]=0x30; 00868 str[1]=min+0x30; 00869 } 00870 else if(min>=10) 00871 { 00872 str[0]=(min/10)+0x30; 00873 str[1]=(min%10)+0x30; 00874 } 00875 00876 str[2]=':'; 00877 if(Secs<10) 00878 { 00879 str[3]=0x30; 00880 str[4]=Secs+0x30; 00881 } 00882 else if(Secs>=10) 00883 { 00884 str[3]=(Secs/10)+0x30; 00885 str[4]=(Secs%10)+0x30; 00886 } 00887 str[5]='\0'; 00888 00889 }
Generated on Fri Jul 15 2022 15:37:46 by
1.7.2