-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetectCardType.js
58 lines (42 loc) · 1.19 KB
/
detectCardType.js
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
53
54
55
56
import MFRC522 from "mfrc522-rpi";
import SoftSPI from "rpi-softspi";
console.log(SoftSPI);
console.log("Scanning...");
console.log("Please put chip or keycard in the antenna inductive zone!");
//SPI Configuration
const softSPI = new SoftSPI({
clock: 23, //pin number of SCLK
mosi: 19, //pin number of MOSI
miso: 21, //pin number of MISO
client: 24 //pin number of CS
});
//mfrc522 Handler
const mfrc522 = new MFRC522(softSPI).setResetPin(22).setBuzzerPin(18);
//main loop
setInterval(function() {
//reset card
mfrc522.reset();
//scan for cards
let response = mfrc522.findCard();
//No card
if (!response.status) {
console.log("No Card");
return;
}
console.log("Card detected, CardType: " + response.bitSize);
//get UID of the card
response = mfrc522.getUid();
if (!response.status) {
console.log("UID Scan Error");
return;
}
const uid = response.data;
console.log(
"Card read UID: 0x " + uid[0].toString(16) + " " + uid[1].toString(16) + " " + uid[2].toString(16) + " " + uid[0].toString(16)
);
//Scaned Card Selection
const memoryCapacity = mfrc522.selectCard(uid);
console.log("Card Memory Capacity:" + memoryCapacity);
//# Stop
mfrc522.stopCrypto();
}, 1000);