Skip to content

Instantly share code, notes, and snippets.

@timothyclemans
Created May 19, 2014 15:53
Show Gist options
  • Save timothyclemans/a66106ca149b393fc76c to your computer and use it in GitHub Desktop.
Save timothyclemans/a66106ca149b393fc76c to your computer and use it in GitHub Desktop.
[wearscript] myo hotkeys
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<html style="width:100%; height:100%; overflow:hidden">
<style>
table {
font-size:50px;
}
</style>
<body style="width:100%; height:100%; overflow:hidden; margin:0; color:#FFF">
<h1>Myo Hot Keys 6 </h1>
<table>
<tr><th>Key</th><th>Command</th></t></tr>
</table>
<script>
var gestures = [];
var key_length = 2;
var dictionary = {'FIST_FIST': 'Lookup patient', 'FIST_WAVE_OUT': 'See history', 'WAVE_OUT_FINGERS_SPREAD': 'Write an order', 'TWIST_IN_TWIST_IN': 'Inubation checklist'};
for (var key in dictionary) {
$('table').append('<tr><td>'+key+'</td><td>'+dictionary[key]+'</td></tr>')
}
function server() {
WS.myoPair(WS.myoTrain);
WS.gestureCallback('onMyo', function (x) {
if (x != 'NONE') {
//WS.say(x);
gestures.push(x);
$('h1').text(JSON.stringify(gestures));
if (gestures.length == key_length) {
var key = '';
for (var i=0;i<gestures.length;i++) {
if (i != 0) {
key += '_';
}
key += gestures[i];
}
if (dictionary[key] == undefined) {
gestures = [];
WS.say('Command not found');
} else {
WS.say(dictionary[key]);
WS.log(dictionary[key]);
$('h1').text(key+' '+dictionary[key]+' '+JSON.stringify(gestures));
gestures = [];
}
}
WS.log(x);
}
});
WS.sensorOn('myoOrientation', .15, function (data) {
//WS.log('got data: ' + JSON.stringify(data));
});
WS.sensorOn('myoAccelerometer', .15);
WS.sensorOn('myoGyroscope', .15);
WS.dataLog(false, true, .15);
}
function main() {
if (WS.scriptVersion(1)) return;
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script></body></html>
{"name":"Example"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment