-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
150 lines (132 loc) · 5.11 KB
/
main.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var text = null;
var startAcc = false;
var startGravi = false;
var startGyro = false;
var startLinAcc = false;
console.log("acl ->" + typeof(Accelerometer));
let acl = null;
let lin_acl = null;
let gravi = null;
let gyro = null;
if (typeof(Accelerometer) === 'function')
acl = new Accelerometer({frequency:10});
if (typeof(LinearAccelerationSensor) === 'function')
lin_acl = new LinearAccelerationSensor({frequency:10});
if (typeof(GravitySensor) === 'function')
gravi = new GravitySensor({frequency:10});
if (typeof(Gyroscope) === 'function')
gyro = new Gyroscope({frequency:10});
console.log("acl" + acl);
console.log("linacl" + lin_acl);
console.log("gravi" + gravi);
console.log("gyro" + gyro);
function setText(text) {
game_text.innerText = text;
game_text.style.display = "none";
game_text.style.display = "block";
}
function main() {
game_text = document.getElementById("game_text");
acl.addEventListener('reading', e => {
document.getElementById("acc_x_val").innerHTML = Math.round(acl.x*1000)/1000;
document.getElementById("acc_y_val").innerHTML = Math.round(acl.y*1000)/1000;
document.getElementById("acc_z_val").innerHTML = Math.round(acl.z*1000)/1000;
});
acl.onerror = event => {
console.log(event.error.name, event.error.message);
document.getElementById("acc_status").innerHTML = event.error.message;
}
lin_acl.addEventListener('reading', e => {
document.getElementById("lin_acc_x_val").innerHTML = Math.round(lin_acl.x*1000)/1000;
document.getElementById("lin_acc_y_val").innerHTML = Math.round(lin_acl.y*1000)/1000;
document.getElementById("lin_acc_z_val").innerHTML = Math.round(lin_acl.z*1000)/1000;
});
lin_acl.onerror = event => {
console.log(event.error.name, event.error.message);
document.getElementById("lin_acc_status").innerHTML = event.error.message;
}
if (gravi) {
gravi.addEventListener('reading', e => {
document.getElementById("gravity_x_val").innerHTML = Math.round(gravi.x*1000)/1000;
document.getElementById("gravity_y_val").innerHTML = Math.round(gravi.y*1000)/1000;
document.getElementById("gravity_z_val").innerHTML = Math.round(gravi.z*1000)/1000;
});
gravi.onerror = event => {
console.log(event.error.name, event.error.message);
document.getElementById("gravity_status").innerHTML = event.error.message;
}
}
gyro.addEventListener('reading', e => {
document.getElementById("gyro_x_val").innerHTML = Math.round(gyro.x*1000)/1000;
document.getElementById("gyro_y_val").innerHTML = Math.round(gyro.y*1000)/1000;
document.getElementById("gyro_z_val").innerHTML = Math.round(gyro.z*1000)/1000;
});
gyro.onerror = event => {
console.log(event.error.name, event.error.message);
document.getElementById("gyro_status").innerHTML = event.error.message;
}
}
function startStopAcc() {
if (startAcc == false) {
document.getElementById("accStatus").innerHTML = "ON";
startAcc = true;
acl.start();
} else {
document.getElementById("accStatus").innerHTML = "OFF";
startAcc = false;
acl.stop();
document.getElementById("acc_x_val").innerHTML = "-";
document.getElementById("acc_y_val").innerHTML = "-";
document.getElementById("acc_z_val").innerHTML = "-";
document.getElementById("acc_status").innerHTML = "";
}
}
function startStopLinAcc() {
if (startLinAcc == false) {
document.getElementById("linAccStatus").innerHTML = "ON";
startLinAcc = true;
lin_acl.start();
} else {
document.getElementById("linAccStatus").innerHTML = "OFF";
startLinAcc = false;
lin_acl.stop();
document.getElementById("lin_acc_x_val").innerHTML = "-";
document.getElementById("lin_acc_y_val").innerHTML = "-";
document.getElementById("lin_acc_z_val").innerHTML = "-";
document.getElementById("lin_acc_status").innerHTML = "";
}
}
function startStopGravity() {
if (gravi) {
if (startGravi == false) {
document.getElementById("gravityStatus").innerHTML = "ON";
startGravi = true;
gravi.start();
} else {
document.getElementById("gravityStatus").innerHTML = "OFF";
startGravi = false;
gravi.stop();
document.getElementById("gravity_x_val").innerHTML = "-";
document.getElementById("gravity_y_val").innerHTML = "-";
document.getElementById("gravity_z_val").innerHTML = "-";
document.getElementById("gravity_status").innerHTML = "";
}
} else {
document.getElementById("gravityStatus").innerHTML = "SENSOR NOT SUPPORTED";
}
}
function startStopGyro() {
if (startGyro == false) {
document.getElementById("gyroStatus").innerHTML = "ON";
startGyro = true;
gyro.start();
} else {
document.getElementById("gyroStatus").innerHTML = "OFF";
startGyro = false;
gyro.stop();
document.getElementById("gyro_x_val").innerHTML = "-";
document.getElementById("gyro_y_val").innerHTML = "-";
document.getElementById("gyro_z_val").innerHTML = "-";
document.getElementById("gyro_status").innerHTML = "-";
}
}