-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindexRecording.html
289 lines (211 loc) · 8.52 KB
/
indexRecording.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyoRecorderDB</title>
<script src="/socket.io/socket.io.js"></script>
<!-- Your url goes here -->
<base href="http://127.0.0.1:8080/MyoWebToolkit/" />
<!-- Css for the site -->
<link rel="stylesheet" href="css/styleRecording.css">
<!-- jQuery are usefull coding tools for javascript -->
<script src="libs/jquery-1.12.0.min.js"></script>
<!-- Flot is the plotting library -->
<script src="libs/Flot/jquery.flot.js"></script>
<!-- Myo.js is the library for connecting via websocket to Myo device -->
<script src='myo/myo2.js'></script>
<!-- imu_emg_Graphs is a library for plotting Myo signals -->
<script src='myo/imu_emg_Graphs.js'></script>
<script>
isRecording = false;
// We start with Myo disconnected. It is not necessary to record non-annotated signals
Myo.connect();
// node.js socket for sending signals to node.js server
var socket = io();
// Myo data callbacks.
// 1. When emg input comes from myo send it to node js
Myo.on("emg", function(data){
rawData = data;
if (isRecording) {
// For graphs visualization
$.each($(".pod"),function(a,b){b.style.backgroundColor="red";});
// Send raw Data to Node.js // LF character (change line)
socket.emit("append", "EMG;" + (new Date).getTime() + ";" + data + String.fromCharCode(10));
}else{
$.each($(".pod"),function(a,b){b.style.backgroundColor="#fefdff";});
}
$("#batteryIndicator").text("BATTERY LEVEL:" + Myo.myos[0].requestBatteryLevel().batteryLevel);
}); // End of Myo.on
// 2. When imu input comes from myo send it to node js
Myo.on("imu", function(quant){
// Send raw Data to Node.js
if (isRecording)
socket.emit("append", "IMU;" + (new Date).getTime() + ";" + JSON.stringify( quant) + String.fromCharCode(10) );
});
</script>
</head>
<body>
<!-- HTML -------------------------------------------- -->
<!-- Two html pages: 1. Give nickname, 2. MainMyoRecording -->
<ul class="pages">
<!-- Give nickname (to name the datafile in recordings/data_[mynickname]_[mymove].txt -->
<li class="login page">
<div class="form">
<h3 class="title">What's your nickname?</h3>
<input id="usernametextfield" class="usernameInput" type="text" maxlength="14" autofocus />
<div id="oknamebutton" onclick="setUsername()">OK</div>
</div>
</li>
<!-- Main Myo Recording page -->
<li class="myo page">
<div id="batteryIndicator">BATTERY: </div>
<!-- Signal subplots -->
<div id='pod0' class='pod'>Pod 1</div>
<div id='pod1' class='pod'>Pod 2</div>
<div id='pod2' class='pod'>Pod 3</div>
<div id='pod3' class='pod'>Pod 4</div>
<div id='pod4' class='pod'>Pod 5</div>
<div id='pod5' class='pod'>Pod 6</div>
<div id='pod6' class='pod'>Pod 7</div>
<div id='pod7' class='pod'>Pod 8</div>
<!-- Main interaction area -->
<div class="interactionArea">
<!-- Show some hints for the subject to follow -->
<div id="texthint">1. Myo at LEFT arm.<br />2. Press NEXT for hint video.<br /> 3. Press DO & REC to record. </div>
<!-- Show a video for the movement to do -->
<div class="imagehint">
<video id="videohint" width="480" height="270" autoplay>
<source src="" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<!-- The subject has the ability to go back and redo the recording (replace the old one) -->
<div id="back-button-triangle" onclick="gotoPrevious()">Back</div>
<!-- Go to next movement -->
<div id="next-button-triangle" onclick="gotoNext()">Next</div>
<!-- Some graphics for user-friendliness (an hour glass, cyclic) -->
<svg id="hourglass" width="100" height="100">
<circle id="circle1" cx="100" cy="50" r="50" fill="red"/>
<path style="stroke: #2c3e50; stroke-dasharray:820; stroke-dashoffset:820; stroke-width:12; fill:transparent"
d="
M 95, 54
m -42.5, 0
a 42.5,42.5 0 1,0 95,0
a 42.5,42.5 0 1,0 -95,0
">
<!--d="-->
<!--M cx cy-->
<!--m -r, 0-->
<!--a r,r 0 1,0 (r * 2),0-->
<!--a r,r 0 1,0 -(r * 2),0-->
<!--"-->
<animate id='clockanim' attributeName="stroke-dashoffset" dur="2s" to="-820" repeatCount="0"/>
</path>
</svg>
<!-- Record Red button -->
<div class="round-button"
onclick="rec(); clockanim.beginElement()"
onmouseover=circle1.style.fill="#660000";
onmouseleave=circle1.style.fill="red">
Do <br /> & <br /> Rec
</div>
</div>
</li>
</ul>
<script>
currMovement = -1;
var $window = $(window);
var $usernameInput = $('.usernameInput'); // Input for username
var $loginPage = $('.login.page');
var $chatPage = $('.myo.page');
// Sets the client's username
function setUsername () {
username = cleanInput($usernameInput.val().trim());
// If the username is valid
if (username) {
$loginPage.fadeOut();
$chatPage.show();
$loginPage.off('click');
}
}
// Prevents input from having injected markup
function cleanInput (input) {
return $('<div/>').text(input).text();
}
// Videos and hints index
var allVideos = ["thumbFlex1.mp4", "indexFlex1.mp4", "middleFlex1.mp4", "ringFlex1.mp4", "smallFlex1.mp4"];
var allTextHints = ["Flex thumb finger",
"Flex index finger",
"Flex middle finger",
"Flex ring finger",
"Flex small finger"];
var nMoves = allVideos.length;
function gotoNext(){
// Do not capture in dead times
//Myo.disconnect();
isRecording = false;
console.log('Next', currMovement);
if (currMovement < nMoves-1) {
currMovement++;
document.getElementById("videohint").src = "videos/" + allVideos[currMovement];
document.getElementById("texthint").innerHTML = allTextHints[currMovement];
if (currMovement > 0)
document.getElementById('back-button-triangle').style.display ="flex";
jQuery("#circle1")[0].style.display = "flex";
jQuery(".round-button")[0].style.display = "block";
}
}
function gotoPrevious(){
//Myo.disconnect();
isRecording = false;
console.log('Previous', currMovement);
if (currMovement > 0) {
currMovement--;
document.getElementById("videohint").src = "videos/" + allVideos[currMovement];
document.getElementById("texthint").innerHTML = allTextHints[currMovement];
if (currMovement < 1) {
document.getElementById('back-button-triangle').style.display = "none";
}
}
}
// Record signals
function rec(){
console.log('record');
document.getElementById("videohint").src = "videos/" + allVideos[currMovement];
$("#circle1")[0].style.display = "none";
$(".round-button")[0].style.display = "none";
// Create the file to store the Myo data
socket.emit('createfile', {usr: username, action: allVideos[currMovement].split('.')[0]});
// Connect Myo *automatically the Myo.on callback in the begin sends the data to socket.js
//Myo.connect();
isRecording = true;
var t1 = (new Date()).getTime();
// Record for 3000 ms
setTimeout(
function(){
//Myo.disconnect();
isRecording = false;
$("#circle1")[0].style.display = "flex";
$(".round-button")[0].style.display = "block";
var t2 = (new Date()).getTime();
console.log("t2 - t1", t2-t1);
},
3000);
}
function initFunc() {
$('#usernametextfield').keypress(function(e){
if(e.keyCode==13) {
$('#oknamebutton').click();
console.log("initializing");
}
});
}
$('document').ready(initFunc());
// ! Important Close Myo when closing window
window.onbeforeunload = function() {
Myo.socket.close();
return null;
}
</script>
</body>
</html>