Created
February 15, 2014 18:10
-
-
Save bwhite/9022979 to your computer and use it in GitHub Desktop.
[wearscript] Eye tracker calibration (image version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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) { | |
EYETRACKER_VALUE = sensorValues['Pupil Eyetracker'][0]; | |
WS.log(JSON.stringify(EYETRACKER_VALUE)); | |
}); | |
IMAGE_DATA = undefined; | |
EYETRACKER_VALUE = undefined; | |
POINTS = []; | |
WS.gestureCallback('onGesture', function (name) { | |
if (name == 'TAP') { | |
WS.sound('TAP'); | |
if (TAPCOUNT == -1) { | |
WS.cameraPhoto(function (imageData) { | |
IMAGE_DATA = imageData; | |
WS.say('got image'); | |
}); | |
WS.say('Tap once per point'); | |
TAPCOUNT += 1; | |
} else { | |
if (EYETRACKER_VALUE) { | |
POINTS.push(EYETRACKER_VALUE); | |
WS.say(TAPCOUNT); | |
TAPCOUNT += 1; | |
EYETRACKER_VALUE = undefined; | |
} else { | |
WS.say('Try again'); | |
} | |
} | |
} else if (name == 'THREE_TAP') { | |
if (IMAGE_DATA && POINTS.length) { | |
WS.say('Sending points'); | |
WS.publish('imageeyepos', (new Date).getTime() / 1000, IMAGE_DATA, POINTS); | |
} else { | |
WS.say('Not sending'); | |
} | |
} | |
}); | |
} | |
function main() { | |
if (WS.scriptVersion(1)) return; | |
ctx = document.getElementById('canvas').getContext("2d"); | |
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