-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
executable file
·213 lines (192 loc) · 6.57 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PiBoat</title>
<meta name="author" content="richet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<!--link href="css/style.css" rel="stylesheet"-->
<link href="css/font-awesome.min.css" rel="stylesheet">
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<!--script src="node_modules/ws/index.js" type="text/javascript"></script-->
</head>
<body>
<h1>View</h1>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-12">
<div class="media well">
<!--div class="jsmpeg" data-url="video.ts"></div-->
<center><img id='view' src="http://localhost:8080/stream/video.mjpeg" alt="View" width="100%"></img></center>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4">
</div>
<div class="col-xs-4">
<div class="row">
<div class="col-xs-12">
<center>
<button name="forward" id="forward" class="btn btn-default" href="" aria-label="Forward">
<i class="fa fa-arrow-up" aria-hidden="true"></i>
</button>
<script>
$('#forward').click(function(e) {
e.preventDefault();
$.post('/forward')
});
</script>
</center>
</div>
</div>
</div>
<div class="col-xs-4">
</div>
</div>
<br/>
<div class="row">
<div class="col-xs-4">
<div class="row">
<div class="col-xs-12">
<center>
<button name="left" id="left" class="btn btn-default" href="" aria-label="Left">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
</button>
<script>
$('#left').click(function(e) {
e.preventDefault();
$.post('/left')
});
</script>
</center>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="row">
<div class="col-xs-12">
<center>
<button name="stop" id="stop" class="btn btn-default" href="" aria-label="Stop">
<i class="fa fa-stop" aria-hidden="true"></i>
</button>
<script>
$('#stop').click(function(e) {
e.preventDefault();
$.post('/stop')
});
</script>
</center>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="row">
<div class="col-xs-12">
<center>
<button name="right" id="right" class="btn btn-default" href="" aria-label="Right">
<i class="fa fa-arrow-right" aria-hidden="true"></i>
</button>
<script>
$('#right').click(function(e) {
e.preventDefault();
$.post('/right')
});
</script>
</center>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-xs-4">
</div>
<div class="col-xs-4">
<div class="row">
<div class="col-xs-12">
<center>
<button name="backward" id="backward" class="btn btn-default" href="" aria-label="Backward">
<i class="fa fa-arrow-down" aria-hidden="true"></i>
</button>
<script>
$('#backward').click(function(e) {
e.preventDefault();
$.post('/backward')
});
</script>
</center>
</div>
</div>
</div>
<div class="col-xs-4">
</div>
</div>
</div>
</div>
</div>
<script>
var ip = location.host;
$("#view").attr("src", "http://"+ip+":8080/stream/video.mjpeg");
console.log("ip: "+ip);
</script>
<h1 id="start"></h1>
<script>
// Setup websocket to pass controller actions to server
//@ref: https://hackernoon.com/nodejs-web-socket-example-tutorial-send-message-connect-express-set-up-easy-step-30347a2c5535
var ws = new WebSocket('ws://'+location.host+':3000');
// event emmited when connected
ws.onopen = function () {
console.log('websocket is connected ...')
// sending a send event to websocket server
ws.send('connected')
}
// event emmited when receiving message
ws.onmessage = function (ev) {
console.log(ev);
}
window.addEventListener('gamepadconnected', (event) => {
const update = () => {
const output = document.getElementById('axes');
output.innerHTML = ''; // clear the output
for (const gamepad of navigator.getGamepads()) {
if (!gamepad) continue;
for (const [index, axis] of gamepad.axes.entries()) {
output.insertAdjacentHTML('beforeend',
`<label>${gamepad.index}, ${index}
<progress value=${axis * 0.5 + 0.5}></progress>
</label>`);
console.log("index: "+index);
console.log("gamepad.axes: "+gamepad.axes);
var i = index;
var speed = 0;
var angle = 0;
if (i==0) {
if (angle != gamepad.axes[i]) {
angle = gamepad.axes[i];
console.log("angle: "+angle);
ws.send("angle: "+angle);
}
}
if (i==1) {
if (speed != gamepad.axes[i]) {
speed = gamepad.axes[i];
console.log("speed: "+speed);
ws.send("speed: "+speed);
}
}
}
}
requestAnimationFrame(update);
};
update();
});
</script>
<div id="axes" style="display: flex; flex-direction: column;"></div>
</body>
</html>