|
@ -26,36 +26,8 @@ function connecthandler(e) { |
|
|
addgamepad(e.gamepad); |
|
|
addgamepad(e.gamepad); |
|
|
} |
|
|
} |
|
|
function addgamepad(gamepad) { |
|
|
function addgamepad(gamepad) { |
|
|
controllers[gamepad.index] = gamepad; var d = document.createElement("div"); |
|
|
controllers[gamepad.index] = gamepad; |
|
|
d.setAttribute("id", "controller" + gamepad.index); |
|
|
|
|
|
var t = document.createElement("h1"); |
|
|
|
|
|
t.appendChild(document.createTextNode("gamepad: " + gamepad.id)); |
|
|
|
|
|
d.appendChild(t); |
|
|
|
|
|
var b = document.createElement("div"); |
|
|
|
|
|
b.className = "buttons"; |
|
|
|
|
|
for (var i=0; i<gamepad.buttons.length; i++) { |
|
|
|
|
|
var e = document.createElement("span"); |
|
|
|
|
|
e.className = "button"; |
|
|
|
|
|
//e.id = "b" + i;
|
|
|
|
|
|
e.innerHTML = i; |
|
|
|
|
|
b.appendChild(e); |
|
|
|
|
|
} |
|
|
|
|
|
d.appendChild(b); |
|
|
|
|
|
var a = document.createElement("div"); |
|
|
|
|
|
a.className = "axes"; |
|
|
|
|
|
for (i=0; i<gamepad.axes.length; i++) { |
|
|
|
|
|
e = document.createElement("meter"); |
|
|
|
|
|
e.className = "axis"; |
|
|
|
|
|
//e.id = "a" + i;
|
|
|
|
|
|
e.setAttribute("min", "-1"); |
|
|
|
|
|
e.setAttribute("max", "1"); |
|
|
|
|
|
e.setAttribute("value", "0"); |
|
|
|
|
|
e.innerHTML = i; |
|
|
|
|
|
a.appendChild(e); |
|
|
|
|
|
} |
|
|
|
|
|
d.appendChild(a); |
|
|
|
|
|
document.getElementById("start").style.display = "none"; |
|
|
|
|
|
document.body.appendChild(d); |
|
|
|
|
|
rAF(updateStatus); |
|
|
rAF(updateStatus); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -64,8 +36,6 @@ function disconnecthandler(e) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function removegamepad(gamepad) { |
|
|
function removegamepad(gamepad) { |
|
|
var d = document.getElementById("controller" + gamepad.index); |
|
|
|
|
|
document.body.removeChild(d); |
|
|
|
|
|
delete controllers[gamepad.index]; |
|
|
delete controllers[gamepad.index]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -73,10 +43,9 @@ function updateStatus() { |
|
|
scangamepads(); |
|
|
scangamepads(); |
|
|
for (j in controllers) { |
|
|
for (j in controllers) { |
|
|
var controller = controllers[j]; |
|
|
var controller = controllers[j]; |
|
|
var d = document.getElementById("controller" + j); |
|
|
|
|
|
var buttons = d.getElementsByClassName("button"); |
|
|
|
|
|
for (var i=0; i<controller.buttons.length; i++) { |
|
|
for (var i=0; i<controller.buttons.length; i++) { |
|
|
var b = buttons[i]; |
|
|
|
|
|
var val = controller.buttons[i]; |
|
|
var val = controller.buttons[i]; |
|
|
var pressed = val == 1.0; |
|
|
var pressed = val == 1.0; |
|
|
var touched = false; |
|
|
var touched = false; |
|
@ -88,22 +57,11 @@ function updateStatus() { |
|
|
val = val.value; |
|
|
val = val.value; |
|
|
} |
|
|
} |
|
|
var pct = Math.round(val * 100) + "%"; |
|
|
var pct = Math.round(val * 100) + "%"; |
|
|
b.style.backgroundSize = pct + " " + pct; |
|
|
|
|
|
b.className = "button"; |
|
|
|
|
|
if (pressed) { |
|
|
|
|
|
b.className += " pressed"; |
|
|
|
|
|
} |
|
|
|
|
|
if (touched) { |
|
|
|
|
|
b.className += " touched"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var axesChanged = false; |
|
|
var axesChanged = false; |
|
|
var axes = d.getElementsByClassName("axis"); |
|
|
|
|
|
for (var i=0; i<controller.axes.length; i++) { |
|
|
for (var i=0; i<controller.axes.length; i++) { |
|
|
var a = axes[i]; |
|
|
|
|
|
a.innerHTML = i + ": " + controller.axes[i].toFixed(4); |
|
|
|
|
|
a.setAttribute("value", controller.axes[i]); |
|
|
|
|
|
if (axesState[i] != controller.axes[i]) { |
|
|
if (axesState[i] != controller.axes[i]) { |
|
|
axesState[i] = controller.axes[i]; |
|
|
axesState[i] = controller.axes[i]; |
|
|
axesChanged = true; |
|
|
axesChanged = true; |
|
|