Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save scottgwald/11016025 to your computer and use it in GitHub Desktop.

Select an option

Save scottgwald/11016025 to your computer and use it in GitHub Desktop.
[wearscript] photoCallbackTest
<html style="width:100%; height:100%; overflow:hidden">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<img id="theImage" src="" width=640 height=360>
<script>
var lightThreshold = 25;
var theImage = $('#theImage');
var catPath = "http://imgur.com/TVDbSR1.jpg";
var tigerPath = "http://imgur.com/Mk0XZNL.jpg";
var isCovered;
var currentPath = catPath;
var picturesTaken = 0;
function server() {
WS.sound('SUCCESS');
WS.sensorOn('light', .01, function (data) {
isCovered = (data['values'][0] > lightThreshold) ? false : true;
setImage();
});
}
function setImage() {
if (isCovered) {
if (currentPath != catPath) {
WS.say("where are you");
theImage.attr('src', catPath);
currentPath = catPath;
}
} else {
if (currentPath != tigerPath) {
WS.say("Picaboo");
theImage.attr('src', tigerPath);
currentPath = tigerPath;
}
}
}
WS.gestureCallback('onGestureTAP', function () {
WS.say('tapped');
console.log("Pictures taken: " + picturesTaken);
if (picturesTaken < 2) {
WS.cameraPhoto(function(path) {
console.log("Got camera callback");
if (picturesTaken == 0) {
tigerPath = path;
} else if (picturesTaken == 1) {
catPath = path;
}
picturesTaken += 1;
setImage();
});
}
});
function main() {
if (WS.scriptVersion(1)) return;
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script>
</body>
</html>
{"name":"Photo Callback Test"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment