forked from cory/tildefriends
Oh. Device orientation is separate from location.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3295 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
f08b564755
commit
b908f63424
@ -6,6 +6,7 @@ var gCredentials;
|
|||||||
var gErrorCount = 0;
|
var gErrorCount = 0;
|
||||||
var gCommandHistory = [];
|
var gCommandHistory = [];
|
||||||
var gSendKeyEvents = false;
|
var gSendKeyEvents = false;
|
||||||
|
var gSendDeviceOrientationEvents = false;
|
||||||
var gGeolocatorWatch;
|
var gGeolocatorWatch;
|
||||||
|
|
||||||
var kMaxCommandHistory = 16;
|
var kMaxCommandHistory = 16;
|
||||||
@ -162,6 +163,14 @@ function receive(data) {
|
|||||||
if (navigator && navigator.geolocation && gGeolocatorWatch !== undefined) {
|
if (navigator && navigator.geolocation && gGeolocatorWatch !== undefined) {
|
||||||
navigator.geolocation.clearWatch(gGeolocatorWatch);
|
navigator.geolocation.clearWatch(gGeolocatorWatch);
|
||||||
}
|
}
|
||||||
|
} else if (line && line[0] && line[0].action == "setSendDeviceOrientationEvents") {
|
||||||
|
let value = line[0].value;
|
||||||
|
if (value && !gSendDeviceOrientationEvents) {
|
||||||
|
window.addEventListener("deviceorientation", deviceOrientation);
|
||||||
|
} else if (!value && gSendDeviceOrientationEvents) {
|
||||||
|
window.removeEventListener("deviceorientation", deviceOrientation);
|
||||||
|
}
|
||||||
|
gSendDeviceOrientationEvents = value;
|
||||||
} else {
|
} else {
|
||||||
print(document.getElementById(target), line);
|
print(document.getElementById(target), line);
|
||||||
}
|
}
|
||||||
@ -196,6 +205,18 @@ function geolocationError(error) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deviceOrientation(event) {
|
||||||
|
send({
|
||||||
|
event: 'deviceorientation',
|
||||||
|
orientation: {
|
||||||
|
alpha: event.alpha,
|
||||||
|
beta: event.beta,
|
||||||
|
gamma: event.gamma,
|
||||||
|
absolute: event.absolute,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function keyEvent(event) {
|
function keyEvent(event) {
|
||||||
send({
|
send({
|
||||||
event: "key",
|
event: "key",
|
||||||
@ -536,6 +557,8 @@ function connectSocket() {
|
|||||||
['getCurrentPosition', 'options'],
|
['getCurrentPosition', 'options'],
|
||||||
['watchPosition', 'options'],
|
['watchPosition', 'options'],
|
||||||
['clearWatch'],
|
['clearWatch'],
|
||||||
|
|
||||||
|
['setSendDeviceOrientationEvents', 'value'],
|
||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,41 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
core.register("geolocation", function(event) {
|
let gPosition = null;
|
||||||
terminal.print("hi");
|
let gOrientation = null;
|
||||||
|
let gError = null;
|
||||||
|
|
||||||
|
function draw() {
|
||||||
terminal.cork();
|
terminal.cork();
|
||||||
if (event.position) {
|
terminal.clear();
|
||||||
for (let field in event.position.coords) {
|
if (gPosition) {
|
||||||
let value = event.position.coords[field];
|
for (let field in gPosition.coords) {
|
||||||
|
let value = gPosition.coords[field];
|
||||||
terminal.print(field, ": ", value != null ? value.toString() : "null");
|
terminal.print(field, ": ", value != null ? value.toString() : "null");
|
||||||
}
|
}
|
||||||
} else if (event.error) {
|
}
|
||||||
|
if (gOrientation && gOrientation.alpha && gOrientation.beta && gOrientation.gamma) {
|
||||||
|
terminal.print(gOrientation.alpha.toString(), ", ", gOrientation.beta.toString(), ", ", gOrientation.gamma.toString(), ", ", gOrientation.absolute.toString());
|
||||||
|
}
|
||||||
|
if (gError) {
|
||||||
terminal.print(event.error.message);
|
terminal.print(event.error.message);
|
||||||
terminal.clearWatch();
|
terminal.clearWatch();
|
||||||
}
|
}
|
||||||
terminal.uncork();
|
terminal.uncork();
|
||||||
|
}
|
||||||
|
|
||||||
|
core.register("geolocation", function(event) {
|
||||||
|
if (event.position) {
|
||||||
|
gPosition = event.position;
|
||||||
|
} else if (event.error) {
|
||||||
|
gError = event.error;
|
||||||
|
}
|
||||||
|
draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
core.register("deviceorientation", function(event) {
|
||||||
|
gOrientation = event.orientation;
|
||||||
|
draw();
|
||||||
});
|
});
|
||||||
|
|
||||||
terminal.watchPosition({enableHighAccuracy: true});
|
terminal.watchPosition({enableHighAccuracy: true});
|
||||||
//terminal.watchPosition();
|
terminal.setSendDeviceOrientationEvents(true);
|
Loading…
Reference in New Issue
Block a user