Skip to content

Instantly share code, notes, and snippets.

@timothyclemans
Created April 5, 2014 23:31
Show Gist options
  • Save timothyclemans/9999437 to your computer and use it in GitHub Desktop.
Save timothyclemans/9999437 to your computer and use it in GitHub Desktop.
[wearscript]
<!-- Complex checklists -->
<html style="width:100%; height:100%; overflow:hidden">
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://raw.github.com/Glench/fuzzyset.js/master/lib/fuzzyset.js"></script>
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700' rel='stylesheet' type='text/css'>
<style>
body {
font-family:roboto;
font-weight:100;
}
</style>
<!-- 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; background:#000;color:#FFF;">
<p id="text" style="padding:40px; font-size:40px; font-family:roboto; font-weight:100;"></p>
<script>
var beat = false;
var current = [];
var i = 0;
var seconds = 0;
var global_item = {};
var status = '';
var checklist = [{'type': 'voice_prompt', 'prompt': 'Is the patient breathing normally?', 'answers': {'yes': [{'type': 'static', 'text': 'Introduce yourself'}], 'no': [{'type': 'countdown', 'text': 'Check pulse for no more than ten seconds', 'start': 10}, {'type': 'voice_prompt', 'prompt': 'Does the patient have a pulse', 'answers': {'yes': [{'type': 'static', 'text': 'do nothing'}], 'no': [{'type': 'static', 'text': 'Start compressions'}, {'type': 'two_part_loop', 'text': 'For 2 minutes do 30 compressions at 100 beats per minute then 2 respirations', 'continue': 'Start compressions again', 'at_end': 'Say "Everyone clear". As soon as no one is touching the patient click analyze and deliver shock if advised', 'countdown': 120, 'countdown_text': 'till analyze'}]}}]}}];
current = checklist;
function processItem(item) {
$('#countdown').remove();
if (item['type'] == 'voice_prompt') {
WS.speechRecognize(item['prompt'], function (data) {
if (jQuery.inArray(data.toLowerCase(), Object.keys(item['answers'])) != -1) {
current = item['answers'][data.toLowerCase()];
i = 0;
processItem(current[i]);
} else {
WS.say('answer not recognized');
WS.speechRecognize(item['prompt'], function (data) {
if (jQuery.inArray(data.toLowerCase(), Object.keys(item['answers'])) != -1) {
current = item['answers'][data.toLowerCase()];
i = 0;
processItem(current[i]);
} else {
WS.say('something is wrong with voice recognition');
}
});
}
});
} else if (item['type'] == 'countdown') {
$('body').append('<p id="countdown" style="position:absolute; bottom:40px; right:40px;font-size:40px;">'+item['start']+'</p>');
$('#text').text(current[i]['text']);
WS.say(current[i]['text']);
i += 1;
} else if (item['type'] == 'two_part_loop') {
global_item = item;
$('body').append('<p id="countdown" style="position:absolute; bottom:40px; right:40px;font-size:40px;">'+item['countdown']+' seconds '+item['countdown_text']+'</p>');
$('#text').text(current[i]['text']);
WS.say(current[i]['text']);
i += 1;
seconds = item['countdown'];
beats = true;
setTimeout(function() {beats = false;WS.say('Stop compressions and give two respirations'); $('#text').text('Stop compressions and give two respirations');status='start_main_loop';},30000)
setInterval(function() {if (beats) { WS.sound('SUCCESS'); }},600);
setInterval(function() {
if (seconds == 0) {
status = 'ask_end_loop_question';
beats = false;
seconds = -1;
WS.say(item['at_end']);
$('#text').text(item['at_end']);
} else if (seconds > 0) {
seconds -=1;$('#countdown').text(seconds+' seconds '+item['countdown_text']);
}
},1000);
} else if (item['type'] == 'static') {
$('#text').text(current[i]['text']);
WS.say(current[i]['text']);
i += 1;
}
}
function onGesture(name) {
if (status == 'start_main_loop') {
setTimeout(function() {beats = false;WS.say('Stop compressions and give two respirations'); $('#text').text('Stop compressions and give two respirations');status='start_main_loop';},30000)
beats = true;
$('#text').text(global_item['continue']);
WS.say(global_item['continue']);
} else if (status == 'ask_end_loop_question') {
status = '';
WS.speechRecognize('Is the patient moving?', function (data) {
if (data.toLowerCase() == 'yes') {
$('#text').text('done');
} else {
processItem(current[0]);
}
});
} else {
processItem(current[i]);
}
}
function server() {
processItem(checklist[0]);
WS.gestureCallback('onGesture', 'onGesture');
WS.gestureCallback('onEyeGesture', 'onGesture');
}
function main() {
if (WS.scriptVersion(1)) return;
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