-
Notifications
You must be signed in to change notification settings - Fork 1
/
usetheforce.html
executable file
·199 lines (175 loc) · 5.82 KB
/
usetheforce.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
<!doctype html>
<!--
@author Bridget Lane
@url mason.gmu.edu/~blane3/theforce/usetheforce.html
@lastupdated 2014-04-28
@version 1.0.0
@comments start up the force
-->
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The iRobot Force: use the force</title>
<link rel="stylesheet" href="css/foundation.css" />
<link rel="normalize" href="css/normalize.css" />
<script src="js/vendor/modernizr.js"></script>
<script src="socket.io/socket.io.js"></script>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
</head>
<body>
<div class="row">
<div class="large-12 columns">
<h1 id="logo_small"><a href="index.html" style="text-decoration: none; color: white;" Title="home">the force</a></h1>
</div>
</div>
<script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script>
<div id="SkypeButton_Call_bigspender4812_1" style="text-align: center;">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_bigspender4812_1",
"participants": ["bigspender4812"],
"imageColor": "white",
"imageSize": 32
});
</script>
</div>
<div class="row" style="padding-bottom: 5%;">
<div class="large-8 large-centered columns">
<ul class="button-group round even-4">
<li><button onmousedown="forwards()" onmouseup="removeForward()" style="font-family: StarJedi;">Forward</button></li>
<li><button onmousedown="turnRight()" onmouseup="removeRight()" style="font-family: StarJedi;">Right</button></li>
<li><button onmousedown="turnLeft()" onmouseup="removeLeft()" style="font-family: StarJedi;">Left</button></li>
<li><button onmousedown="backwards()" onmouseup="removeBackward()" style="font-family: StarJedi;">Backward</button></li>
</ul>
</div>
</div>
<div class="row">
<div style="color: white; display: inline-block; float:left; padding-top:2%;">
<span>Speed: </span>
<span id="sliderOutput1"></span>
</div>
<div class="small-8 medium-9 small-centered medium-centered columns">
<div class="range-slider" data-slider data-options="start: 0; end: 25; display_selector:#sliderOutput1;">
<span class="range-slider-handle"></span>
<span class="range-slider-active-segment"></span>
</div>
</div>
</div>
<div class="row">
<div style="color: white; display: inline-block; float:left; padding-top:2%;">
<span>Turn Speed: </span>
<span id="sliderOutput2"></span>
</div>
<div class="small-8 medium-9 small-centered medium-centered columns">
<div class="range-slider" data-slider data-options="start: 0; end: 25; display_selector:#sliderOutput2;">
<span class="range-slider-handle"></span>
<span class="range-slider-active-segment"></span>
<input type="hidden">
</div>
</div>
</div>
<script>
$(document).foundation();
</script>
<script>
var speed = 12;
//$('sliderOutput1').foundation('sliderOutput1', 'set_value', speed);
/* $('[data-slider]').on('change', function(){
var tempSpeed = $('#sliderOutput1').attr('data-slider');
speed = parseInt(tempSpeed);
});*/
var turnSpeed = 12;
//$('sliderOutput2').foundation('sliderOutput2', 'set_value', turnSpeed);
/* $('[data-slider]').on('change', function(){
var tempTurnSpeed = $('#sliderOutput2').attr('data-slider');
turnSpeed = parseInt(tempTurnSpeed);
console.log($('#sliderOutput2').attr('data-slider'));
});*/
$('[data-slider]').on('change', function(){
speed = parseInt($('[data-slider]')[0].getAttribute('data-slider'));
turnSpeed = parseInt($('[data-slider]')[1].getAttribute('data-slider'));
});
var socket = io.connect();
var forward = false;
var backward = false;
var right = false;
var left = false;
document.onkeydown = function(event) {
event = event || window.event;
var e = event.keyCode;
if(e == 87)
forwards();
if(e == 83)
backwards();
if(e == 65)
turnLeft();
if(e == 68)
turnRight();
}
document.onkeyup = function(event) {
event = event || window.event;
var e = event.keyCode;
if(e == 87)
removeForward();
if(e == 83)
removeBackward();
if(e == 65)
removeLeft();
if(e == 68)
removeRight();
}
function forwards(){
forward = true;
sendSpeed();
}
function backwards(){
backward = true;
sendSpeed();
}
function turnRight(){
right = true;
sendSpeed();
}
function turnLeft(){
left = true;
sendSpeed();
}
function removeForward(){
forward = false;
sendSpeed();
}
function removeBackward(){
backward = false;
sendSpeed();
}
function removeRight(){
right = false;
sendSpeed();
}
function removeLeft(){
left = false;
sendSpeed();
}
function sendSpeed(){
var vertical = 0;
var horizontal = 0;
if(right && left)
horizontal = 0;
else if(right)
horizontal = -turnSpeed;
else if(left)
horizontal = turnSpeed;
if(forward && backward)
vertical = 0;
else if(forward)
vertical = speed;
else if(backward)
vertical = -speed;
socket.emit('updateSpeed', vertical, horizontal);
}
</script>
</body>
</html>