Skip to content

Instantly share code, notes, and snippets.

@connerbrooks
Created March 25, 2014 02:08
Show Gist options
  • Save connerbrooks/9754023 to your computer and use it in GitHub Desktop.
Save connerbrooks/9754023 to your computer and use it in GitHub Desktop.
[wearscript] Hue->Myo control
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script data-require="jquery" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
function server() {
WS.say('I am phone')
WS.log('I am a phone')
WS.myoTrain();
// Currently one of {NONE, FIST, FINGERS_SPREAD, WAVE_IN, WAVE_OUT}
WS.gestureCallback('onMyo', function (x) {
WS.say(x);
WS.log(x);
if (x == 'FINGERS_SPREAD') {
$.ajax({
url: 'http://192.168.1.66/api/wearscript/lights/1/state',
type: 'PUT',
dataType: 'application/json',
data: '{"on":true}',
success: function(data) {
console.log('success',data);
},
error: function(data){
console.log('error',data.responseText)
}
})
$.ajax({
url: 'http://192.168.1.66/api/wearscript/lights/2/state',
type: 'PUT',
dataType: 'application/json',
data: '{"on":true}',
success: function(data) {
console.log('success',data);
},
error: function(data){
console.log('error',data.responseText)
}
})
$.ajax({
url: 'http://192.168.1.66/api/wearscript/lights/3/state',
type: 'PUT',
dataType: 'application/json',
data: '{"on":true}',
success: function(data) {
console.log('success',data);
},
error: function(data){
console.log('error',data.responseText)
}
})
}
if (x == 'FIST') {
$.ajax({
url: 'http://192.168.1.66/api/wearscript/lights/1/state',
type: 'PUT',
dataType: 'application/json',
data: '{"on":false}',
success: function(data) {
console.log('success',data);
},
error: function(data){
console.log('error',data.responseText)
}
})
$.ajax({
url: 'http://192.168.1.66/api/wearscript/lights/2/state',
type: 'PUT',
dataType: 'application/json',
data: '{"on":false}',
success: function(data) {
console.log('success',data);
},
error: function(data){
console.log('error',data.responseText)
}
})
$.ajax({
url: 'http://192.168.1.66/api/wearscript/lights/3/state',
type: 'PUT',
dataType: 'application/json',
data: '{"on":false}',
success: function(data) {
console.log('success',data);
},
error: function(data){
console.log('error',data.responseText)
}
})
}
});
}
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