-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle.html
123 lines (111 loc) · 3.33 KB
/
vehicle.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head> <meta charset="UTF-8"/> <title>vehicle</title> </head>
<body onload="bodyOnLoad()">
Raspberry PI vehicle
</br>
</br>
<strong onmousedown="sockSend('forward')" onmouseup="sockSend('forward_stop')">#######forward#######</strong>
<table border="1">
<tr>
<td><strong onmousedown="sockSend('left_forward')" onmouseup="sockSend('left_forward_stop')">left_forward</strong></td>
<td><strong onmousedown="sockSend('right_forward')" onmouseup="sockSend('right_forward_stop')">right_forward</strong></td>
</tr>
<tr>
<td><strong onmousedown="sockSend('left_backward')" onmouseup="sockSend('left_backward_stop')">left_backward</strong></td>
<td><strong onmousedown="sockSend('right_backward')" onmouseup="sockSend('right_backward_stop')">right_backward</strong></td>
</tr>
</table>
<strong onmousedown="sockSend('backward')" onmouseup="sockSend('backward_stop')">#######backward#######</strong>
</br>
</br>
</br>
<strong onmousedown="sockSend('stop')" onmouseup="sockSend('stop')">stop all</strong>
</br>
</br>
</br>
<table border="1">
<tr>
<strong onmousedown="sockSend('forward')" onmouseup="sockSend('forward_stop')">#######forward#######</strong>
<td><strong onmousedown="sockSend('clockwise')" onmouseup="sockSend('stop')">clockwise</strong></td>
<td><strong onmousedown="sockSend('counterclockwise')" onmouseup="sockSend('stop')">counterclockwise</strong></td>
</tr>
</table>
<strong onmousedown="sockSend('backward')" onmouseup="sockSend('backward_stop')">#######backward#######</strong>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script>
var arrowing = false;
document.onkeydown = function checkKey(e) {
e = e || window.event;
if (arrowing) return;
switch (e.keyCode) {
case 38:
// up arrow
console.log("onkeydown:up");
sockSend("forward");
break;
case 40:
// down arrow
console.log("onkeydown:down");
sockSend("backward");
break;
case 37:
// left arrow
console.log("onkeydown:left");
sockSend("counterclockwise");
break;
case 39:
// right arrow
console.log("onkeydown:right");
sockSend("clockwise");
break;
default:
console.log(e.keyCode);
break;
}
arrowing = true;
}
document.onkeyup = function checkKey(e) {
sockSend("stop");
arrowing = false;
e = e || window.event;
if (e.keyCode == '38') {
// up arrow
console.log("onkeyup:up");
}
else if (e.keyCode == '40') {
// down arrow
console.log("onkeyup:down");
}
else if (e.keyCode == '37') {
// left arrow
console.log("onkeyup:left");
}
else if (e.keyCode == '39') {
// right arrow
console.log("onkeyup:right");
}
}
// Create a connection to http://localhost:[same as web server]/echo
var sock = new SockJS('/echo');
// Open the connection
sock.onopen = function() {
console.log('sock open');
};
// On connection close
sock.onclose = function() {
console.log('sock close');
};
// On receive message from server
sock.onmessage = function(e) {
// Get the content
var content = JSON.parse(e.data);
//console.log(content);
};
function sockSend(d) {
sock.send(JSON.stringify({require: d}));
}
</script>
</body>
</html>