-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscancard.c
52 lines (51 loc) · 1.67 KB
/
scancard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "card.h"
#include "cardlist.h"
#include "scancard.h"
#include "safeinput.h"
// Using red/green-light and delay-function from remotedoor.c
#include "remotedoor.h"
// Function to test the accessGranted-value of different cards in the register.
void scanCard(CARDLIST *cardList) {
int cardId = 0000;
GetInputInt("\nEnter the card ID-number: ", &cardId);
// Default value indicating the card ID is not found
int index = -1;
for (int i = 0; i < cardList->count; i++) {
if (cardList->list[i].cardId == cardId) {
index = i; // Card ID found
break;
}
}
if (index != -1) {
// Card ID found
printf("\nCard ID %d found.\n", cardId);
if (cardList->list[index].accessGranted) {
// If access is granted, simulate a green lamp
printf("Access: GRANTED.\n");
printf("\nDoor is opening...\n");
simulateGreenLamp();
printf("\n- Countdown - \n");
printf("3...\n");
delay(1000);
printf("2...\n");
delay(1000);
printf("1...\n");
delay(1000);
printf("\nDoor is now locked.\n");
simulateRedLamp();
} else {
// If access is denied, simulate red lamp
printf("Access: DENIED.\n");
printf("\nDoor is locked...\n");
simulateRedLamp();
}
} else {
// Card ID not found. Door remains locked.
printf("\nERROR: Card ID %d not found.\nAccess: DENIED.\n", cardId);
printf("\nDoor is locked...\n");
simulateRedLamp();
}
}