Last active
January 24, 2017 00:25
-
-
Save masakick/94deff22844f53ad80806253736829a9 to your computer and use it in GitHub Desktop.
67ws example IOT for SP
This file contains 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
<body> | |
<div id="output"></div> | |
<script src="https://cdn.mlkcca.com/v0.6.0/milkcocoa.js"></script> | |
<script src="main-sp.js"></script> | |
</body> |
This file contains 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
window.onload = function(){ | |
var output = document.getElementById('output'); | |
var x=0; | |
var y=0; | |
var px=0; | |
var py=0; | |
var furufuru = false; | |
var milkcocoa = new MilkCocoa('maxiyarfndt.mlkcca.com'); | |
var ds = milkcocoa.dataStore('gravity'); | |
window.addEventListener('devicemotion', function(e){ | |
gravity = e.accelerationIncludingGravity; | |
x = gravity.x; | |
y = gravity.y; | |
output.innerHTML | |
= 'x: '+x | |
+ '<br>y: '+y; | |
sendModeFromGravityValue(x,y,px,py); | |
//ds.push({mode: "yes"}); | |
px = x; | |
py = y; | |
},true); | |
function sendModeFromGravityValue(x,y,px,py){ | |
var VU = x*px+y*py; | |
var valV = Math.sqrt(x*x+y*y); | |
var valU = Math.sqrt(px*px+py*py); | |
var cos = VU / valV / valU; | |
// portrait -> landscape | |
if(!furufuru && cos < 0.95){ | |
furufuru = true; | |
console.log("send "+furufuru); | |
ds.send({furue: furufuru}); | |
} | |
// landscape -> portrait | |
if(furufuru && cos >= 0.95){ | |
furufuru = false; | |
console.log("send "+furufuru); | |
ds.send({furue: furufuru}); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment