Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Last active November 14, 2015 04:14
Show Gist options
  • Save scottgwald/d9b19609cd7fde223533 to your computer and use it in GitHub Desktop.
Save scottgwald/d9b19609cd7fde223533 to your computer and use it in GitHub Desktop.
[wearscript] minimal camera image streaming on/off
<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>
var frameCount = 0;
var isCameraOn = false;
var dims ={width: 128, height: 96};
WS.gestureCallback('onGestureTAP', function() {
isCameraOn = !isCameraOn;
isCameraOn ? myCameraOn() : myCameraOff();
});
function myCameraOn() {
// Stream camera frames (can view in the Images tab)
WS.dataLog(false, true, 1.0);
WS.cameraOn(0.5, dims.height, dims.width, function(){console.log("Got a frame " + frameCount); frameCount++});
isCameraOn = true;
WS.say("camera on");
}
function myCameraOff() {
WS.cameraOff();
isCameraOn = false;
WS.say("camera off");
}
function server() {
WS.sound('SUCCESS');
myCameraOn();
}
function main() {
WS.dataLog(false, true, 1.0);
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script>
</body>
</html>
{"name":"Camera On Off"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment