-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgyro.js
88 lines (78 loc) · 3.8 KB
/
gyro.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
function visiblenow(target_alt, target_az, the_sat_id, the_sat_name) {
//check??
console.log("loaded");
function sat_found(alt, az, t_alt, t_az, eps) {
return (math.abs(alt-t_alt)<eps && math.abs(alt-t_alt)<eps);
}
function unlock_sat(d, sat_id, sat_name) {
d.innerHTML = "Sat found! Your satellite will now unlock.";
//inserts satellite
$.ajax({
data: {satellite_id: sat_id,
name: sat_name},
url: '../queries/insert_satellite.php',
method: 'GET', // or GET
async: false,
success: function(msg) {
//var response = JSON.parse(msg);
//console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
console.log(msg);
/*if (response=="1") {
return true;
} else {
return false;
}*/
}
});
//updates sat-user relationship (unlocks)
$.ajax({
data: {satellite_id: sat_id,
user_id: "1"},
url: '../queries/unlock_satellite.php',
method: 'GET', // or GET
async: false,
success: function(msg) {
//var response = JSON.parse(msg);
//console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
console.log(msg);
/*if (response=="1") {
return true;
} else {
return false;
}*/
}
});
//unlock sat end
}
var observation_info = document.querySelector('.observation-info');
var found_banner = document.querySelector('.found-banner');
var orientation_sensors = document.querySelector('.orientation_sensors');
observation_info.innerHTML = "Look at up and try to locate the satellite in the night sky. Then point your phone towards it to verify.";
var promise = FULLTILT.getDeviceOrientation({ 'type': 'world' });
promise.then(function(deviceOrientation) { // Device Orientation Events are supported
deviceOrientation.listen(function() {
var currentOrientation = deviceOrientation.getScreenAdjustedEuler();
var az = 360 - currentOrientation.alpha;
var alt = currentOrientation.beta;
orientation_sensors.innerHTML = "Sat is located at:<br>";
orientation_sensors.innerHTML += "alt:" + target_alt + "<br>";
orientation_sensors.innerHTML += "az:" + target_az + "<br>";
orientation_sensors.innerHTML += "You are now pointing at:<br>";
orientation_sensors.innerHTML += "alt:" + math.round(alt) + "<br>";
orientation_sensors.innerHTML += "az:" + math.round(az) + "<br>";
if (sat_found(alt, az, target_alt, target_az, 20)) {
unlock_sat(found_banner, the_sat_id, the_sat_name);
}
});
}).catch(function(errorMessage) { // Device Orientation Events are not supported
console.log(errorMessage);
observation_info.innerHTML = "";
orientation_sensors.innerHTML = "Couldn't detect orientation sensors. Please try a different browser and/or device.<br> You can scan the following QRcode and open this page on your smartphone instead.<br>";
var qrcode = new QRCode("qrcode");
function makeCode () {
var elText = document.location.href;
qrcode.makeCode(elText);
}
makeCode();
});
}