-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
88 lines (77 loc) · 2.11 KB
/
index.html
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
81
82
83
84
85
86
87
88
<!doctype html>
<html>
<head>
<title>Bus LED viewer</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; background-color: black; color: white}
</style>
</head>
<body>
<h1>LED viewer</h2>
<canvas id="led" width="580" height="930"></canvas>
<script src="/socket.io.js"></script>
<script src="/jquery.js"></script>
<script>
$(function () {
var curpainting = 0;
var width = 58;
var height = 93;
var mult = 8;
var pix = 5;
var c = document.getElementById("led");
var ctx = c.getContext('2d');
var socket = io();
socket.on('pixels', function(msgbuf) {
if (curpainting == 0) {
curpainting = 1;
var msg = new Uint8Array(msgbuf);
//console.log(msg);
if ((width * height * 3) != msg.byteLength) {
console.log("invalid bytelength, need " + (width * height * 3) + ", got " + msg.byteLength);
} else {
var flip = 0;
var i = 0;
ctx.save();
ctx.clearRect(0, 0, (width * mult), (height * mult));
for (y = 0; y < height; y++) { // >
for (x = 0; x < width; x++) { // >
ctx.fillStyle="rgb(" + msg[i] + ',' + msg[i+1] + ',' + msg[i+2] + ")";
if (y % 2 == 0 && y < 31) {
flip = 1;
} else if (y % 2 == 1 && y < 31) {
flip = 0;
} else if (y % 2 == 1 && y < 62) {
flip = 1;
} else if (y % 2 == 0 && y < 62) {
flip = 0;
} else if (y % 2 == 1 && y > 61) {
flip = 0;
} else if (y % 2 == 0 && y > 61) {
flip = 1;
}
if (flip == 1) {
ctx.fillRect((width - x - 1) * mult, y * mult, pix, pix);
} else {
ctx.fillRect((x) * mult, y * mult, pix, pix);
}
i += 3;
}
}
ctx.restore();
curpainting = 0;
// setTimeout(function() { curpainting = 0; }, 25);
}
} else {
console.log("skipping frame, still painting");
}
});
/* $('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
}); */
});
</script>
</body>
</html>