Last active
August 29, 2015 14:00
-
-
Save scottgwald/11016025 to your computer and use it in GitHub Desktop.
[wearscript] photoCallbackTest
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
| <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> |
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
| {"name":"Photo Callback Test"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment