combinationLockPG/main.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-03-18 07:30:57 +00:00
function onSuccess(acceleration) {
/*alert('Acceleration X: ' + acceleration.x + '\n' +
2014-03-18 07:30:57 +00:00
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n' +
((Math.atan(acceleration.y / acceleration.x))/Math.PI*180)+90
);*/
var element = document.getElementById('textfeld');
element.innerHTML = "x:"+ acceleration.x + "y:"+ acceleration.y +" <br />"+ "<br />"+ "<br />"+getAngle(acceleration.x, acceleration.y);
drawDial(-getAngle(acceleration.x, acceleration.y)* Math.PI/180) ;
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
document.addEventListener("deviceready", startup, false);