-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
67 lines (63 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gamepad Data</title>
<script>
let socket = new WebSocket("ws://192.168.10.103:8000");
socket.onopen = function (event) {
console.log("WebSocket 连接成功!");
document.getElementById("status").textContent = "连接成功";
};
socket.onmessage = function (event) {
let data = JSON.parse(event.data);
document.getElementById(
"button-0"
).textContent = `Button 0: ${data.directions[0]}`;
document.getElementById(
"button-1"
).textContent = `Button 1: ${data.directions[1]}`;
document.getElementById(
"button-2"
).textContent = `Button 2: ${data.directions[2]}`;
document.getElementById(
"button-3"
).textContent = `Button 3: ${data.directions[3]}`;
document.getElementById(
"button-4"
).textContent = `Button 4: ${data.right_buttons[0]}`;
document.getElementById(
"button-5"
).textContent = `Button 5: ${data.right_buttons[1]}`;
document.getElementById(
"button-6"
).textContent = `Button 6: ${data.right_buttons[2]}`;
document.getElementById(
"button-7"
).textContent = `Button 7: ${data.right_buttons[3]}`;
};
socket.onerror = function (error) {
console.error("WebSocket 错误:", error);
};
socket.onclose = function (event) {
console.log("WebSocket 连接关闭");
document.getElementById("status").textContent = "连接关闭";
};
</script>
</head>
<body>
<h1>Gamepad Data</h1>
<div id="status">连接中...</div>
<div id="data">
<p id="button-0">Button 0:</p>
<p id="button-1">Button 1:</p>
<p id="button-2">Button 2:</p>
<p id="button-3">Button 3:</p>
<p id="button-4">Button 4:</p>
<p id="button-5">Button 5:</p>
<p id="button-6">Button 6:</p>
<p id="button-7">Button 7:</p>
</div>
</body>
</html>