Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from hecomi/pebble2.js
Last active August 29, 2015 14:25
Show Gist options
  • Save JT5D/a01ad95242923e2fb287 to your computer and use it in GitHub Desktop.
Save JT5D/a01ad95242923e2fb287 to your computer and use it in GitHub Desktop.
simply.title('TSUBAKUMI');
simply.subtitle('Loading...');
var DEVICE_API_URL = 'http://192.168.0.6:23456';
var API_LIST_URL = 'http://192.168.0.6:23457/apis/pebble';
var apis = ['NO DATA'];
var index = parseInt(localStorage.getItem('index')) || 0;
var available = false;
var update = function() {
if (!available) return;
var current = apis[index].slice(0, 16);
var next = apis[(index + 1) % apis.length].slice(0, 16);
var prev = apis[(index - 1 < 0) ? apis.length - 1 : index - 1].slice(0, 16);
simply.subtitle(current.slice(0, 12));
simply.body('< ' + prev + '\n* ' + current + '\n> ' + next + '\n' + '...');
};
ajax({ url: API_LIST_URL, type: 'json' }, function(json) {
apis = json.apis;
available = true;
update();
});
simply.on('singleClick', function(e) {
if (!available) return;
switch (e.button) {
case 'up':
index = (index - 1 < 0) ? apis.length - 1 : index - 1;
break;
case 'down':
index = (index + 1) % apis.length;
break;
case 'select':
available = false;
ajax({ url: DEVICE_API_URL + apis[index], type: 'json' }, function(json) {
if (json.error) {
simply.subtitle('ERROR');
simply.body(json.error);
} else {
simply.body('SUCCESS');
}
available = true;
simply.vibe('short');
});
break;
}
localStorage.setItem('index', index);
update();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment