combinationLockPG/main.js

30 lines
807 B
JavaScript
Raw Normal View History

2014-03-18 07:30:57 +00:00
function onSuccess(acceleration) {
var element = document.getElementById('textfeld');
2014-03-25 07:06:01 +00:00
element.innerHTML = "x:"+ acceleration.x + "y:"+ acceleration.y +" <br />"+ "<br />"+ "<br />"+getAngle(acceleration.x, acceleration.y);
handleAngle(getAngle(acceleration.x, acceleration.y) / 180 * Math.PI);
2014-03-11 08:24:07 +00:00
};
function getAngle (x, y) {
if (x == 0)
x += 0.00001;
x = -x;
if (x < 0)
return (360 - Math.atan(y / x) * 360 / 2 / Math.PI - 90);
else
return -(Math.atan(y / x) * 360 / 2 / Math.PI - 90);
}
2014-03-11 08:24:07 +00:00
2014-03-18 07:30:57 +00:00
function onError() {
alert('onError!');
2014-03-11 08:24:07 +00:00
};
var startup = function(){
watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError,options);
2014-03-11 08:24:07 +00:00
lockinit();
}
2014-03-17 21:24:08 +00:00
2014-03-18 07:30:57 +00:00
var options = { frequency: 100 };
2014-03-17 21:24:08 +00:00
2014-03-25 07:06:01 +00:00
document.addEventListener("deviceready", startup, false);
//window.onload = startup;