-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.html
157 lines (134 loc) · 2.85 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
<html>
<head>
<style type="text/css">
* {
user-select: none;
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: -moz-none;
-webkit-user-select: none;
-webkit-touch-callout: none;
}
table {
font-size:36px; font-family:Arial, Helvetica, sans-serif;
width: 100%;
height: 95%;
}
td {
text-align: center;
vertical-align: middle;
background-color: #CCCCCC;
}
td.down {
background-color: red;
}
td.disable {
background-color: #CCCCCC;
}
</style>
<script type="text/javascript">
var configTable = [
"d1", "d2", "d3", "fwd", "bwd", "tl", "tr", "sl", "sr",
]
var currMode = undefined
var connected = undefined
var timer = undefined
function init()
{
connected = false
configTable.forEach(function(id) {
var obj = document.getElementById("cell_" + id)
obj.addEventListener("mousedown", function(evt) {
mode(id)
})
obj.addEventListener("touchstart", function(evt) {
mode(id)
})
obj.addEventListener("mouseup", function(evt) {
mode("s")
})
obj.addEventListener("touchend", function(evt) {
mode("s")
})
obj.className = "disable"
})
var slog = document.getElementById("state_panel");
if("WebSocket" in window)
{
ws = new WebSocket("ws://"+window.location.hostname+":8001");
slog.innerHTML = "Connecting...";
ws.onopen = function() {
slog.innerHTML = "Connected";
};
ws.onclose = function() {
slog.innerHTML = "Disconnected:" + evt.data;
connected = false
};
ws.onmessage = function(evt) {
slog.innerHTML = "Connected - " + evt.data;
if(evt.data == "control mode")
connected = true;
}
ws.onerror = function(evt) {
log.innerHTML = "Error:" + evt.data;
}
}
else
{
ws = null;
slog.innerHTML = "WebSocket is not supported!";
}
}
function mode(id)
{
if(!connected)
return
if(id == currMode)
return
console.log("mode switch to " + id)
currMode = id
for(i in configTable) {
if(id == configTable[i])
document.getElementById("cell_" + configTable[i]).className = "down"
else
document.getElementById("cell_" + configTable[i]).className = "up"
}
_repeat()
}
function _repeat()
{
if(timer != undefined)
{
clearTimeout(timer)
timer = undefined
}
if(ws && connected)
{
ws.send(currMode)
if(currMode != "s")
timer = setTimeout(_repeat, 2000)
}
}
</script>
</head>
<body onload="init()">
<div id="state_panel"></div>
<table border=0>
<tr>
<td id="cell_d1">Dance1</td>
<td id="cell_d2">Dance2</td>
<td id="cell_d3">Dance3</td>
</tr>
<tr>
<td id="cell_tl">Turn Left</td>
<td id="cell_fwd">Forward</td>
<td id="cell_tr">Turn Right</td>
</tr>
<tr>
<td id="cell_sl">Shift Left</td>
<td id="cell_bwd">Backward</td>
<td id="cell_sr">Shift Right</td>
</tr>
</table>
</body>
</html>