lecture de carte RFID et vérification par code PIN

Dependencies:   BSP_DISCO_F746NG

Files at this revision

API Documentation at this revision

Comitter:
maximej
Date:
Thu Jun 16 09:20:02 2022 +0000
Parent:
4:1e2613cedb60
Commit message:
JANEZ_Maxime_rendu_final

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1e2613cedb60 -r 03d1097de75e main.cpp
--- a/main.cpp	Wed Jun 15 15:20:50 2022 +0000
+++ b/main.cpp	Thu Jun 16 09:20:02 2022 +0000
@@ -4,20 +4,17 @@
 
 
 BufferedSerial RFID(D1, D0, 9600); // initialisation de la liaison TX RX
+//AnalogOut gache(A0);
 
 int main()
 {
-    
+    // variable de detection tactile   
     TS_StateTypeDef TS_State;
     uint16_t x, y;
     uint16_t X, Y;
-    uint8_t text[30];
     uint8_t status;
-    uint8_t idx;
-    uint8_t cleared = 0;
-    uint8_t prev_nb_touches = 0;
     
-
+    // init de la carte
     BSP_LCD_Init();
     BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
     BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
@@ -47,16 +44,16 @@
     BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
     BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
     
-    // déclaration des variables
+    // déclaration des variables 
     
-    int cara1 = 0;
+    int cara1 = 0; // caractère du code pin
     int cara2 = 0;
     
-    uint8_t tab1[5];
+    uint8_t tab1[5]; // stokage des caractères pour les cases
     uint8_t tab2[5];
     
-    int code = 0;
-    int carteRFID = 0;
+    int code = 0;   // si code pin bon = 1
+    int carteRFID = 0; // si pass bon = 1
 
     while(1) 
     {        
@@ -73,7 +70,7 @@
         BSP_LCD_DisplayStringAt(265,230  ,(uint8_t *)" 9 ", LEFT_MODE);
         BSP_LCD_DisplayStringAt(326,230  ,(uint8_t *)" CLEAR ", LEFT_MODE);
     
-        //Creation des 2 zone du code pin 
+        //Creation des 2 zones du code pin 
         
         BSP_LCD_DrawRect(80,75,40,40);// zone 1
         BSP_LCD_DrawRect(150,75,40,40);// zone 2
@@ -93,20 +90,26 @@
         
         BSP_LCD_DisplayStringAt(0,LINE(1),(uint8_t *)"PROJET GACHE, JANEZ MAXIME", CENTER_MODE);
         
-        if(RFID.readable())
+        if(RFID.readable()) // lecture de la carte RFID
         {
             char buffer[100];
             RFID.read(buffer,100);
             printf("%s\r\n", buffer); 
-            BSP_LCD_DisplayStringAt(40,50  ,(uint8_t *)buffer, LEFT_MODE);
+            //BSP_LCD_DisplayStringAt(40,50  ,(uint8_t *)buffer, LEFT_MODE);
             
             if ( buffer[0] == '0' && buffer[1] == 'D' && buffer[2] == '0' && buffer [3] == '0')
             {
                 carteRFID = 1;
-            }    
+                BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)" PASS CORRECT ", CENTER_MODE);
+            }
+            else 
+            {
+                carteRFID = 0;
+                BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"PASS INCORRECT", CENTER_MODE);
+            }   
         }
 
-        // choix du 1er caractère 
+        // choix du 1er caractère du code pin
         
         if(cara1 == 0 && carteRFID == 1)
         {
@@ -215,7 +218,7 @@
                 {
                     if(Y > 210 && Y < 260)
                     {
-                        // clear des 4 caratères 
+                        // clear des 2 caratères 
                         cara1 = 0;
                         cara2 = 0;
                     }
@@ -227,8 +230,8 @@
         sprintf((char*)tab1, "%d" , cara1);
         BSP_LCD_DisplayStringAt(95,95  ,(uint8_t *)&tab1, LEFT_MODE);
         
-        
-                // écriture du 2nd caractère 
+             
+                // choix du 2nd caractère du code pin 
 
         if(cara1 != 0)
         {
@@ -348,60 +351,26 @@
         sprintf((char*)tab2, "%d" , cara2);
         BSP_LCD_DisplayStringAt(170,95  ,(uint8_t *)&tab2, LEFT_MODE); 
     
-        if (cara1 == 3 && cara2 == 9)
+        if (cara1 == 3 && cara2 == 9) // vérification du bon code pin
         {
-            code = 1;  
+            code = 1;
+            if ( carteRFID == 1 && code == 1)  // si le pass + code bon 
+            {
+                //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"CODE BON, ACCES AUTORISER", CENTER_MODE);
+                BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
+                BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)" CODE CORRECT ", CENTER_MODE);
+                //gache = 1;
+                //HAL_Delay(1000);
+                
+            }  
         }
         else 
         {
-            BSP_LCD_DisplayStringAt(0, LINE(2)  ,(uint8_t *)"Code incorrect", CENTER_MODE);
+            BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
+            BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"CODE INCORRECT", CENTER_MODE);
         }
-        
-        if ( carteRFID == 1 && code == 1)
-        {
-            BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"CODE BON, ACCES AUTORISER", CENTER_MODE);
-        }
-        
+        // détection des cordonnées tactile
         BSP_TS_GetState(&TS_State);
-          
-        if (TS_State.touchDetected) 
-        {
-            // Clear lines corresponding to old touches coordinates
-            if (TS_State.touchDetected < prev_nb_touches) 
-            {
-                for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) 
-                {
-                    BSP_LCD_ClearStringLine(idx);
-                }
-            }
-            prev_nb_touches = TS_State.touchDetected;
-
-            cleared = 0;
-
-            sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
-            BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
-
-            for (idx = 0; idx < TS_State.touchDetected; idx++) 
-            {
-                x = TS_State.touchX[idx];
-                y = TS_State.touchY[idx];
-                sprintf((char*)text, "Touch %d: x=%d y=%d    ", idx+1, x, y);
-                BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
-            }
-
-
-            //BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE);
-        } 
-        else 
-        {
-            if (!cleared) 
-            {
-                BSP_LCD_Clear(LCD_COLOR_BLACK);
-                sprintf((char*)text, "Touches: 0");
-                BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
-                cleared = 1;
-            }
-        }
         X = TS_State.touchX[0];
         Y = TS_State.touchY[0];       
     }