-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (68 loc) · 1.2 KB
/
index.js
File metadata and controls
73 lines (68 loc) · 1.2 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* ASCII to Hexa array translation
*/
const _convert = {
48: "0",
49: "1",
50: "2",
51: "3",
52: "4",
53: "5",
54: "6",
55: "7",
56: "8",
57: "9",
65: "A",
66: "B",
67: "C",
68: "D",
69: "E",
70: "F",
81: "A",
97: "A",
98: "B",
99: "C",
100: "D",
101: "E",
102: "F",
113: "A"
};
/**
* Current tag value
* @type String
*/
let _tag = "";
/**
* Module to handle handled RFID reader message
*/
const HandledRFIDReaderDecoder = {
/**
* Clear current tag value
* @returns {undefined}
*/
clear : () => {
_tag = "";
},
/**
* Handle keyboard event
* @param {Event} event
* @param {function} onValid
* @returns {Boolean}
*/
onInput: (event, onValid) => {
// if code is 84, it a tag prefix => clear value
if (event.keyCode === 84) {
_tag = "";
} else if (event.keyCode === 13) { // validation on "Enter" case
event.currentTarget.value = _tag;
if(typeof onValid === "function"){
onValid(_tag);
}
} else if (typeof _convert[event.keyCode] !== "undefined") { // add only if hexa input
_tag = _tag + _convert[event.keyCode];
}
// display blocked
return false;
}
};
module.exports = HandledRFIDReaderDecoder;