แก้ให้แล้ว
Dependencies: NOKIA_5110 mbed
Fork of Lost-Found_BOX by
Diff: main.cpp
- Revision:
- 8:e683edc8a530
- Parent:
- 7:725f5fb7e3a3
- Child:
- 9:5944142f8b40
--- a/main.cpp Mon Dec 07 14:43:15 2015 +0000 +++ b/main.cpp Mon Dec 07 18:12:36 2015 +0000 @@ -19,6 +19,7 @@ #include "myESP.h" #include "myRFID.h" #include "myLCD4884.h" +#include <ctype.h> DigitalOut LedGreen(LED1); DigitalOut spi_address[2] = {SPI_CS,PB_4}; //Serial connection to PC for output @@ -84,60 +85,160 @@ myLcd.DrawString("Welcome to LOST & FOUND BOX V.1"); myLcd.stop(); - getStatus("192.168.1.88","/l-f-box/getdata.php?check=1",stat_uid); - if(stat_uid[0] > 0){ - mode = 0; //It have an item - }else{ - mode = 1; //Doesn't have an item - } + + while(true){//Loop around + wait(1); + getStatus("192.168.1.88","/l-f-box/getdata.php?check=1",stat_uid); //Recheck now status + + + + if(isalnum((int)stat_uid[0])){ + mode = 0; //It have an item + submode=-1; + }else{ + mode = 1; //Doesn't have an item + submode=0; + } + - while(mode == 0){ - if(submode == 0){ - myLcd.InitLcd(); - myLcd.DrawString("PLEASE TAP A CARD"); - myLcd.stop(); - submode++; - } - if(submode == 1){ - if ( ! RfChip.PICC_IsNewCardPresent()) - { - wait_ms(500); - continue; - } - // Select one of the cards - if ( ! RfChip.PICC_ReadCardSerial()) - { - wait_ms(500); - continue; + + while(mode == 0){ //Withdraw Process (Item in the box!) + pc.printf("Withdraw process..."); + if(stat_uid[0] == 'X'){ //Unlocked! + speak.speakRight(); + wait(0.5); + myLcd.InitLcd(); + myLcd.SetXY(20,2); + myLcd.DrawString("UNLOCKED!"); + myLcd.SetXY(16,2); + myLcd.DrawString("TAP A CARD..."); + myLcd.stop(); + submode = 0; + }else{ + wait(1); + getStatus("192.168.1.88","/l-f-box/getdata.php?check=1",stat_uid); //Recheck now status + + } + if(submode == 0){ //Get RFID for update withdrawer + if ( ! RfChip.PICC_IsNewCardPresent()) + { + wait_ms(500); + continue; + } + // Select one of the cards + if ( ! RfChip.PICC_ReadCardSerial()) + { + wait_ms(500); + continue; + } + speak.speak(); + wait(0.5); + myLcd.InitLcd(); + myLcd.DrawString("WAITING..."); + myLcd.stop(); + GetID(RFID); + getDataHTTP("192.168.1.88","/l-f-box/getdata.php?rfid=",IDs,sid,name,tel); // Data of withdrawer + submode ++; + } + if(submode == 1){ + updateWithdrawer("192.168.1.88","/l-f-box/update.php",sid); + wait(0.5); + myLcd.InitLcd(); + myLcd.SetXY(20,2); + myLcd.DrawString("WITHDRAW"); + myLcd.SetXY(16,2); + myLcd.DrawString("SUCCESSFUL"); + myLcd.stop(); + submode++; + } + if(submode == 2){//Check for item & return to empty position + mode = -1; } - speak.speak(); - submode ++; - } - if(submode == 2){ - wait(0.5); - myLcd.InitLcd(); - myLcd.DrawString("WAITING..."); - myLcd.stop(); - GetID(RFID); - getDataHTTP("192.168.1.88","/l-f-box/getdata.php?rfid=",IDs,sid,name,tel); - submode ++; } - if(submode == 3){ - wait(0.5); - myLcd.InitLcd(); - myLcd.DrawString("NAME : "); - myLcd.DrawString(name); - myLcd.SetXY(0,1); - myLcd.DrawString("TEL : "); - myLcd.DrawString(tel); - myLcd.stop(); + while(mode == 1){ //Deposit Process (No item in the box) + if(submode == 0){ //Ask for deposit + myLcd.InitLcd(); + myLcd.SetXY(20,1); + myLcd.DrawString("PLEASE"); + myLcd.SetXY(8,3); + myLcd.DrawString("TAP A CARD"); + + myLcd.stop(); + submode++; + } + if(submode == 1){ //Wait and Get Tap Card + if ( ! RfChip.PICC_IsNewCardPresent()) + { + wait_ms(500); + continue; + } + // Select one of the cards + if ( ! RfChip.PICC_ReadCardSerial()) + { + wait_ms(500); + continue; + } + speak.speak(); + submode ++; + } + if(submode == 2){ //Get depositor data. & Show depositor data + wait(0.5); + myLcd.InitLcd(); + myLcd.DrawString("WAITING..."); + myLcd.stop(); + GetID(RFID); + getDataHTTP("192.168.1.88","/l-f-box/getdata.php?rfid=",IDs,sid,name,tel); + submode ++; + + wait(0.5); + myLcd.InitLcd(); + myLcd.DrawString("NAME : "); + myLcd.SetXY(5,1); + + myLcd.DrawString(name); + myLcd.SetXY(0,3); + myLcd.DrawString("TEL : "); + myLcd.SetXY(5,4); + + myLcd.DrawString(tel); + myLcd.stop(); + } + if(submode == 3){ // Show depositor data on screen + newDepositor("192.168.1.88","/l-f-box/update.php",sid); + wait(0.5); + myLcd.InitLcd(); + myLcd.SetXY(20,1); + myLcd.DrawString("PLEASE"); + myLcd.SetXY(4,3); + myLcd.DrawString("CHECK ON WEB"); + myLcd.stop(); + + wait(3); + myLcd.InitLcd(); + myLcd.SetXY(10,0); + myLcd.DrawString("==CONTACT=="); + myLcd.SetXY(5,2); + myLcd.DrawString("NAME : "); + myLcd.SetXY(5,3); + + myLcd.DrawString(name); + myLcd.SetXY(0,4); + myLcd.DrawString("TEL : "); + myLcd.SetXY(5,5); + + myLcd.DrawString(tel); + myLcd.stop(); + + + submode=0; + mode = 0; + } // End Deposit Process } + } - - /* while (true) { LedGreen = 1;