Skip to content

Instantly share code, notes, and snippets.

@connerbrooks
Created March 5, 2014 16:00
Show Gist options
  • Save connerbrooks/9370075 to your computer and use it in GitHub Desktop.
Save connerbrooks/9370075 to your computer and use it in GitHub Desktop.
[wearscript] Pebble API
<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 main() {
if (WS.scriptVersion(1)) return;
WS.gestureCallback('onPebbleSingleClick', function (name) {
WS.log('onPebbleSingleClick: ' + name);
WS.pebbleSetTitle('Robot Control');
switch(name) {
case 'SELECT':
post('RIGHT');
WS.pebbleSetSubtitle('Right');
break;
case 'UP':
post('FORWARD');
WS.pebbleSetSubtitle('Forward');
break;
case 'DOWN':
post('BACKWARD');
WS.pebbleSetSubtitle('Backward');
break;
}
});
WS.gestureCallback('onPebbleLongClick', function (name) {
WS.log('onPebbleLongClick: ' + name);
WS.pebbleVibe(2);
if(name === 'SELECT') {
post('LEFT');
WS.pebbleSetSubtitle('Left');
}
if(name === 'DOWN'){
post('STOP');
WS.pebbleSetSubtitle('All Stop');
}
});
// Post command to the robot
function post(direction) {
WS.log('post: ' + direction);
WS.pebbleSetBody('post: ' + direction);
$.ajax ({
type: "POST",
url: 'http://192.168.43.42:3000/robot',
dataType: 'json',
async: true,
data: {"direction": direction, "speed" : 255, "duration" : 2000},
success: function () {
WS.log("success");
}
})
}
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment