Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Last active November 14, 2015 03:58
Show Gist options
  • Save scottgwald/b678cedcc55ed7ee1b24 to your computer and use it in GitHub Desktop.
Save scottgwald/b678cedcc55ed7ee1b24 to your computer and use it in GitHub Desktop.
[wearscript] minimal sensors
<html style="width:100%; height:100%; overflow:hidden">
<head>
<!-- You can include external scripts here like so... -->
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>-->
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
// WS.serverConnect("ws://invalid.com/ws", function() {console.log("No fucking way.")});
// WS.serverConnect('{{WSUrl}}', server);
var frameCount = 0;
var playgroundConnected = false;
var dims ={width: 128, height: 96};
// var dims ={width: 416, height: 240};
// WS.gestureCallback('onGestureTAP', function() {
// //WS.say("Tapped");
// if (playgroundConnected) {
// WS.say("Tapped and trying to connect to glass prahv");
// WS.serverConnect("ws://glassprov.media.mit.edu:8080/ws", gserver);
// } else {
// WS.say("Tapped and trying to connect to playground.");
// WS.serverConnect('{{WSUrl}}', pserver);
// }
// });
WS.gestureCallback('onGestureTAP', function() {
WS.say("tapped");
WS.cameraOff();
WS.dataLog(false, false, 1.0);
setTimeout(function() {
WS.say("back on");
// WS.cameraOn(0.5, 96, 128, function(){console.log("Got a frame " + frameCount); frameCount++});
WS.cameraOn(0.5, dims.height, dims.width, function(){console.log("Got a frame " + frameCount); frameCount++});
WS.dataLog(false, true, 0.15);
}, 5000);
});
function gserver() {
WS.say("Welcome to glass prahv");
WS.log("Connected to glassprov");
playgroundConnected = false;
server();
}
function pserver() {
WS.say("Welcome to playground");
WS.log("Connected to playground.");
playgroundConnected = true;
server();
}
function server() {
WS.sound('SUCCESS');
WS.sensorOn('orientation', .15);
// Stream camera frames (can view in the Images tab)
WS.cameraOn(0.5, dims.height, dims.width, function(){console.log("Got a frame " + frameCount); frameCount++});
WS.dataLog(false, true, 1.0);
}
function main() {
if (WS.scriptVersion(1)) return;
ctx = document.getElementById('canvas').getContext("2d");
// WS.serverConnect("ws://glassprov.media.mit.edu:8080/ws", gserver);
WS.serverConnect('{{WSUrl}}', pserver);
}
window.onload = main;
</script>
</body>
</html>
{"name":"Example"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment