Created
June 16, 2015 11:26
-
-
Save ga2arch/8022a41017e68d99f447 to your computer and use it in GitHub Desktop.
AtoomaMacAccelerometerExtensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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