forked from denismr/iOSGyroForCemuhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.html
39 lines (36 loc) · 1.06 KB
/
static.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Gyro Client</title>
<style>
</style>
</head>
<body>
<p>Version: 1</p>
<p><label id="lblConnected"></label></p>
<script>
let bar = window.location.href;
let wsAddress = `ws://${bar.match(/^https?:\/\/([^:]+).+$/)[1]}:1337`;
console.log(wsAddress);
var ws = new WebSocket(wsAddress);
let scale = 960;
ws.onopen = function(ws_evnt) {
window.document.getElementById("lblConnected").textContent = "Connected";
window.ondevicemotion = function(motion) {
let data = {
ts: Date.now(),
gyro: {
x: scale * motion.rotationRate.alpha,
z: scale * motion.rotationRate.beta,
y: -scale * motion.rotationRate.gamma,
},
}
ws.send(JSON.stringify(data, function(key, val) {
return val.toFixed ? Number(val.toFixed(20)) : val;
}));
};
};
</script>
</body>
</html>