![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
แก้ให้แล้ว
Dependencies: NOKIA_5110 mbed
Fork of Lost-Found_BOX by
main.cpp
- Committer:
- mustwillza
- Date:
- 2015-12-07
- Revision:
- 8:e683edc8a530
- Parent:
- 7:725f5fb7e3a3
- Child:
- 9:5944142f8b40
File content as of revision 8:e683edc8a530:
//Test of cheap 13.56 Mhz RFID-RC522 module from eBay //This code is based on Martin Olejar's MFRC522 library. Minimal changes //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too //Connect as follows: //RFID pins -> Nucleo header CN5 (Arduino-compatible header) //---------------------------------------- //RFID IRQ=pin5 -> Not used. Leave open //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 //RFID MOSI=pin3 -> Nucleo SPI_MOSI=PA_7=D11 //RFID SCK=pin2 -> Nucleo SPI_SCK =PA_5=D13 //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 SlaveSelect //RFID RST=pin7 -> Nucleo =PA_9=D8 //3.3V and Gnd to the respective pins #include "mbed.h" #include "MFRC522.h" #include "NOKIA_5110.h" // Nucleo Pin for MFRC522 reset (pick another D pin if you need D8) #define MF_RESET D9 #include "speaker.h" #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 Serial esp(D8, D2); //tx rx Serial pc(SERIAL_TX, SERIAL_RX); Speakers speak(D3); DigitalOut lock(PB_13); MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); char buffers[5]={'\0'}; char IDs[17]={'\0'}; void wifiInitial(){ pc.baud(115200); esp.baud(9600); string ssid = "1544_2G"; string pass = "fiborobot" ; if(setupESP(ssid,pass) == 1) { pc.printf("System connected to %s with %s as password\n",ssid.c_str(),pass.c_str()); pc.printf("System Initialized :: ESP8266 Module Ready!\n"); wait(2); } } int main(void) { // Init. LCD Pin LcdPins myPins; myPins.sce = PB_4; //D5 ActiveLow SlaveSelect myPins.rst = PB_10; //D6 myPins.dc = PA_8; //D7 myPins.mosi = PA_7; //SPI_MOSI; myPins.miso = NC; myPins.sclk = PA_5; //SPI_SCK; // Init. LCD Chip NokiaLcd myLcd( myPins ); myLcd.InitLcd(); // LCD is reset and DDRAM is cleared myLcd.DrawString("System Initializing..."); myLcd.stop(); // Init. esp8266 wifiInitial(); char name[20]; char sid[20]; char tel[10]; char stat_uid[3]; // Init.RFID Variable uint8_t RFID[10]; int checker = 0; int checks = 0; int mode = 0; int submode = 0; pc.printf("starting...\n"); // Init. RC522 Chip RfChip.PCD_Init(); pc.printf("Begin RFID!\n"); /* ===== System Initialized ===== */ myLcd.InitLcd(); myLcd.DrawString("Welcome to LOST & FOUND BOX V.1"); myLcd.stop(); 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){ //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; } } 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; // Look for new cards if ( ! RfChip.PICC_IsNewCardPresent()) { wait_ms(500); continue; } // Select one of the cards if ( ! RfChip.PICC_ReadCardSerial()) { wait_ms(500); continue; } LedGreen = 0; myLcd.InitLcd(); myLcd.DrawString("Ready"); myLcd.stop(); checker = check(RFID); if(checks == 1) { if (checker == 1) { pc.printf("Right\n"); myLcd.InitLcd(); myLcd.DrawString("Right"); myLcd.stop(); checks = 0; speak.speakRight(); strcpy(IDs,""); continue; } else { pc.printf("Wrong!!\n"); myLcd.InitLcd(); myLcd.DrawString("Wrong!!"); myLcd.stop(); speak.speakWrong(); continue; } } // Print Card UID pc.printf("Card UID: "); for (uint8_t i = 0; i < RfChip.uid.size; i++) { pc.printf(" %X", RfChip.uid.uidByte[i]); } checker = check(RFID); speak.speak(); GetID(RFID); lock = 0; pc.printf("\n\r"); wait_ms(1000); checks = 1; } */ }