Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Forked from fluidglassml/glass.html
Last active August 29, 2015 14:04
Show Gist options
  • Save scottgwald/4fd78440330c45376aa0 to your computer and use it in GitHub Desktop.
Save scottgwald/4fd78440330c45376aa0 to your computer and use it in GitHub Desktop.
<html>
<body>
<script>
var me;
var endpoint = 'ws://192.168.2.253:8112';
DBG = false;
battery = "?";
Date.prototype.today = function () {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
}
Date.prototype.timeNow = function () {
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
}
currentTimeString = function () {
return new Date().today() + " @ " + new Date().timeNow();
}
function registered(channel, name) {
WS.say("Registered as " + name);
}
function blobCB(channel, message) {
WS.sound('SELECTED');
WS.wake();
WS.activityCreate();
tree = new WS.Cards();
tree.add(message, currentTimeString() + " battery: " + 100*battery + "%");
WS.cardTree(tree);
WS.displayCardTree();
}
function batteryCB(data) {
console.log("Got battery data " + JSON.stringify(data));
battery = data['values'][0];
}
function toggleServer() {
WS.sound("SELECTED");
if (!playground) {
WS.serverConnect('{{WSUrl}}', server);
playground = true;
} else {
WS.serverConnect(customEndpoint, serverCustom);
playground = false;
}
}
if (DBG) WS.gestureCallback('onGestureTAP', toggleServer);
function my_cb(channel, data) {
console.log("Got a lines object!");
console.log(JSON.stringify(data));
if (data.glassID == me) {
WS.wake();
WS.activityCreate();
WS.displayCardTree();
var tree = new WS.Cards();
tree.add(data, 'GlassProv');
// tree.add(data.text, 'GlassProv');
WS.cardTree(tree);
//console.log("It's me! And the text is: " + data.text);
//WS.say(data.text);
} else {
console.log("It's not me. But the text is: " + data.text);
}
}
function main() {
tree = new WS.Cards();
tree.add(WS.groupDevice(), currentTimeString());
WS.cardTree(tree);
WS.displayCardTree();
WS.serverConnect(endpoint, function () {
WS.sound('SUCCESS');
WS.subscribe('registered', registered);
// WS.subscribe('blob', blobCB);
WS.subscribe(WS.groupDevice(), blobCB);
WS.publish('register', 'registered', WS.groupDevice());
// WS.publish('blob', 'glassmessage', 'glass body');
WS.sensorOn("battery", 1, batteryCB);
// WS.say("Server connected.");
// console.log(WSRAW.getGlassID());
me = WS.groupDevice();
// me = WSRAW.getGlassID();
console.log(me);
// setTimeout(function () {
// if (me == "f8:8f:ca:25:06:bf") {
// WS.say("It's me");
// } else {
// WS.say("It's not me!");
// }
// }, 2000);
line_cb = function(chan, data) {
console.log("Got a lines object!");
console.log(JSON.stringify(data));
if (data.glassID == me) {
WS.wake();
WS.activityCreate();
WS.displayCardTree();
var tree = new WS.Cards();
tree.add(data.text, 'GlassProv');
WS.cardTree(tree);
//console.log("It's me! And the text is: " + data.text);
//WS.say(data.text);
} else {
console.log("It's not me. But the text is: " + data.text);
}
}
vid_cb = function(chan, data) {
console.log("Got a vids object!");
console.log(JSON.stringify(data));
if (data.glassID == me) {
WS.wake();
WS.activityCreate();
WS.displayCardTree();
var tree = new WS.Cards();
tree.add(data.url, 'GlassProv');
WS.cardTree(tree);
//console.log("It's me! And the text is: " + data.text);
//WS.say(data.text);
} else {
console.log("It's not me. But the text is: " + data.url);
}
}
// WS.subscribe(me, my_cb);
// WS.subscribe('lines:' + me, line_cb);
// WS.subscribe('lines', line_cb);
// WS.subscribe('videos:' + me, vid_cb );
});
}
window.onload = main;
</script>
</body>
</html>
{
"name": "GlassProv"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment