-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.js
133 lines (117 loc) · 3.59 KB
/
get.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
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
var x, y, z; // Position Variables for
var vx, vy, vz; // Speed - Velocity
var ax, ay, az; // Acceleration
var ai; // data reporting interval (event.interval)
var arAlpha, arBeta, arGamma; // rotation acceleration angles
var delay = 100;
var vMultiplier = 0.01;
var alpha = 0;
var beta = 0;
var gamma = 0;
function ondeviceorientation(event) {
alert("ondeviceorientation");
alpha = event.alpha.toFixed(2);
beta = event.beta.toFixed(2);
gamma = event.gamma.toFixed(2);
}
function onDeviceMotion(event) {
alert("onDeviceMotion");
$("#printData").hide();
$("#header").hide();
$("#sources").hide();
ax = event.accelerationIncludingGravity.x.toFixed(2);
ay = event.accelerationIncludingGravity.y.toFixed(2);
az = event.accelerationIncludingGravity.z.toFixed(2);
ai = Math.round(event.interval * 100) / 100;
rR = event.rotationRate;
if (rR != null) {
arAlpha = rR.alpha;
arBeta = rR.beta).toFixed(2);
arGamma = rR.gamma.to;
} /*
ax = Math.abs(event.acceleration.x * 1000);
ay = Math.abs(event.acceleration.y * 1000);
az = Math.abs(event.acceleration.z * 1000);
*/
setInterval(function() {
$.get('data.php', {
'go': 1,
'x': ax,
'y': ay,
'z': az,
'a': alpha,
'b': beta,
'g': gamma,
'ar': arAlpha.toFixed(2),
'br': arBeta.toFixed(2),
'gr': arGamma.toFixed(2),
});
}, delay);
}
window.addEventListener("compassneedscalibration", function(event) {
alert('Your compass needs calibrating! Wave your device in a figure-eight motion');
event.preventDefault();
}, true);
/*
function onDeviceMotion(event) {
ax = event.accelerationIncludingGravity.x.toFixed(2);
ay = event.accelerationIncludingGravity.y.toFixed(2);
az = event.accelerationIncludingGravity.z.toFixed(2);
ai = Math.round(event.interval * 100) / 100;
rR = event.rotationRate;
if (rR != null) {
arAlpha = (rR.alpha).toFixed(2);
arBeta = (rR.beta).toFixed(2);
arGamma = (rR.gamma).toFixed(2);
} /*
ax = Math.abs(event.acceleration.x * 1000);
ay = Math.abs(event.acceleration.y * 1000);
az = Math.abs(event.acceleration.z * 1000);
setInterval(function() {
$.get('data.php', {
'go': 1,
'x': ax,
'y': ay,
'z': az,
'a': alpha,
'b': beta,
'g': gamma,
'ar': arAlpha,
'br': arBeta,
'gr': arGamma,
});
/*document.getElementById("xlabel").innerHTML = "X: " + ax;
document.getElementById("ylabel").innerHTML = "Y: " + ay;
document.getElementById("zlabel").innerHTML = "Z: " + az;
document.getElementById("ilabel").innerHTML = "I: " + ai;
document.getElementById("arAlphaLabel").innerHTML = "arA: " + arAlpha;
document.getElementById("arBetaLabel").innerHTML = "arB: " + arBeta;
document.getElementById("arGammaLabel").innerHTML = "arG: " + arGamma;
document.getElementById("alphalabel").innerHTML = "Alpha: " + alpha;
document.getElementById("betalabel").innerHTML = "Beta: " + beta;
document.getElementById("gammalabel").innerHTML = "Gamma: " + gamma;
}, delay);
}
/* Old stuff I don't think I need:
// function converting decimal values to hex values
function d2h(d) {
return d.toString(16);
}
// function for converting hex values to decimal
function h2d(h) {
return parseInt(h, 16);
}
// converts decimal numbers to HTML/Hex code color
function makecolor(a, b, c) {
red = Math.abs(a) % 255;
green = Math.abs(b) % 255;
blue = Math.abs(c) % 255;
return "#" + d2h(red) + d2h(green) + d2h(blue);
}
function makeacceleratedcolor(a, b, c) {
red = Math.round(Math.abs(a + az) % 255);
green = Math.round(Math.abs(b + ay) % 255);
blue = Math.round(Math.abs(c + az) % 255);
return "#" + d2h(red) + d2h(green) + d2h(blue);
}
*/