-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchild.js
80 lines (77 loc) · 2.03 KB
/
child.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
74
75
76
77
78
79
80
const ntClient = require('wpilib-nt-client');
const client = new ntClient.Client();
const now = require('performance-now');
var frame = 0;
var obj = null;
var previousTime = 0;
var firstLoop = true;
const sampleFrames = 60;
function handleMessage(msg) {
let newTime = now();
switch (msg.name) {
case "server":
client.start((isConnected, err) => {
if (err) {
throw err;
} else {
process.send({
name: "connected"
});
}
}, msg.data);
break;
case "data":
obj = msg.data;
process.send({
name: "received"
});
break;
case "pulse":
updateDisplay(newTime);
break;
}
}
function updateDisplay(newTime) {
let timeDiff = 0;
if (!firstLoop) {
timeDiff = newTime - previousTime;
} else {
firstLoop = false;
}
process.send({
name: "timing",
data: timeDiff
});
try {
switch (frame) {
case 3:
console.time(String(sampleFrames) + ' frames');
break;
case (sampleFrames + 3):
console.timeEnd(String(sampleFrames) + ' frames');
break;
}
obj[frame].forEach((scanline, row) => {
scanline.forEach((pixel, column) => {
var key_target = "/display/row" + String(row) + "/column" + String(column);
if (pixel == 1) {
client.Assign(true, key_target);
} else {
client.Assign(false, key_target);
}
});
});
client.Assign(frame, "/display/frame");
frame++;
} catch (e) {
client.stop();
client.destroy();
process.send("done");
process.exit();
}
previousTime = newTime;
}
process.on('message', handleMessage);
process.send({
name: "launched"
});