Skip to content

Instantly share code, notes, and snippets.

@bwhite
bwhite / glass.html
Last active August 29, 2015 13:55
[wearscript] All gestures get logged to the console and the onGesture results are spoken aloud
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function show(msg) {
WS.log(msg)
WS.cardModify(0, WS.cardFactory(msg, ''));
}
function onGesture(gesture) {
@bwhite
bwhite / install.py
Last active August 29, 2015 13:56
WearScript Installer: Execute the following in a shell: curl -L http://goo.gl/nRjW6y > install.py && python install.py
#!/usr/bin/env python
import shutil
import urllib2
import platform
import tempfile
import urllib
import os
import subprocess
import webbrowser
import stat
@bwhite
bwhite / glass.html
Created February 9, 2014 03:38
[wearscript] Eye tracker calibration
<html style="width:100%; height:100%; overflow:hidden">
<head><script src="https://api.picar.us/wearscriptdev/bower_components/msgpack-javascript/msgpack.js"></script></head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function publish() {
var data = msgpack.pack(Array.prototype.slice.call(arguments));
WS.publish(arguments[0], btoa(data.map(function (x) {return String.fromCharCode(x)}).join('')));
}
function cb(path) {
@bwhite
bwhite / glass.html
Created February 9, 2014 20:53
[wearscript] Tests the java/javascript bridge for character violations. A string can be sent to java and back as long as it has no null characters in it. For callbacks there are more restrictions (as such all data should be b64d).
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function server() {
var a=[]; for (var i = 0; i < 256; i++) a.push(String.fromCharCode(i));b256=a.join('');
a=[]; for (var i = 1; i < 256; i++) a.push(String.fromCharCode(i));b255=a.join('');
WS.log('echolen(b256): ' + WS.echolen(b256));
WS.log('echolen(b255): ' + WS.echolen(b255));
WS.log('echo(b256).length: ' + WS.echo(b256).length);
WS.log('echo(b255).length: ' + WS.echo(b255).length);
@bwhite
bwhite / glass.html
Created February 9, 2014 21:27
[wearscript] Example using the subscribe functionality
<html style="width:100%; height:100%; overflow:hidden">
<head><script src="https://api.picar.us/wearscriptdev/bower_components/msgpack-javascript/msgpack.js"></script></head>
<script>
/* To use, try the following in the playground (HACK_WS may change by then, but use w/e it is now)
HACK_WS.publish('example', 'test');
HACK_WS.publish('example', 'test', {'1': 3});
*/
function example(data) {
WS.log(JSON.stringify(msgpack.unpack(atob(data))));
@bwhite
bwhite / glass.html
Created February 15, 2014 18:10
[wearscript] Eye tracker calibration (image version)
<html style="width:100%; height:100%; overflow:hidden">
<head><script src="https://api.picar.us/wearscriptdev/bower_components/msgpack-javascript/msgpack.js"></script></head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function server() {
TAPCOUNT = -1;
WS.say('Tap to take a picture');
WS.subscribe('sensors:eyetracker', function (channel, sensorNames, sensorValues) {
@bwhite
bwhite / glass.html
Created February 24, 2014 23:51
[wearscriptold] Working copy of cards, currently integrated
<html style="width:100%; height:100%; overflow:hidden">
<head>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>-->
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
function Cards(cards) {
this.cards = cards || [];
@bwhite
bwhite / glass.html
Last active August 29, 2015 13:56
[wearscript] Sensor/camera log
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function main() {
if (WSRAW.scriptVersion(1)) return;
WSRAW.say('Logging');
var sensors = ['gps', 'accelerometer', 'magneticField', 'orientation', 'gyroscope',
'light', 'gravity', 'linearAcceleration', 'rotationVector'];
for (var i = 0; i < sensors.length; i++)
WSRAW.sensorOn(WSRAW.sensor(sensors[i]), .15);
@bwhite
bwhite / glass.html
Created February 27, 2014 22:47
[wearscriptold]
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function server() {
WS.displayCardTree();
var tree = new WS.Cards();
tree.add('Summary', 'Auto');
tree.add('Summary', 'Auto', function () {WS.say('selected')}); // Select
tree.add('Summary', 'Auto', function () {WS.say('selected')}, function () {WS.say('tap')}); // Select + Tap
tree.add('Summary', 'Auto', 'Say', function () {WS.say('Say clicked')}, 'Log', function () {WS.log('log clicked')}); // Menu
@bwhite
bwhite / glass.html
Created February 28, 2014 21:27
[wearscript] Card Tree Comprehensive Example
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function server() {
WS.displayCardTree();
var select = function () {WS.say('select')};
var tap = function () {};
var select = function (n) {return function () {WS.say('select ' + n);WS.log('select ' + n)}};
var log = function (n) {return function () {WS.log('log ' + n)}};
var tap = function (n) {return function () {WS.say('tap ' + n);WS.log('tap ' + n)}};