project van rtos

Dependencies:   mbed-os

Fork of MFRC522 by Martin Olejar

Files at this revision

API Documentation at this revision

Comitter:
Bram122
Date:
Thu May 17 13:52:41 2018 +0000
Parent:
9:f1f71e42e267
Commit message:
Gefixt doordat Danilo zijn laptop kut deed ;p

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f1f71e42e267 -r 65c046928e5d main.cpp
--- a/main.cpp	Thu May 17 11:53:09 2018 +0000
+++ b/main.cpp	Thu May 17 13:52:41 2018 +0000
@@ -45,10 +45,14 @@
 DigitalOut IN3(p13);
 DigitalOut IN4(p14);
 
+DigitalIn  POWER(p17);
+
 float sensorValue = 0.0000;
 
 int speedcontrol = 0.00001;
 
+bool loggedIn = 0;
+
 int sevenSeg;
 
 void light7Seg(int nr, int output) {
@@ -249,6 +253,8 @@
 
 void motorControl() {
     while(true) {
+        bool PWR = POWER.read();
+        if(loggedIn == 1 && PWR == 1) {
             IN1 = 1;
             IN2 = 0;
             IN3 = 1;
@@ -280,6 +286,9 @@
             
             //Thread::wait(speedcontrol - speedcontrol/sensorValue);
             Thread::wait(100-100*sensorValue);
+        } else {
+            Thread::wait(100);
+        }
     }
 }
 
@@ -308,7 +317,6 @@
 
 void samplePotentio() {
     while (true) {
-        pc.printf("ik sample. %f ", sensorValue);
         float samples[20];
         float sum = 0;
         for(int i = 0; i < 20; i++) {
@@ -324,6 +332,9 @@
 
 
 void checkRFID() {
+  pc.printf("start rfid");
+  uint8_t mastercard [] = {0x04, 0x89, 0x39, 0x1a, 0xee, 0x32, 0x80};
+  bool mastercardFound = 0;
   // Init. RC522 Chip
   RfChip.PCD_Init();
   while (true) {  
@@ -346,14 +357,29 @@
     pc.printf("Card UID: ");
     for (uint8_t i = 0; i < RfChip.uid.size; i++)
     {
-      pc.printf(" %X02 ", RfChip.uid.uidByte[i]);
+      led2 = 1;
+      pc.printf("card: %02x ", RfChip.uid.uidByte[i]);
+      pc.printf("master: %02x ", mastercard[i]);
+      if (RfChip.uid.uidByte[i] != mastercard[i]) {
+          mastercardFound = 0;
+          break;
+      } else {
+          mastercardFound = 1;
+      }
     }
-    pc.printf("\n\r");
+    pc.printf("\r\n");
 
-    // Print Card type
-    uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
-    pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
+    led3 = 1;
+    
+    if (mastercardFound == 1) {
+        led4 = 1;
+        loggedIn = !loggedIn;
+        led1 = loggedIn;
+    }
     Thread::wait(1000);
+    led2 = 0;
+    led3 = 0;
+    led4 = 0;
   }
 }
     
@@ -364,8 +390,8 @@
   Thread thread_sample;
   thread_sample.start(samplePotentio);
   
-  Thread thread_control;
-  thread_control.start(control);
+  /*Thread thread_control;
+  thread_control.start(control);*/
    
   Thread thread_motor(osPriorityRealtime);
   thread_motor.start(motorControl);