-
-
Save scottgwald/325945b9e19e6ed06a04 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<!-- 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> | |
// Constants | |
var DBG = true; | |
var i = 0; | |
var secondLineText = "Second line"; | |
var wakeTime; | |
var timeDeltaText = ""; | |
var wakeInterval = 300000; | |
var timeNow = new Date().getTime(); | |
var tillNextWake = Math.floor(wakeInterval / 1000); | |
var deltasMaxLength = 10; | |
var timeDeltas = []; | |
var woken; | |
var timeDeltaTitleText = "Between Last Wakes:"; | |
var batteryLevelText = "Battery level: "; | |
var showDashboard = true; | |
var cameraCB; | |
var showImageInterval = 10000; | |
var pauseFudgeFactor = 500; | |
var videoLength = 10; | |
// AUXILIARY FUNCTIONS | |
function drawModeName(name) { | |
upperBase = 40; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawSecondLine(name) { | |
upperBase = 90; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawTextLine(text, _number) { | |
var number = _number; | |
if ( number === undefined ) { | |
console.log("No number given, setting to 0"); | |
number = 0; | |
} | |
baseline = 40 + 50 * number; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(text, 10, baseline); | |
} | |
function clearCanvas() { | |
context.fillStyle = "rgb(0, 0, 0)"; | |
context.fillRect(0, 0, 640, 360); | |
} | |
Date.prototype.today = function () { | |
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear(); | |
} | |
Date.prototype.timeNow = function () { | |
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds(); | |
} | |
// MAIN | |
function draw() { | |
if (showDashboard) { | |
clearCanvas(); | |
drawTextLine(firstLineText, 0 ); | |
drawTextLine(secondLineText, 1 ); | |
drawTextLine(tillNextWake, 2 ); | |
drawTextLine(timeDeltaTitleText, 3 ); | |
drawTextLine(timeDeltaText, 4 ); | |
drawTextLine(batteryLevelText, 5 ); | |
} | |
// list of last times | |
// drawModeName("" + i); | |
// drawSecondLine(secondLineText); | |
} | |
currentTimeString = function () { | |
return new Date().today() + " @ " + new Date().timeNow(); | |
} | |
timeString = function(date) { | |
return date.today() + " @ " + date.timeNow(); | |
} | |
function server() { | |
if (!DBG) WS.serverConnect('0.0.0.0', null); | |
WS.log('Welcome to WearScript'); | |
WS.say('Welcome to WearScript'); | |
WS.sound('SUCCESS'); | |
WS.dataLog(true, false, 1); | |
WS.sensorOn("battery", 1, function (data) { | |
console.log("Got battery callback"); | |
console.log(JSON.stringify(data)); | |
batteryLevelText = "Battery Level: " + Math.round(data.values[0] * 100) + "%"; | |
if (Math.round(data.values[0] * 100) <= 20) WS.say("Low battery."); | |
batteryLevelText += " @ " + new Date(parseInt(data.timestamp * 1000)).timeNow(); | |
}); | |
clearCanvas(); | |
drawModeName("Rock and roll"); | |
var updateCurrentTime = function() { | |
var date = new Date(); | |
timeNow = date.getTime(); | |
tillNextWake = "Till Next Wake: " + Math.ceil((wakeInterval - (timeNow - wakeTime)) / 1000); | |
//firstLineText = currentTimeString(); | |
firstLineText = timeString(date); | |
draw(); | |
} | |
var updateWakeTime = function () { | |
if (wakeTime != undefined) { | |
woken = true; | |
} | |
var date = new Date(); | |
lastWakeTime = wakeTime; | |
wakeTime = date.getTime(); | |
wakeTimeString = timeString(date); | |
wakeTimeDelta = wakeTime - lastWakeTime; | |
if (woken) { | |
timeDeltas.unshift(Math.floor(wakeTimeDelta / 1000)); | |
if (timeDeltas.length > deltasMaxLength) timeDeltas.pop(); | |
} | |
timeDeltaText = JSON.stringify(timeDeltas); | |
secondLineText = "Last Wake: " + currentTimeString(); | |
//thirdLineText = "Time since last wake: "; | |
//secondLineText = "current time"; | |
draw(); | |
} | |
updateCurrentTime(); | |
updateWakeTime(); | |
// WS.cameraOn(0.5, 480, 640, cameraCB); | |
setInterval(updateCurrentTime, 1000); | |
var img = new Image(); | |
img.onload = function() { | |
context.drawImage(img, 0, 0); | |
} | |
cameraCB = function(data) { | |
WS.log("Got camera callback."); | |
showDashboard = false; | |
WS.cameraOff(); | |
//context.drawImage(img, 0, 0); | |
img.src = 'data:image/jpg;base64,' + data; | |
setTimeout(function() { | |
showDashboard = true; | |
//WS.liveCardCreate(true, .45); | |
WS.activityDestroy(); | |
}, showImageInterval); | |
//WS.say("Creating live card"); | |
//WS.liveCardDestroy(); | |
} | |
var periodic = function() { | |
WS.say("Cheese balls"); | |
WS.wake(); | |
WS.activityCreate(); | |
WS.displayWebView(); | |
// secondLineText = "LastWake: " + new Date().today() + " @ " + new Date().timeNow(); | |
updateWakeTime(); | |
WSRAW.recordWSVideo(videoLength); | |
WS.activityDestroy(); | |
//setTimeout(function() {WS.cameraOn(0.5, 480, 640, cameraCB);}, pauseFudgeFactor); | |
} | |
setInterval( periodic, wakeInterval ); | |
// Below this are more examples, uncomment to use them | |
WS.liveCardCreate(true, .2); | |
WSRAW.recordWSVideo(videoLength); | |
/* | |
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(); | |
} | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
context = document.getElementById('canvas').getContext("2d"); | |
WS.serverConnect('{{WSUrl}}', server); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
This file contains 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> | |
<meta charset="UTF-8"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<!--<script src="//www.parsecdn.com/js/parse-1.2.18.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> | |
console.log('welcome!'); | |
WS.say('Welcome!'); | |
// Parse.initialize("9hrZ3h5viAKZg93PhiYX1YucInOQvS0EqqtXCGip", "Dm1x1VCicnjkIlz803kJpNlPUAJFrKSLDER7gwGE"); | |
// var GuessObject = Parse.Object.extend("GuessObject"); | |
// var TestObject = Parse.Object.extend("TestObject"); | |
// var testObject = new TestObject(); | |
// testObject.save({foo: "bar"}).then(function(object) { | |
// alert("yay! it worked"); | |
// console.log('PARSE WORKED!!!!!!!!!'); | |
// }); | |
var kimonoSet = [['frog','ribbit'],['snake','hiss'],['cat','meow'],['dog','bark'],['horse','neigh'],['lion','roar'],['mouse','squeak'],['wolf','howl']]; | |
var kimonoTitle = ''; | |
function kimonoCallback(data) { | |
if(data.lastrunstatus=="success"){ | |
console.log('kimonocallback'); | |
window.kimonoSet.length = 0; | |
for(var i=0;i<data.results.collection1.length;i++){ | |
window.kimonoSet.push([data.results.collection1[i].question,data.results.collection1[i].answer]); | |
} | |
window.kimonoTitle=data.results.collection2[0].title; | |
console.log(JSON.stringify(window.kimonoTitle)); | |
console.log(JSON.stringify(window.kimonoSet)); | |
}else{ | |
getRandomWords(); | |
} | |
} | |
function getRandomWords(){ | |
console.log('getrandomwords'); | |
var url = "http://www.kimonolabs.com/api/dwrmpm04?apikey=989877be85a3ca05477428c8b41d4fbe&callback=kimonoCallback&kimpath1="; | |
var num = Math.floor(Math.random()*1000000)+3000000; | |
console.log('kimono number: '+num); | |
url = url+num+"&kimpath2="; | |
$.ajax({ | |
"url": url, | |
"crossDomain":true, | |
"dataType":"jsonp" | |
}); | |
} | |
getRandomWords(); // gets a new set of words | |
// setTimeout(function(){console.log(JSON.stringify(kimonoSet));},5000); | |
// setTimeout(function(){console.log( JSON.stringify(kimonoSet[0][0]) );},5000); | |
// setTimeout(function(){console.log( JSON.stringify(kimonoSet[0][1]) );},5000); | |
// Constants | |
var DBG = true; | |
var i = 0; | |
var secondLineText = "Second line"; | |
var wakeTime; | |
var timeDeltaText = ""; | |
var wakeInterval = 5*60*1000; | |
var wordInterval = 10*1000; | |
var timeNow = new Date().getTime(); | |
var tillNextSet = Math.floor(wakeInterval / 1000); | |
var tillNextWord = Math.floor(wordInterval / 1000); | |
var deltasMaxLength = 10; | |
var timeDeltas = []; | |
var woken; | |
var timeDeltaTitleText = "Between Last Wakes:"; | |
var batteryLevelText = "Battery level: "; | |
var showDashboard = true; | |
var cameraCB; | |
var showImageInterval = 10000; | |
var pauseFudgeFactor = 500; | |
var videoLength = 10; | |
var wordsDone = 0; | |
var wordsRight = 0; | |
var accuracy = 100.0; | |
var setSize = 4; | |
var counter = 0; | |
var setIndex = Math.floor((Math.random()*setSize)); | |
var quizzing = false; | |
var currWord; | |
var currDef; | |
var idle = true; | |
var context; | |
var wordsToDisplay = new Array(); | |
function drawModeName(name) { | |
upperBase = 40; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawSecondLine(name) { | |
upperBase = 90; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '28pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(name, 10, upperBase); | |
} | |
function drawTextLine(text, _number) { | |
var number = _number; | |
if ( number === undefined ) { | |
console.log("No number given, setting to 0"); | |
number = 0; | |
} | |
baseline = 88 + 100 * number; | |
context.fillStyle = "rgb(200,200,200)"; | |
context.font = '60pt Calibri'; | |
context.textAlign = 'left'; | |
context.fillText(text, 10, baseline); | |
} | |
function clearCanvas() { | |
context.fillStyle = "rgb(0, 0, 0)"; | |
context.fillRect(0, 0, 640, 360); | |
} | |
Date.prototype.today = function () { | |
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear(); | |
} | |
Date.prototype.timeNow = function () { | |
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds(); | |
} | |
// MAIN | |
function draw() { | |
} | |
currentTimeString = function () { | |
return new Date().today() + " @ " + new Date().timeNow(); | |
} | |
timeString = function(date) { | |
return date.today() + " @ " + date.timeNow(); | |
} | |
function server() { | |
WS.wake(); | |
if (!DBG) WS.serverConnect('0.0.0.0', null); | |
WS.log('Welcome to WearScript'); | |
// WS.say('Welcome to WearScript'); | |
WS.sound('SUCCESS'); | |
WS.dataLog(true, false, 1); | |
WS.sensorOn("battery", 1, function (data) { | |
console.log("Got battery callback"); | |
console.log(JSON.stringify(data)); | |
batteryLevelText = "Battery Level: " + Math.round(data.values[0] * 100) + "%"; | |
if (Math.round(data.values[0] * 100) <= 20) WS.say("Low battery."); | |
batteryLevelText += " @ " + new Date(parseInt(data.timestamp * 1000)).timeNow(); | |
}); | |
clearCanvas(); | |
drawModeName("Rock and roll"); | |
// draw(); | |
var createDisplay = function(wordsDone,accuracy){ | |
WS.activityDestroy(); | |
setIndex = Math.floor((Math.random()*setSize)); | |
var tree = new WS.Cards(); | |
var roundedAcc = Math.round(accuracy * 100) / 100; | |
tree.add('Words Quizzed: '+wordsDone+'\n'+'Accuracy: '+roundedAcc+'%', 'Tap for a new word!',undefined,createQuiz); | |
WS.cardTree(tree); | |
WS.displayCardTree(); | |
} | |
var test = function(wordsDone,accuracy){ | |
var temp = accuracy; | |
if(quizzing){ | |
var ansTree = new WS.Cards(); | |
ansTree.add(decodeURIComponent(escape(currWord))+'\n'+decodeURIComponent(escape(currDef)),window.kimonoTitle); | |
WS.cardTree(ansTree); | |
WS.displayCardTree(); | |
setTimeout(function() { | |
quizzing = false; | |
test(wordsDone,accuracy); | |
}, 4000); | |
return | |
} | |
if(counter>4){ | |
// getRandomWords(); | |
createDisplay(wordsDone,accuracy); | |
counter = 0; | |
idle = true; | |
} | |
else{ | |
idle = false; | |
quizzing = true; | |
createQuiz(); | |
} | |
} | |
var processWord = function(w, d){ | |
word = w; | |
def = d; | |
var isCorrect; | |
// WS.say(word); | |
var incorrectPhrase= "incorrect. The correct definition is: " + def; | |
setTimeout(function(){WS.speechRecognize(decodeURIComponent(escape(word)), function speech(data) {console.log('WS.speechRecognize: ' + data);if(data=='' || data===''){console.log('SWIPE BACK FUNCTION CAUGHT!!!!!!!');processWord(word,def);return;}if(def.toUpperCase().indexOf(data.toUpperCase())!=-1){isCorrect=true;WS.say('correct');wordsRight+=1;}else{isCorrect=false;WS.say('incorrect')}wordsDone+=1;accuracy=100*wordsRight/wordsDone;counter+=1;test(wordsDone,accuracy);})},1); //WS.say(incorrectPhrase); in else statement to read incorrect answer | |
// var guessObject = new GuessObject(); | |
// guessObject.save({user:window.glassID,word:word,def:def,correct:isCorrect}).then(function(object) { | |
// alert("yay! it worked"); | |
// console.log('PARSE WORKED!!!!!!!!!'); | |
// }); | |
} | |
var swipe_callback = function(){ | |
// var tempTree = new WS.Cards();tempTree.add('Tap for a new word!','');WS.cardTree(tempTree);WS.displayCardTree(); | |
WS.say('Try Again!'); | |
createQuiz(); | |
console.log('!!!!!!!!!!!!!!!!!!!!callback!!!!!!!!!!!!!!!!!!!!!'); | |
} | |
var temp_func = function(){ | |
} | |
var new_context = function(){ | |
getRandomWords(); | |
WS.say('new context!'); | |
} | |
var createQuiz = function(){ | |
WS.displayCardTree(); | |
quizzing = true; | |
var quiztree = new WS.Cards(); | |
console.log(JSON.stringify(kimonoSet)); | |
var currentSetSize=JSON.stringify(kimonoSet.length); | |
console.log('set size: '+currentSetSize); | |
var wordIndex = Math.floor((Math.random()*currentSetSize)); | |
console.log('word index: '+wordIndex); | |
console.log(JSON.stringify(kimonoSet[wordIndex][0])); | |
console.log(JSON.stringify(kimonoSet[wordIndex][1])); | |
if(counter>0){ | |
console.log('game screen!!!!!!'); | |
quiztree.add('', '', function(){processWord(kimonoSet[wordIndex][0],kimonoSet[wordIndex][1]);}, swipe_callback); | |
} else { | |
console.log('menu screen!!!!!!!'); | |
quiztree.add('Tap to play!', window.kimonoTitle, temp_func, temp_func, 'Start Quiz!', function(){processWord(kimonoSet[wordIndex][0],kimonoSet[wordIndex][1]);}, 'New Context', new_context); | |
} | |
currWord = kimonoSet[wordIndex][0]; | |
currDef = kimonoSet[wordIndex][1]; | |
WS.cardTree(quiztree); | |
} | |
createDisplay(0,0); | |
var processScenery = function(wordsToDisplay,context,index){ | |
WS.wake(); | |
w = wordsToDisplay[0][0]; | |
d = wordsToDisplay[0][1]; | |
c = context; | |
displayScenery(w,d,c); | |
} | |
var displayScenery = function(w,d,c){ | |
WS.wake(); | |
var tree = new WS.Cards(); | |
tree.add(decodeURIComponent(escape(w))+'\n'+d,c); | |
WS.cardTree(tree); | |
WS.displayCardTree(); | |
} | |
var newWord = function(){ | |
if(sceneryMode){ | |
WS.wake(); | |
// display a new word. | |
processScenery(wordsToDisplay,context); | |
wordsToDisplay.splice(0, 1); | |
if(wordsToDisplay.length==0){ | |
sceneryMode=false; | |
createDisplay(wordsDone,accuracy); | |
} | |
WS.wake(); | |
} | |
} | |
var wakeUp = function(){ | |
if(idle){ | |
sceneryMode = true; | |
setIndex = Math.floor((Math.random()*setSize)); | |
var currentSetSize=window.kimonoSet.length; | |
for (var i=0;i<6;i++){ | |
var wordIndex = Math.floor((Math.random()*currentSetSize)); | |
wordsToDisplay.push([window.kimonoSet[wordIndex][0],window.kimonoSet[wordIndex][1]]); | |
} | |
context = window.kimonoTitle; | |
} | |
} | |
setInterval(wakeUp,wakeInterval); | |
setInterval(newWord,wordInterval); | |
// Below this are more examples, uncomment to use them | |
WS.liveCardCreate(true, .2); | |
WSRAW.recordWSVideo(videoLength); | |
} | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
context = document.getElementById('canvas').getContext("2d"); | |
WS.serverConnect('{{WSUrl}}', server); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment