forked from saipraveend/Omnibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
115 lines (90 loc) · 2.95 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
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>OmniBot Web Interface</title>
<meta name="description" content="A simple web interface to control the omni robot through internet">
<meta name="author" content="@saipraveend">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/underscore-min.js"></script>
<script type="text/javascript" src="js/backbone-min.js"></script>
<script type="text/javascript" src="js/joystick_view.js"></script>
</head>
<body>
<header>
<img src="images/logo.png">
Omni<strong>BOT</strong>
<div class="pubnub"></div>
</header>
<script type="text/html" id="joystick-view">
<canvas id="joystickCanvas" width="<%= squareSize %>" height="<%= squareSize %>" style="width: <%= squareSize %>px; height: <%= squareSize %>px;">
</canvas>
</script>
<div id="joystickContent" align="center">
</div>
<div>
x: <span id="xVal"></span><br/>
y: <span id="yVal"></span><br/>
</div>
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var joystickView = new JoystickView(150, function(callbackView){
$("#joystickContent").append(callbackView.render().el);
setTimeout(function(){
callbackView.renderSprite();
}, 0);
});
var settings = {
channel: 'Robot',
publish_key: 'pub-c-358b7e07-32d8-454b-a910-ad8208cb68c0',
subscribe_key: 'sub-c-25fb2b4a-6d97-11e5-b6e2-0619f8945a4f'
};
var x_old=0;
var y_old=0;
var pubnub = PUBNUB(settings);
pubnub.subscribe({
channel: 'Robot',
message: function(m){console.log(m)},
//connect : publish
});
joystickView.bind("verticalMove", function(y){
$("#yVal").html(y);
if (y == 1 && y!=y_old) {
pubnub.publish({
channel: settings.channel,
message: "up"
});
}
else if ( y == -1 && y!=y_old) {
pubnub.publish({
channel: settings.channel,
message: "down"
});
}
y_old = y;
});
joystickView.bind("horizontalMove", function(x){
$("#xVal").html(x);
if (x == 1 && x!=x_old) {
pubnub.publish({
channel: settings.channel,
message: "right"
});
}
else if ( x == -1 && x!=x_old) {
pubnub.publish({
channel: settings.channel,
message: "left"
});
}
x_old = x;
});
});
</script>
<footer>
</footer>
</body>
</html>