-
Notifications
You must be signed in to change notification settings - Fork 0
/
gyroGraphs.js
executable file
·70 lines (53 loc) · 1.32 KB
/
gyroGraphs.js
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
//This tells Myo.js to create the web sockets needed to communnicate with Myo Connect
Myo.connect('com.myojs.deviceGraphs');
Myo.on('gyroscope', function(quant){
updateGraph(quant);
})
var range = 500;
var resolution = 100;
var graphIMU;
var arrayOfZeros = Array.apply(null, Array(resolution)).map(Number.prototype.valueOf,0);
var graphDataIMU = {
x : arrayOfZeros.slice(0),
y : arrayOfZeros.slice(0),
z : arrayOfZeros.slice(0),
w : Array.apply(null, Array(resolution)).map(Number.prototype.valueOf,0)
}
$(document).ready(function(){
graphIMU = $('.orientationGraph').plot(formatFlotData(), {
colors: [ '#04fbec', '#ebf1be', '#c14b2a', '#8aceb5'],
xaxis: {
show: false,
min : 0,
max : resolution
},
yaxis : {
min : -range,
max : range,
},
grid : {
borderColor : "#427F78",
borderWidth : 1
}
}).data("plot");
});
var formatFlotData = function(){
return Object.keys(graphDataIMU).map(function(axis){
return {
label : axis + ' axis',
data : graphDataIMU[axis].map(function(val, index){
return [index, val]
})
}
});
}
var updateGraph = function(orientationData){
Object.keys(orientationData).map(function(axis){
graphDataIMU[axis] = graphDataIMU[axis].slice(1);
graphDataIMU[axis].push(orientationData[axis]);
});
graphIMU.setData(formatFlotData());
graphIMU.draw();
}
/*
*/