Skip to content

Instantly share code, notes, and snippets.

@ga2arch
Created June 16, 2015 11:26
Show Gist options
  • Select an option

  • Save ga2arch/8022a41017e68d99f447 to your computer and use it in GitHub Desktop.

Select an option

Save ga2arch/8022a41017e68d99f447 to your computer and use it in GitHub Desktop.
AtoomaMacAccelerometerExtensions
chrome.identity.getAuthToken({ 'interactive': true }, function(access_token) {
var dir = null;
var threshold = 9;
window.addEventListener('deviceorientation', function(event) {
var a = event.alpha;
var b = event.beta;
var g = event.gamma;
sendData(b, g);
}, false);
function sendData(beta, gamma) {
var tdir = null;
if ((Math.abs(beta) > Math.abs(gamma)))
if (beta > threshold)
tdir = 1;
else if (beta < -threshold)
tdir = 0;
else
tdir = null;
else
if (gamma > threshold)
tdir = 3;
else if (gamma < -threshold)
tdir = 2;
else
tdir = null;
if (dir != tdir && tdir != null) {
var xhr = new XMLHttpRequest();
xhr.open('POST', "http://192.168.1.101:8080/tilted", true);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send("access_token="+access_token);
}
dir = tdir;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment