Created
February 9, 2014 03:38
-
-
Save bwhite/8893914 to your computer and use it in GitHub Desktop.
[wearscript] Eye tracker calibration
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 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) { | |
WS.log(path); | |
var canvas = document.getElementById('canvas'); | |
var context = canvas.getContext('2d'); | |
var imageObj = new Image(); | |
var k = 0; | |
var xsteps = 4; | |
var ysteps = 3; | |
var xstep = (2528 - 640) / (xsteps - 1); | |
var ystep = (1856 - 360) / (ysteps - 1); | |
var interval; | |
var points = []; | |
imageObj.onload = function() { | |
//2528 x 1856 | |
clearInterval(interval); | |
interval = window.setInterval(function () { | |
if (k) { | |
points.push([x, y, EYETRACKER_VALUE[0][0], EYETRACKER_VALUE[0][1], EYETRACKER_VALUE[0][2], EYETRACKER_VALUE[0][3], EYETRACKER_VALUE[0][4]]); | |
} | |
if (k >= xsteps * ysteps) { | |
clearInterval(interval); | |
WS.sound('SUCCESS') | |
WS.log(JSON.stringify(points)); | |
return; | |
} | |
WS.sound('TAP') | |
i = Math.floor(k / xsteps); | |
j = k % xsteps; | |
x = j * xstep + 320; | |
y = i * ystep + 240; | |
context.drawImage(imageObj, -j * xstep, -i * ystep); | |
k += 1; | |
}, 15000); | |
}; | |
imageObj.src = 'file://' + path; | |
} | |
function eyetracker(data) { | |
var sensor = msgpack.unpack(atob(data)); | |
EYETRACKER_VALUE = sensor[2]['Pupil Eyetracker'][0]; | |
WS.log(JSON.stringify(EYETRACKER_VALUE)); | |
} | |
function server() { | |
WS.log('Welcome to WearScript'); | |
WS.say('Welcome to WearScript'); | |
WS.subscribe('sensors:eyetracker', 'eyetracker'); | |
//WS.wake(); | |
//WS.activityCreate(); | |
WS.cameraPhotoPath('cb'); | |
} | |
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