Skip to content

Commit

Permalink
Use a bitfield sequence to configure LED behaviour for gamepad status.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbuller authored and robsdedude committed Apr 4, 2020
1 parent 07f6300 commit 619a0b0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
7 changes: 5 additions & 2 deletions app/virtual_gamepad_hub.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ Virtual gamepad hub class

gamepad = require './virtual_gamepad'
log = require '../lib/log'
config = require '../config'

num_gamepads = config.ledBitFieldSequence.length

class virtual_gamepad_hub

constructor: () ->
@gamepads = []
for i in [0..3]
for i in [0..(num_gamepads-1)]
@gamepads[i] = undefined

connectGamepad: (callback) ->
Expand All @@ -19,7 +22,7 @@ class virtual_gamepad_hub

# Check is a slot is available
# and retrieve the corresponding gamepad id
while !freeSlot and padId < 4
while !freeSlot and padId < num_gamepads
if !@gamepads[padId]
freeSlot = true
else
Expand Down
12 changes: 8 additions & 4 deletions app/virtual_gamepad_hub.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"port": 80,
"useGamepadByDefault": false,
"analog": true,
"logLevel": "info"
"logLevel": "info",
"ledBitFieldSequence": [1,2,4,8,9,10,12,13,14,15]
}
10 changes: 8 additions & 2 deletions public/js/virtual_gamepad_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,16 @@ function removegamepad(gamepad) {
************************/
var indicatorOn;
var slotNumber;
var ledBitField;
var initSlotIndicator = function () {
indicatorOn = false;
var slotAnimationLoop = function () {
if (slotNumber != undefined) {
if (ledBitField != undefined) {
$(".indicator").removeClass("indicatorSelected");
$("#indicator_"+(slotNumber+1)).addClass("indicatorSelected");
if (ledBitField & 0b0001) { $("#indicator_1").addClass("indicatorSelected"); }
if (ledBitField & 0b0010) { $("#indicator_2").addClass("indicatorSelected"); }
if (ledBitField & 0b0100) { $("#indicator_3").addClass("indicatorSelected"); }
if (ledBitField & 0b1000) { $("#indicator_4").addClass("indicatorSelected"); }
} else {
if(indicatorOn) {
$(".indicator").removeClass("indicatorSelected");
Expand Down Expand Up @@ -454,6 +458,8 @@ $( window ).load(function() {

socket.on("gamepadConnected", function(data) {
slotNumber = data.padId;
ledBitField = data.ledBitField;
console.log("Here I am, and", data)

$(".btn").off("touchstart touchend");

Expand Down
3 changes: 2 additions & 1 deletion server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ io.on 'connection', (socket) ->

socket.on 'connectGamepad', () ->
gp_hub.connectGamepad (gamePadId) ->
ledBitField = config.ledBitFieldSequence[gamePadId]
if gamePadId != -1
log 'info', 'connectGamepad: success'
socket.gamePadId = gamePadId
socket.emit 'gamepadConnected', {padId: gamePadId}
socket.emit 'gamepadConnected', {padId: gamePadId, ledBitField: ledBitField}
else
log 'warning', 'connectGamepad: failed'

Expand Down
5 changes: 4 additions & 1 deletion server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 619a0b0

Please sign in to comment.