From c450f9ed041f8087a3329ea50fe0f63246e295bc Mon Sep 17 00:00:00 2001 From: Max Zhaloba <25727413+MaxZhaloba@users.noreply.github.com> Date: Wed, 27 Mar 2019 20:01:01 +0000 Subject: [PATCH] Ignore axes which return data out of the range [-1; 1] in centered position For task: Integrate Bluetooth Joystick to mobile VR set #86 --- leobot_web_server/web_content/js/config.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/leobot_web_server/web_content/js/config.js b/leobot_web_server/web_content/js/config.js index 004b91e..adde9a9 100644 --- a/leobot_web_server/web_content/js/config.js +++ b/leobot_web_server/web_content/js/config.js @@ -98,8 +98,10 @@ $(function(){ if (a >= -1 && a <= 1) { axis = a; } - initialGamepadAxes.push(a); + initialGamepadAxes.push(axis); }); + + console.log("Initial gamepad axes values:", initialGamepadAxes); break; case TABS.check: @@ -256,10 +258,12 @@ $(function(){ if (!configEntry) return; gamepad.axes.forEach(function(a, i) { - var pitch = a - initialGamepadAxes[i]; + // Can be null + var axis = initialGamepadAxes[i]; + var pitch = a - axis; var absPitch = Math.abs(pitch); - if (absPitch > pitchThreshold && i!==9) { + if (axis !== null && absPitch > pitchThreshold) { if (!configEntry.releasedValue) { configEntry.releasedValue = configEntry.pitchedValue = initialGamepadAxes[i]; }