-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotctrl.html
161 lines (133 loc) · 4.09 KB
/
robotctrl.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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Telepresence Robot Control</title>
<link rel="stylesheet" href="robotctrl.css" />
<script language="javascript" type="text/javascript">
document.onkeydown = onkeydown_handler;
document.onkeyup = onkeyup_handler;
is_key_down = false;
function onkeydown_handler(e)
{
e = e || window.event;
if (is_key_down == true) { return; }
if (e.keyCode == '37') { L.onmousedown(); }
else if (e.keyCode == '38') { F.onmousedown(); }
else if (e.keyCode == '39') { R.onmousedown(); }
else if (e.keyCode == '40') { B.onmousedown(); }
else if (e.keyCode == '83') { S.onmousedown(); }
is_key_down = true;
}
function onkeyup_handler(e)
{
e = e || window.event;
if ( (e.keyCode == '37') ||
(e.keyCode == '38') ||
(e.keyCode == '39') ||
(e.keyCode == '40') ||
(e.keyCode == '83') )
{
S.onclick();
is_key_down = false;
}
}
function init()
{
document.myform.url.value = "ws://localhost:8000/"
document.myform.inputtext.value = "Hello World!"
document.myform.disconnectButton.disabled = true;
}
function doConnect()
{
websocket = new WebSocket(document.myform.url.value);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
function onOpen(evt)
{
writeToScreen("connected\n");
document.myform.connectButton.disabled = true;
document.myform.disconnectButton.disabled = false;
}
function onClose(evt)
{
writeToScreen("disconnected\n");
document.myform.connectButton.disabled = false;
document.myform.disconnectButton.disabled = true;
}
function onMessage(evt)
{
writeToScreen("response: " + evt.data + '\n');
}
function onError(evt)
{
writeToScreen('error: ' + evt.data + '\n');
websocket.close();
document.myform.connectButton.disabled = false;
document.myform.disconnectButton.disabled = true;
}
function doSend(message)
{
writeToScreen("sent: " + message + '\n');
websocket.send(message);
}
function writeToScreen(message)
{
document.myform.outputtext.value += message
document.myform.outputtext.scrollTop = document.myform.outputtext.scrollHeight;
}
window.addEventListener("load", init, false);
function sendText()
{
doSend( document.myform.inputtext.value );
}
function clearText()
{
document.myform.outputtext.value = "";
}
function doDisconnect()
{
websocket.close();
}
</script>
<table cellspacing="0" cellpadding="0">
<tr>
<!-- text boxes and buttons -->
<td>
<form name="myform">
<p><textarea name="outputtext" rows="20" cols="50"></textarea></p>
<p><textarea name="inputtext" cols="50"></textarea></p>
<p><textarea name="url" cols="50"></textarea></p>
<p>
<input type="button" name=sendButton value="Send" onClick="sendText();">
<input type="button" name=clearButton value="Clear" onClick="clearText();">
<input type="button" name=disconnectButton value="Disconnect" onClick="doDisconnect();">
<input type="button" name=connectButton value="Connect" onClick="doConnect();">
</p>
</form>
</td>
<!-- spacer cell/column -->
<td width="100px"></td>
<!-- movement buttons -->
<td valign="top">
<table class="button" padding=5>
<tr align="center">
<td></td>
<td id="F" class="button" onmouseup=doSend("S") onmousedown=doSend("F")>F</td>
<td></td>
</tr>
<tr align="center">
<td id="L" class="button" onmouseup=doSend("S") onmousedown=doSend("L")>L</td>
<td id="B" class="button" onmouseup=doSend("S") onmousedown=doSend("B")>B</td>
<td id="R" class="button" onmouseup=doSend("S") onmousedown=doSend("R")>R</td>
</tr>
<tr><td height="50px"></td></tr>
<tr>
<td></td>
<td align="center" id="S" class="stopbutton" onclick=doSend("S")>STOP</td>
<td></td>
</table>
</td>
</tr>
</html>