Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Created April 10, 2014 21:29
Show Gist options
  • Save scottgwald/10425270 to your computer and use it in GitHub Desktop.
Save scottgwald/10425270 to your computer and use it in GitHub Desktop.
[wearscript] nametagz
<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">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function qrCB(qrText) {
WS.publish('nametags', qrText);
//WS.publish('whatever', qrText);
var tree = new WS.Cards();
finalString = decodeURIComponent(escape(qrText));
parts = finalString.split(";");
WS.say("This is " + parts[0]);
if (parts.length > 1) {
tree.add(parts[0], parts[1], undefined, toggleServer);
WS.say(parts[0]);
} else {
tree.add(finalString, '', undefined, toggleServer);
}
// tree.add(finalString);
WS.cardTree(tree);
WS.displayCardTree();
setTimeout(function() {WS.qr(qrCB);}, 3000);
}
function server() {
WS.log('Welcome to WearScript');
WS.say('Welcome to WearScript');
WS.sound('SUCCESS');
//WS.qr(qrCB);
// Below this are more examples, uncomment to use them
//WS.liveCardCreate(false, .2);
/*
var tree = new WS.Cards();
tree.add('Body text', 'Footer text', function () {WS.say('selected')}, function () {WS.say('tapped')}, 'Menu0', function () {WS.say('menu0')}, 'Menu1', function () {WS.say('menu1')});
tree.add('Body text', 'Footer text', (new WS.Cards()).add('Child0', '0').add('Child1', '1'));
WS.cardTree(tree);
WS.displayCardTree();
*/
/*
WS.speechRecognize('Say Something', function (data) {
WS.log('speech: ' + data);
WS.say('you said ' + data);
});
*/
//WS.cameraPhoto();
//WS.cameraVideo();
//WS.cameraOff();
//WS.shutdown();
}
var playground = false;
function toggleServer() {
if (!playground) {
WS.say('connecting to playground');
WS.serverConnect('{{WSUrl}}', server);
playground = true;
} else {
WS.say('connecting to custom endpoint');
WS.serverConnect('ws://scrumdiddly.dyndns.org:8112/');
playground = false;
}
}
WS.gestureCallback('onGestureTAP', function () {
if (!playground) {
WS.say('connecting to playground');
WS.serverConnect('{{WSUrl}}', server);
playground = true;
} else {
WS.say('connecting to custom endpoint');
WS.serverConnect('ws://scrumdiddly.dyndns.org:8112/');
playground = false;
}
});
function main() {
if (WS.scriptVersion(1)) return;
ctx = document.getElementById('canvas').getContext("2d");
// WS.serverConnect('{{WSUrl}}', server);
WS.serverConnect('ws://scrumdiddly.dyndns.org:8112/', server);
WS.qr(qrCB);
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment