From ac75cdd21aa8b137576c326d0dd5470c2f888ed4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 10 Mar 2019 19:07:19 +0100 Subject: [PATCH] custom readout of host provided Motion Processor Service --- stereoview.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/stereoview.js b/stereoview.js index 50863d5..edba378 100644 --- a/stereoview.js +++ b/stereoview.js @@ -66,7 +66,7 @@ function draw() { if ( gp.buttons[3].pressed ) { fov += 10; controlTimeout = Date.now() + 500; } } - // debug.textContent = "" + video.currentTime + " " + controlTimeout; + // debug.textContent = "" + video.currentTime + " " + controlTimeout + " " + tx + " " + ty + " " + tz; }; function stereoview(layout, video) { @@ -87,6 +87,30 @@ function stereoview(layout, video) { lc = lv.getContext("2d"); rc = rv.getContext("2d"); + mpuevent = new EventSource("http://localhost:314"); + var x = [], y = [], z = [], cnt = -1, inertia = 6; + + mpuevent.addEventListener("bearing", function(e) { + bearing = e.data.split(" "); + yaw = -parseFloat(bearing[0]); + }, false); + mpuevent.addEventListener("motion", function(e) { + motion = e.data.split(" "); + + cnt = (cnt + 1) % inertia; + x[cnt] = parseFloat(motion[0]); + y[cnt] = parseFloat(motion[1]); + z[cnt] = parseFloat(motion[2]); + + // tx = 0; x.forEach( function(n, i){ tx += n; } ); tx /= inertia; + ty = 0; y.forEach( function(n, i){ ty += n; } ); ty /= inertia; + tz = 0; z.forEach( function(n, i){ tz += n; } ); tz /= inertia; + + pitch = Math.asin((tz / 9.81 > 1)?1:(tz/9.81)) / Math.PI * 180 + 22.5; + roll = - Math.asin((ty / 9.81 > 1)?1:(ty/9.81)) / Math.PI * 180; + // yaw = (yaw + ty) % 360; + }, false ); + window.addEventListener("devicemotion", (function() { var x = [], y = [], z = [], cnt = -1, inertia = 6; return function(event) { -- 2.39.2