-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (59 loc) · 1.58 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var client = null,
releaseKeyboard = false,
home = String.fromCharCode(27) + '[H',
clearScreen = String.fromCharCode(27) + '[J',
lineFeed = String.fromCharCode(27) + '[1B',
lineAt = 1,
obj = null,
status = null;
var pinpad = module.exports = function(config) {
};
(function() {
this.cls = function() {
client.write(home);
client.write(clearScreen);
client.write(home);
lineAt = 1;
}
this.setObj = function(object) {
obj = object;
}
this.connect = function(options) {
status = options.sts;
client = require('net').Socket();
client.connect(options.port,options.ip);
client.on("error", function(err) {
console.log(err.stack)
});
pinpad.cls();
client.on("data",function(data) {
if (data.toString() == 'A') { //Keep sending function status to the pinpad
releaseKeyboard = false;
status(obj,client);
sleep(900,client);
} else if (data.toString().charCodeAt(0) == 13) { //clear the screen and realese the keyboard
pinpad.cls();
releaseKeyboard = true;
} else if (releaseKeyboard) {
//print on the screen what was press on the keyboard
pinpad.print(data.toString(),false);
}
});
};
this.print = function(text,jumpLine) {
client.write(text);
if (jumpLine) {
client.write(lineFeed);
lineAt += 1;
client.write(String.fromCharCode(27) + '[' + lineAt.toString() + ';1f');
};
};
}).call(pinpad);
function sleep(millis, cli) {
setTimeout(function()
{ if (!releaseKeyboard) {
sleep(millis,cli);
status(obj,cli); }
}
, millis);
}