forked from wdauwen/picar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile.html
167 lines (149 loc) · 4.47 KB
/
mobile.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
<!DOCTYPE HTML>
<html>
<head>
<style>
body { margin: 0px; padding: 0px; }
canvas { border: 1px solid #9C9898; }
</style>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.7.1-beta.js"></script>
<script>
var socket = new WebSocket("ws://" + window.location.hostname + ":" + window.location.port + "/ws");
socket.onopen = function(){
console.log("connected");
};
socket.onmessage = function (message) {
console.log("receiving: " + message.data);
};
socket.onclose = function(){
console.log("disconnected");
};
sendMessage = function(message) {
socket.send(message);
};
var value = 0;
window.onload = function() {
var stage = new Kinetic.Stage({
container: "container",
width: 200,
height: 300
});
var layer = new Kinetic.Layer();
var circle = new Kinetic.Circle({
x: 100,
y: 50,
radius: 30,
fill: "blue",
stroke: "black",
strokeWidth: 4,
draggable: false
});
circle.on("touchstart", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({forward: timedelay}));
});
circle.on("touchend", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({stop: timedelay}));
});
layer.add(circle);
var circle2 = new Kinetic.Circle({
x: 100,
y: 200,
radius: 30,
fill: "green",
stroke: "black",
strokeWidth: 4,
draggable: false
});
circle2.on("touchstart", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({reverse: timedelay}));
});
circle2.on("touchend", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({stop: timedelay}));
});
layer.add(circle2);
var circle3 = new Kinetic.Circle({
x: 150,
y: 150,
radius: 30,
fill: "red",
stroke: "black",
strokeWidth: 4,
draggable: false
});
circle3.on("touchstart", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({right: timedelay}));
});
circle3.on("touchend", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({stop: timedelay}));
});
layer.add(circle3);
var circle4 = new Kinetic.Circle({
x: 50,
y: 150,
radius: 30,
fill: "red",
stroke: "black",
strokeWidth: 4,
draggable: false
});
circle4.on("touchstart", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({left: timedelay}));
});
circle4.on("touchend", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({stop: timedelay}));
});
layer.add(circle4);
var circle5 = new Kinetic.Circle({
x: 150,
y: 250,
radius: 30,
fill: "red",
stroke: "black",
strokeWidth: 4,
draggable: false
});
circle5.on("touchstart", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({pivotright: timedelay}));
});
circle5.on("touchend", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({stop: timedelay}));
});
layer.add(circle5);
var circle6 = new Kinetic.Circle({
x:
y: 250,
radius: 30,
fill: "red",
stroke: "black",
strokeWidth: 4,
draggable: false
});
circle6.on("touchstart", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({pivotleft: timedelay}));
});
circle6.on("touchend", function() {
var timedelay = 0.030
sendMessage(JSON.stringify({stop: timedelay}));
});
layer.add(circle6);
stage.add(layer);
};
</script>
</head>
<body>
<h1>Websockettest for Picar1</h1>
<p>This is a websocket testpage for Willem Dauwen's thesis at UCLL, formerly known as ACE Group T</p>
<p>The aim of this project is to drive an RC car over wifi signals from a remote pc, tablet or mobile device</p>
<div id="container"></div>
</body>
</html>