-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.js
50 lines (39 loc) Β· 1.32 KB
/
demo.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
const Cards = require('./Cards/Cards');
//Handle Card Tap event. This event is raised when a user taps his phone on the reader.
//Note that Cards must be installed on the phone.
function onCardTap(cardInfo)
{
if(!cardInfo.isSuccess)
{
console.log('Error reading card');
console.log(Cards.CardTapError[cardInfo.error]);
return;
}
console.log('Card read, user id: ');
console.log(cardInfo.cardDetails.userID);
/*Your code goes here!
Do whatever you want with the accepted User ID!
-----------------------
Example: Open the door, if the user is authorized
-----------------------
if(YourSystem.IsAuthorizedToOpenDoor(cardInfo.cardDetails.userID, doors.hallway))
{
YourSystem.OpenDoor(doors.hallway);
}
-----------------------
Example: Remove balance
----------------------
YourSystem.Users.ChangeBalance(cardInfo.cardDetails.userID, -10);*/
}
//Handles reader status change.
function onStatusChange(readerStatus)
{
console.log('Status changed!');
console.log(Cards.ReaderStatus[readerStatus]);
}
var readerCredentials = new Cards.ReaderCredentials('ABCD1234ABCD1234ABCD1234');
var readerSettings = new Cards.ReaderSettings('ACS - ACR122U PICC Interface');
var reader = new Cards.CardReader(readerSettings, readerCredentials);
reader.onStatusChange = onStatusChange;
reader.onCardTap = onCardTap;
reader.listen();