the hub

Dependencies:   mbed MFRC522 UniGraphic

Revision:
9:914f2ea246bc
Parent:
8:2bcc87bbd034
Child:
10:2985dc4e40a5
--- a/main.cpp	Fri Dec 14 11:55:49 2018 +0000
+++ b/main.cpp	Fri Dec 14 20:41:26 2018 +0000
@@ -9,7 +9,10 @@
 #include "pavement_48x34.h"
 #include "TFT_MIPI.h"
 #include "SDFileSystem.h"
+#include "MFRC522.h"
+#define MF_RESET PC_6
 Serial pc(SERIAL_TX, SERIAL_RX);
+MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
 PinName buspins[] = { PA_9, PC_7, PA_10, PB_3, PB_5, PB_4, PB_10, PA_8 };
 TFT_MIPI myLCD(BUS_8, buspins, A3, A4, A2, A1, A0, "myLCD");
 DigitalIn Sw[] = {PB_13, PB_14, PB_15, PB_2, PB_12,PA_11 };
@@ -21,7 +24,7 @@
 int i=0;
 int j=0;
 int k=0;
-int Pagejawjiw = 1;
+int Pagejawjiw = 0;
 int state = 0;
 int main()
 {   //while(1){
@@ -29,6 +32,11 @@
 //    wait(0.3);
 //    pc.printf("BOOO\n");
 //    }}
+    char *StudentID;
+    uint8_t UIDCard[4]={};
+    pc.printf("starting...\n");
+    RfChip.PCD_Init();
+
     myLCD.set_orientation(orient);
     int time;
     t.start();
@@ -36,26 +44,42 @@
     myLCD.foreground(foregroundcolor);    
     myLCD.cls();
 
-    while(1){   
-        //if(Sw[0] == 0){
-//        wait(0.3);
-//        pc.printf("BOOO\n");
-    //}
-        //myLCD.background(backgroundcolor);
-//        myLCD.foreground(foregroundcolor);
-//        myLCD.Bitmap(150,45,180,180,data);
-//        myLCD.fillrect(0,320,500,280,Orange);
-//        time=t.read_us();
-//        for(int i=2; i<200;i++){
-//                myLCD.locate(i,295);
-//                myLCD.set_font((unsigned char*) Arial12x12);
-//                myLCD.printf("Please scan your Student ID card to start.");
+    while(1){  
+        if(Pagejawjiw == 0){
+            //if(Sw[0] == 0){
+//            wait(0.3);
+//            pc.printf("BOOO\n");
 //        }
-//        for(int i=200; i>=2;i--){
-//                myLCD.locate(i,295);
-//                myLCD.set_font((unsigned char*) Arial12x12);
-//                myLCD.printf("Please scan your Student ID card to start.");
-//        }}
+            myLCD.background(backgroundcolor);
+            myLCD.foreground(foregroundcolor);
+            myLCD.Bitmap(150,45,180,180,data);
+            myLCD.fillrect(0,320,500,280,Orange);
+            time=t.read_us();
+            for(int i=2; i<200;i++){
+                    myLCD.locate(i,295);
+                    myLCD.set_font((unsigned char*) Arial12x12);
+                    myLCD.printf("Please scan your Student ID card to start.");
+                    if ( ! RfChip.PICC_IsNewCardPresent()){pc.printf("GOOOOOOOOO\n",StudentID);wait_ms(10);continue;}
+                    if ( ! RfChip.PICC_ReadCardSerial()){pc.printf("!!!!!!!!!!!!!!!",StudentID);wait_ms(10);continue;}
+            }
+            for(int i=200; i>=2;i--){
+                    myLCD.locate(i,295);
+                    myLCD.set_font((unsigned char*) Arial12x12);
+                    myLCD.printf("Please scan your Student ID card to start.");
+                    if ( ! RfChip.PICC_IsNewCardPresent()){pc.printf("GOOOOOOOOO\n",StudentID);wait_ms(10);continue;}
+                    if ( ! RfChip.PICC_ReadCardSerial()){pc.printf("!!!!!!!!!!!!!!!",StudentID);wait_ms(10);continue;}
+            }
+            if ( ! RfChip.PICC_IsNewCardPresent()){wait_ms(10);continue;}
+            if ( ! RfChip.PICC_ReadCardSerial()){wait_ms(10);continue;}
+            pc.printf("Studen's ID: ");
+            for (uint8_t i = 0; i < RfChip.uid.size; i++){UIDCard[i] = RfChip.uid.uidByte[i];}
+            if (UIDCard[0]==187 and UIDCard[1]==164 and UIDCard[2]==90 and UIDCard[3]==127){StudentID = "60340500033"; pc.printf("%s\n",StudentID);Pagejawjiw = 1;myLCD.cls();}
+            else if (UIDCard[0]==60 and UIDCard[1]==135 and UIDCard[2]==56 and UIDCard[3]==59){StudentID = "60340500066"; pc.printf("%s\n",StudentID);Pagejawjiw = 0;}
+            else {StudentID="0"; pc.printf("%s\n",StudentID);}
+//            if (StudentID != "0"){Pagejawjiw = 1;myLCD.cls();}
+//            else {Pagejawjiw = 0;}
+            }
+        else if (Pagejawjiw == 1) {
       ///first page///
         //myLCD.cls();
 //        myLCD.fillrect(0,0,500,50,Orange);
@@ -87,7 +111,6 @@
 //        myLCD.printf("Other");
 //        wait(5);
         //do{
-            if(Pagejawjiw == 1){
                 if(i == 0 or Sw[2] == 0){
                     i++;
                     switch(i){
@@ -513,7 +536,7 @@
                 myLCD.Bitmap(150,45,180,180,data);
                 myLCD.fillrect(0,320,500,280,Orange);
                 time=t.read_us();
-                Pagejawjiw = 1;
+                Pagejawjiw = 0;
                 i = 0;
                 for(int i=2; i<350;i++){
                         myLCD.locate(i,295);
@@ -532,7 +555,8 @@
 //                    wait(0.3);
 //                    }
               }
-            //}
+//            }
+//            else {Pagejawjiw = 1;}
                 
         
         //point//