Code Monkey home page Code Monkey logo

node-vigemclient's Introduction

node-ViGEmClient

Native Node.js bindings for the ViGEm virtual gamepad driver.

Current SDK version: commit f719a1d

Installation

npm install vigemclient

Since ViGEmBus only works on Windows, this module can also only be installed on Windows. If you have problems building the native code parts, try installing the Windows Build Tools by running

npm install -g windows-build-tools

Usage

A minimal example of a feeder application looks like this:

const ViGEmClient = require('vigemclient');

let client = new ViGEmClient();

client.connect(); // establish connection to the ViGEmBus driver

let controller = client.createX360Controller();

controller.connect(); // plug in the virtual controller

// change some axes and buttons
controller.axis.leftX.setValue(0.5); // move left stick 50% to the left
controller.axis.leftY.setValue(-0.5); // move left stick 50% down
controller.axis.leftTrigger.setValue(1); // press in left trigger all the way

controller.button.Y.setValue(true); // press Y button

More examples can be found in the examples/ directory.

Methods

ViGEmClient

constructor()

connect()
Connect to the ViGEmBus driver. Returns null on success and an Error if there was an error.

createX360Controller()
Create a new X360Controller instance, with this client as its parent. Can only be called after a connection to the driver has been established.

createDS4Controller(extended = false)
Create a new DS4Controller instance, with this client as its parent. Can only be called after a connection to the driver has been established. If the extended parameter is set to true, a DS4ControllerExtended will be instantiated, which gives access to an experimental feature, allowing access to gyro, accelerometer, trackpad and more, but which is otherwise exactly the same as DS4Controller.

ViGEmTarget

Both X360Controller and DS4Controller inherit from this class, but you can not instantiate it yourself. Most of the methods and properties are the same for both controller types and where they aren't, the differences will be made clear.

get vendorID
Get the vendor ID of the device. Can only be accessed after connect() has been called.

get productID
Get the product ID of the device. Can only be accessed after connect() has been called.

get index
Get the internal index of the device. Can only be accessed after connect() has been called.

get type
Get a string describing the type of the device. Either "Xbox360Wired", "XboxOneWired" or "DualShock4Wired". Can only be accessed after connect() has been called.

get updateMode
set updateMode
Get or set the updateMode. Per default the mode is set to "auto", which leads to every change of each button or axis to be sent to the driver instantly. Set to "manual" if you often update multiple values at once. but don't forget that you have to call update() yourself when in this mode.

get button
Get an object containing all the buttons of the controller. This property differs between the controller types.

X360Controller has the following buttons:

  • START
  • BACK
  • LEFT_THUMB
  • RIGHT_THUMB
  • LEFT_SHOULDER
  • RIGHT_SHOULDER
  • GUIDE
  • A
  • B
  • X
  • Y

DS4Controller has the following buttons:

  • THUMB_RIGHT
  • THUMB_LEFT
  • OPTIONS
  • SHARE
  • TRIGGER_RIGHT
  • TRIGGER_LEFT
  • SHOULDER_RIGHT
  • SHOULDER_LEFT
  • TRIANGLE
  • CIRCLE
  • CROSS
  • SQUARE
  • SPECIAL_PS
  • SPECIAL_TOUCHPAD

All of these buttons are instances of InputButton (documented below).

get axis
Get an object containing all the axes of the controller. This property is the same for both controller types.

  • leftX
  • leftY
  • rightX
  • rightY
  • leftTrigger
  • rightTrigger
  • dpadHorz
  • dpadVert
  • batteryLevel (only DS4ControllerExtended)

All of these buttons are instances of InputAxis (documented below).

get userIndex (X360Controller only)
Get the user index of the virtual Xbox controller. This values corresponds to the player number displayed on the LEDs.

connect(opts = {})
Connect the controller to the driver. This is equivalent of plugging the controller into a USB port. The opts parameter is an object with the following optional properties:

  • vendorID: Specify a custom device vendor ID.
  • productID: Specify a custom device product ID.

Returns null on success and an Error on error.

disconnect()
Disconnect the controller from the driver. This is equivalent of unplugging the controller. Returns null on success and an Error on error.

update()
Submit updated button and axis values to the driver. If updateMode is set to "auto" (default), this method will be called automatically if a value is changed.

resetInputs()
Resets all buttons and axes to their unpressed/neutral states.

addTouch(touch) (DS4ControllerExtended only)
Add a DS4TrackpadTouch object to the current input report. You can add up to 3 of these before having to call update(), but it is usually advised to submit new touch events as soon as they are available.

setGyro(pitch, yaw, roll) (DS4ControllerExtended only)
Sets the gyroscope orientation. Each value is in degrees and must be between -2000 and 2000.

setAccelerometer(x, y, z) (DS4ControllerExtended only)
Set the current accelerometer measurement. Each value is in g-force and must be between -4 and 4.

Note about the gyroscope and the accelerometer: The values they produce are processed as a function of time, therefore each input report contains a timestamp so the receiving application can calculate the change over time. According to the documentation, this timestamp "usually increments" by 188 when the controller is updating every 1.25ms. Ergo, this library will measure the time between updates and increment the timestamp by the measured time multiplied by 188/1.25. I have no idea if this is correct way to do it, but I have no way to test it unfortunately. Just be warned that you need to call update() periodically (and probably with a high update rate) if you want the gyro and accelerometer values to make any sense/be usable.

InputButton

This class represents a single button on a controller. You can not instantiate this class directly, instead you get objects of this class from the .button property from a ViGEmTarget instance.

get name
Get the internal name of this button.

get value
Get the currently set value of this button.

setValue(value)
Set the value of the button (either true or false).

InputAxis

This class represents a single axis on a controller. You can not instantiate this class directly, instead you get objects of this class from the .axis property from a ViGEmTarget instance.

get name
Get the internal name of this axis.

get value
Get the currently set value of the axis (between minValue and maxValue).

get valueRaw
Get the current raw (internal) value of this axis (between minValueRaw and maxValueRaw). This is the value that was sent to the driver.

get minValue
Get the lowest value this axis can be set to. Lower values will be clamped to this value.

get maxValue
Get the highest value this axis can be set to. Higher values will be clamped to this value.

get minValueRaw
Get the lowest value this axis can take on (when accessing .valueRaw).

get maxValueRaw
Get the highest value this axis can take on (when accessing .valueRaw).

get neutralValue
The the "middle" of the axis, i.e. the position at which it is considered "neutral". As of right now, all controllers have this value set to 0.

setValue(value)
Set the value of this axis (between minValue and maxValue). The POV switch is also represented as an axis and it also takes continuous values, but since POV switches are digital, the values are cut-off at 0.5, so >0.5 means pressed and <= 0.5 means not pressed.

reset()
Resets the axis to its neutral position.

DS4TrackpadTouch

This class represents a single multitouch event on the DS4 trackpad. You can import this class by requiring it from "vigemclient/extra".

getFingersDown()
Get the number of fingers that you have setup to touch the trackpad. Either 0, 1 or 2.

addFingerDown(x, y)
Place another finger on the trackpad at location (x,y), with 0 <= x <= 1920 and 0 <= y <= 943. If you try to add more than two fingers, the method will throw an error.

allFingersUp()
Delete all previously added fingers from this event.

Events

Both X360Controller and DS4Controller register a "notification callback" with the bus driver, which is called every time a controller is supposed to vibrate or if the LEDs on the controller change. For the sake of convenience, the data contained in the notification is split up and emitted as regular node events.

Event "large motor"
Emitted by: X360Controller, DS4Controller
Emitted every time the intensity of the large vibration motor changes. The emitted values range from 0 to 255.

Event "small motor"
Emitted by: X360Controller, DS4Controller
Emitted every time the intensity of the small vibration motor changes. The emitted values range from 0 to 255.

Event "vibration"
Emitted by: X360Controller, DS4Controller
Emitted every time the intensity of the large or the small vibration motor changes. The emitted values are objects of the form { large, small }, containing the values of both motors.

Event "notification"
Emitted by: X360Controller, DS4Controller
Emitted every time the notification callback is called. The emmitted values are objects of the form { LargeMotor, SmallMotor, LedNumber } for X360Controller and { LargeMotor, SmallMotor, LightbarColor: { Red, Green, Blue } } for DS4Controller.

Event "led change"
Emitted by: X360Controller
Emitted every time the LEDs around the guide button change. The emitted values range from 0 to 3.

Event "color change"
Emitted by: DS4Controller
Emitted every time the color of the lightbar changes. The emitted values are objects of the form { Red, Green, Blue }, with each components value ranging from 0 to 255.

node-vigemclient's People

Contributors

ejj28 avatar jangxx avatar vicimpa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-vigemclient's Issues

Disconnecting a Controller causes segmentation fault

when trying to disconnect a connected controller, the application crashes, for example:

const ViGEmClient = require("vigemclient");
let client = new ViGEmClient();
client.connect();
let controller = client.createX360Controller();
controller.connect();
setTimeout(()=>{
controller.disconnect();
},1000)

causes the terminal to spit out:

npm[16920]: c:\ws\src\node_api.cc:1075: Assertion `(func) != nullptr' failed.
1: 00007FF71140A41F v8::internal::wasm::DisjointAllocationPool::~DisjointAllocationPool+74447
2: 00007FF7113B2F26 v8::base::CPU::has_sse+59718
3: 00007FF7113B32A1 v8::base::CPU::has_sse+60609
4: 00007FF7113DA8BE napi_call_threadsafe_function+30
5: 00007FFEAFF6FB9F x360_notification_callback+159 [D:\Downloads\node-ViGEmClient-master\node-ViGEmClient-master\src\target_x360.cpp]:L9
6: 00007FFEB7BDE988 vigem_target_x360_get_user_index+3816
7: 00007FFEB7BDE823 vigem_target_x360_get_user_index+3459
8: 00007FFEB7BD4D41
9: 00007FFEB7BD46B5
10: 00007FFEB7BD41CA
11: 00007FFEB7BD5563
12: 00007FFEB7BE0A73 vigem_target_x360_get_user_index+12243
13: 00007FFEB7C04F10 vigem_target_x360_get_user_index+160880
14: 00007FFECF037BD4 BaseThreadInitThunk+20
15: 00007FFED018CE51 RtlUserThreadStart+33

image

at first I thought it because controller does not unregister the notification receiver, so i tried the following:

const ViGEmClient = require(".."); // lets say this is done from example folder in repo
const vigemclient = require('../build/Release/vigemclient');
let client = new ViGEmClient();
client.connect();
let controller = client.createX360Controller();
controller.connect();
setTimeout(() => {
vigemclient.vigem_target_x360_unregister_notification(controller._target);
controller.disconnect();
}, 1000);

this causes the application to close with:

error Command failed with exit code 3221225477.

or when run with npx:

/d/Programs/Programming/NodeJS/npx: line 35: 2976 Segmentation fault "$NODE_EXE" "$NPX_CLI_JS" "$@"

I tried putting a delay between removing the notification and disconnecting the controller, and it seems to work, but its not consistent;

const ViGEmClient = require("..");
const vigemclient = require("../build/Release/vigemclient");
let client = new ViGEmClient();
client.connect();
let controller = client.createX360Controller();
controller.connect();
setTimeout(() => {
vigemclient.vigem_target_x360_unregister_notification(controller._target);
setTimeout(() => {
controller.disconnect();
}, 100);
}, 1000);

Installed and Built but having issues resolving build files

Files are installed and built correctly yet it is not able to resolve the built files. I'm assuming its the vigemclient.node file it's looking for, and I can see it in ../build/Release/. Any solutions on how to resolve this issue?

`[ERROR] Could not resolve "../build/Release/vigemclient"

node_modules/vigemclient/lib/ViGEmClient.js:1:28:
  1 │ const vigemclient = require('../build/Release/vigemclient');
    ╵                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/vigemclient/lib/X360Controller.js:1:28:
  1 │ const vigemclient = require('../build/Release/vigemclient');
    ╵                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/vigemclient/lib/DS4Controller.js:1:28:
  1 │ const vigemclient = require('../build/Release/vigemclient');
    ╵                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/vigemclient/lib/ViGEmTarget.js:3:28:
  3 │ const vigemclient = require('../build/Release/vigemclient');
    ╵                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

The button didn't detected even though i already set the value to true

This is my code :
`
xbox360SetButtonValue(buttonName, value)
{
let err = null;

    if(value !== true && value !== false)
    {
        err = true;
    }

    if(!err)
    {
        switch(buttonName) {
            case "X":
                this.controller.button.X.setValue(value); // press X button
                console.log(`${buttonName}`)
                break;
            case "Y":
                this.controller.button.Y.setValue(value); // press Y button
                console.log(`${buttonName}`)
                break;
            case "A":
                this.controller.button.A.setValue(value); // press A button
                console.log(`${buttonName}`)
                break;
            case "B":
                this.controller.button.B.setValue(value); // press B button
                console.log(`${buttonName}`)
                break;
            // case "DPAD_UP":
            //     this.controller.button.DPAD_UP.setValue(value); // press DPAD_UP button
            //     break;
            // case "DPAD_DOWN":
            //     this.controller.button.DPAD_DOWN.setValue(value); // press DPAD_DOWN button
            //     break;
            // case "DPAD_LEFT":
            //     this.controller.button.DPAD_LEFT.setValue(value); // press DPAD_LEFT button
            //     break;
            // case "DPAD_RIGHT":
            //     this.controller.button.DPAD_RIGHT.setValue(value); // press DPAD_RIGHT button
            //     break;
            case "START":
                this.controller.button.START.setValue(value); // press START button
                break;
            case "BACK":
                this.controller.button.BACK.setValue(value); // press BACK button
                break;
            case "LEFT_THUMB":
                this.controller.button.LEFT_THUMB.setValue(value); // press LEFT_THUMB button
                break;
            case "RIGHT_THUMB":
                this.controller.button.RIGHT_THUMB.setValue(value); // press RIGHT_THUMB button
                break;
            case "LEFT_SHOULDER":
                this.controller.button.LEFT_SHOULDER.setValue(value); // press LEFT_SHOULDER button
                break;
            case "RIGHT_SHOULDER":
                this.controller.button.RIGHT_SHOULDER.setValue(value); // press RIGHT_SHOULDER button
                break;
            case "GUIDE":
                this.controller.button.GUIDE.setValue(value); // press GUIDE button
                break;
            default:
                err = false;
        }
    }

    return err;
}

`

My code is simple, yet the game or gamepad tester doesn't recognize the input. What did i do wrong ?

Something is wrong with the feeder

So, I've been working on making a virtual gamepad, but when I'm making it, there are some issues I've found on the making

  1. When creating the controller, the axis value will not be exactly zero
    image

  2. I Believe the left analog axis is error, when it's the first value that changed and the analog is in the first quadrant ( 0 to 90 degrees ) and the third quadrant ( 180 - 270 degrees ). The right analog is just fine. It will look like this
    image

Note: I've tried another tester. I've verified my input value. And etc. And in conclusion, I thought it's probably in the library itself.

The Code ( Bear with my code, lol ) :
`const feeder = require('./vigem');
var controllers = {};

const express = require('express');
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 7200;

const buttons = {
BOTTOM_BUTTON : "A",
RIGHT_BUTTON : "B",
TOP_BUTTON : "Y",
LEFT_BUTTON : "X",
RIGHT_SHOULDER : "RIGHT_SHOULDER",
LEFT_SHOULDER : "LEFT_SHOULDER",
START : "START",
BACK : "BACK"
}

const axes = {
ANALOG_LEFT : "left",
ANALOG_RIGHT: "right"
}

const shoulder = {
LEFT_TRIGGER : "left",
RIGHT_TRIGGER: "right"
}

// Set root to xbox layout
app.get('/', (req, res) => {
return res.sendFile(__dirname + "/static/s-new.html");
});

// Set /static as root so the assets and stuffs can be loaded
app.use('/', express.static(__dirname + '/static'));

// Socket.io
io.on('connection', (socket) => {
let notificationCallback = function(data)
{
if(data)
{
io.to(socket.id).emit("vibration", true);
} else {
io.to(socket.id).emit("vibration", false);
}
}
controllers[socket.id] = new feeder("x360", notificationCallback);
let client = controllers[socket.id];

// console.log(`a user connected with socketID of ${socket.id}`);

// // Sending to all client
// socket.emit("message", "can you hear me?");

// // Sending to specific client
// io.to(socket.id).emit("message", "I just met you");

socket.on('disconnect', () => {
    console.log('user disconnected');
    client.disconnect();
});

socket.on('message', (tes) => {
    switch(tes.inputType)
    {
        case "axis":
            if(tes.axis == "ANALOG_LEFT" || tes.axis == "ANALOG_RIGHT")
            {
                tes.x = client.clampIt(tes.x, tes.r)
                tes.y = client.clampIt(tes.y, tes.r)
                console.log(tes.x, tes.y)
                client.xbox360SetAxisValue(`${axes[tes.axis]}X`, tes.x );
                client.xbox360SetAxisValue(`${axes[tes.axis]}Y`, tes.y );
                client.update();
            }
            break;
        case "triggerAxis":
            if(tes.axis == "LEFT_TRIGGER" || tes.axis == "RIGHT_TRIGGER")
            {
                tes.value = tes.value/tes.max;
                client.xbox360SetAxisValue(`${shoulder[tes.axis]}Trigger`, tes.value );
                client.update();
            }
            break;
        case "button":
            client.xbox360SetButtonValue(buttons[tes.button], !!tes.v);
            break;
    }
    //console.log(`${JSON.stringify(tes)}`);
});

});

http.listen(port, () => {
console.log(Listenting on ${port});
});`

`const ViGEmClient = require('vigemclient');

class feeder {
constructor(controller, notificationCallback)
{
switch(controller) {
case "x360":
this._controllerName = "x360";
this.xbox360feeder(notificationCallback);
// this.xbox360reset();
break;
case "ds4":
this._controllerName = "ds4";
this.ds4feeder(notificationCallback);
break;
default:
this._controllerName = "x360";
this.xbox360feeder(notificationCallback);
}
}

connectClient()
{
    this.client = new ViGEmClient();
    let err = this.client.connect(); // establish connection to the ViGEmBus driver
    return err;
}

connectController(controllerName)
{
    switch(controllerName) {
        case "x360":
            this.controller = this.client.createX360Controller(); //Spawn x360 virtual controller
            break;
        case "ds4":
            this.controller = this.client.createDS4Controller(); //Spawn ds4 virtual controller
            break;
        default:
            this.controller = this.client.createX360Controller(); //Spawn x360 virtual controller
    }
    let err = this.controller.connect();
    return err;
}

outputIDs(controllerName)
{
    console.log("Vendor ID:", this.controller.vendorID);
    console.log("Product ID:", this.controller.productID);
    console.log("Index:", this.controller.index);
    console.log("Type:", this.controller.type);
    // if(controllerName == "x360")
    // {
    //     console.log("User index:", this.controller.userIndex);
    // }
}

clamp(value, min, max) {
    return Math.min(max, Math.max(min, value));
}

update()
{
    this.controller.update(); // update manually for better performance
}

disconnect()
{
    let err = this.controller.disconnect(); // update manually for better performance
    return err;
}

convertAngleToAxis(a, s) // To convert Angle and Strength of a circle to X and Y of square
{
    let x = (s/100)*Math.cos(a*Math.PI/180);
    let y = (s/100)*Math.sin(a*Math.PI/180);
    let xSquare = 0.5*Math.sqrt(2+2*Math.sqrt(2)*x+Math.pow(x,2)-Math.pow(y,2)) - 0.5*Math.sqrt(2-2*Math.sqrt(2)*x+Math.pow(x,2)-Math.pow(y,2)); // x = ½ √( 2 + 2u√2 + u² - v² ) - ½ √( 2 - 2u√2 + u² - v² )
    let ySquare = 0.5*Math.sqrt(2+2*Math.sqrt(2)*y-Math.pow(x,2)+Math.pow(y,2)) - 0.5*Math.sqrt(2-2*Math.sqrt(2)*y-Math.pow(x,2)+Math.pow(y,2)); // y = ½ √( 2 + 2v√2 - u² + v² ) - ½ √( 2 - 2v√2 - u² + v² )
    if(isNaN(xSquare) && isNaN(ySquare)) {
        if(x>=0)
        {
            xSquare = 1;
        } else {
            xSquare = -1;
        }
        if(y>=0)
        {
            ySquare = 1;
        } else {
            ySquare = -1;
        }
    }
    return {x: xSquare, y: ySquare};
}

convertCircleCoordToSquareCoord(u, v)
{
    u = u / 35 * 1; // 35 = radius of the joystick // u,v element u^2 + v^2 <= 1
    v = -v / 35 * 1; // 35 = radius of the joystick // u,v element u^2 + v^2 <= 1 // The y is inverted, from the client so we need to invert it here
    let xSquare = 0.5*Math.sqrt(2+2*Math.sqrt(2)*u+Math.pow(u,2)-Math.pow(v,2)) - 0.5*Math.sqrt(2-2*Math.sqrt(2)*u+Math.pow(u,2)-Math.pow(v,2)); // x = ½ √( 2 + 2u√2 + u² - v² ) - ½ √( 2 - 2u√2 + u² - v² )
    let ySquare = 0.5*Math.sqrt(2+2*Math.sqrt(2)*v-Math.pow(u,2)+Math.pow(v,2)) - 0.5*Math.sqrt(2-2*Math.sqrt(2)*v-Math.pow(u,2)+Math.pow(v,2)); // y = ½ √( 2 + 2v√2 - u² + v² ) - ½ √( 2 - 2v√2 - u² + v² )
    if(isNaN(xSquare) && isNaN(ySquare)) {
        if(u>=0)
        {
            xSquare = 1;
        } else {
            xSquare = -1;
        }
        if(v>=0)
        {
            ySquare = 1;
        } else {
            ySquare = -1;
        }
    }
    return {x: xSquare, y: ySquare};
}

clampIt(value, max)
{
    return value/max;
}

//--------------------------------------------------[ XBOX 360 Feeder ]--------------------------------------------------//

xbox360reset()
{
    let value = 0;
    this.controller.button.X.setValue(value); // press X button
    this.controller.button.Y.setValue(value); // press Y button
    this.controller.button.A.setValue(value); // press A button
    this.controller.button.B.setValue(value); // press B button
    //     this.controller.button.DPAD_UP.setValue(value); // press DPAD_UP button
    //     this.controller.button.DPAD_DOWN.setValue(value); // press DPAD_DOWN button
    //     this.controller.button.DPAD_LEFT.setValue(value); // press DPAD_LEFT button
    //     this.controller.button.DPAD_RIGHT.setValue(value); // press DPAD_RIGHT button
    this.controller.button.START.setValue(value); // press START button
    this.controller.button.BACK.setValue(value); // press BACK button
    this.controller.button.LEFT_THUMB.setValue(value); // press LEFT_THUMB button
    this.controller.button.RIGHT_THUMB.setValue(value); // press RIGHT_THUMB button
    this.controller.button.LEFT_SHOULDER.setValue(value); // press LEFT_SHOULDER button
    this.controller.button.RIGHT_SHOULDER.setValue(value); // press RIGHT_SHOULDER button
    this.controller.button.GUIDE.setValue(value); // press GUIDE button
    this.controller.axis.leftX.setValue(value); // Left analog X
    this.controller.axis.leftY.setValue(value); // Left analog Y
    this.controller.axis.leftTrigger.setValue(value); // Left Trigger
    this.controller.axis.rightX.setValue(value); // Right analog X
    this.controller.axis.rightY.setValue(value); // Right analog Y
    this.controller.axis.rightTrigger.setValue(value); // Right Trigger
    this.controller.axis.dpadHorz.setValue(value); // Horizontal DPAD
    this.controller.axis.dpadVert.setValue(value); // Horizontal DPAD
}

xbox360feeder(notificationCallback)
{
    let connectClient = this.connectClient(); // Connecting to ViGEmBus driver
    if(connectClient == null) // Checking if connectclient returning null which what we wanted
    {
        let errConnectController = this.connectController(this._controllerName); // Connecting to virtual controller
        if (errConnectController) // Checking if errconnectcontroller returning true which is error happenned
        {
            console.log(errConnectController.message); // Outputting the error message
            process.exit(1);
        }

        this.outputIDs(this._controllerName); // Outputting vendor id and stuffs

        // Controller notification
        this.controller.on("notification", data => {
            console.log("notification", data);
            // if(data.LargeMotor > 0 || data.SmallMotor > 0)
            // {
            //     notificationCallback(true);
            // } else {
            //     notificationCallback(false);
            // }
        });

        // this.controller.updateMode = "manual"; // requires manual calls to controller.update()

        let tes = 0;
        let testing = setInterval(function()
        { 
            if(tes%2 == 0)
            {
                notificationCallback(true);
            } else {
                notificationCallback(false);
            }

            if(tes == 3){
                clearInterval(testing);
            }
            tes++;
        }, 10000);
    }
}

xbox360SetButtonValue(buttonName, value)
{
    let err = null;

    if(value !== true && value !== false)
    {
        err = true;
    }

    if(!err)
    {
        switch(buttonName) {
            case "X":
                this.controller.button.X.setValue(value); // press X button
                break;
            case "Y":
                this.controller.button.Y.setValue(value); // press Y button
                break;
            case "A":
                this.controller.button.A.setValue(value); // press A button
                break;
            case "B":
                this.controller.button.B.setValue(value); // press B button
                break;
            // case "DPAD_UP":
            //     this.controller.button.DPAD_UP.setValue(value); // press DPAD_UP button
            //     break;
            // case "DPAD_DOWN":
            //     this.controller.button.DPAD_DOWN.setValue(value); // press DPAD_DOWN button
            //     break;
            // case "DPAD_LEFT":
            //     this.controller.button.DPAD_LEFT.setValue(value); // press DPAD_LEFT button
            //     break;
            // case "DPAD_RIGHT":
            //     this.controller.button.DPAD_RIGHT.setValue(value); // press DPAD_RIGHT button
            //     break;
            case "START":
                this.controller.button.START.setValue(value); // press START button
                break;
            case "BACK":
                this.controller.button.BACK.setValue(value); // press BACK button
                break;
            case "LEFT_THUMB":
                this.controller.button.LEFT_THUMB.setValue(value); // press LEFT_THUMB button
                break;
            case "RIGHT_THUMB":
                this.controller.button.RIGHT_THUMB.setValue(value); // press RIGHT_THUMB button
                break;
            case "LEFT_SHOULDER":
                this.controller.button.LEFT_SHOULDER.setValue(value); // press LEFT_SHOULDER button
                break;
            case "RIGHT_SHOULDER":
                this.controller.button.RIGHT_SHOULDER.setValue(value); // press RIGHT_SHOULDER button
                break;
            case "GUIDE":
                this.controller.button.GUIDE.setValue(value); // press GUIDE button
                break;
            default:
                err = false;
        }
    }

    if(this.controller.updateMode == "manual")
    {
        this.update();
    }
    return err;
}

xbox360ButtonToggle(index)
{
    let err = null;
    let buttons = Object.keys(this.controller.button);

    if(index > buttons.length)
    {
        err = true;
    }

    if(!err)
    {
        this.controller.button[buttons[index]].setValue(!this.controller.button[buttons[index]].value); // invert button value
    }

    this.update();
    return err;
}

xbox360SetAxisValue(axisName, value) 
{
    let err = null;

    if((value == null) && (typeof(value) == "number"))
    {
        err = true;
    }

    if(!err)
    {


        switch(axisName)
        {
            case "leftX":
                this.controller.axis.leftX.setValue(value); // Left analog X
                break;
            case "leftY":
                this.controller.axis.leftY.setValue(value); // Left analog Y
                break;
            case "leftTrigger":
                this.controller.axis.leftTrigger.setValue(value); // Left Trigger
                break;
            case "rightX":
                this.controller.axis.rightX.setValue(value); // Right analog X
                break;
            case "rightY":
                this.controller.axis.rightY.setValue(value); // Right analog Y
                break;
            case "rightTrigger":
                this.controller.axis.rightTrigger.setValue(value); // Right Trigger
                break;
            case "dpadHorz":
                this.controller.axis.dpadHorz.setValue(value); // Horizontal DPAD
                break;
            case "dpadVert":
                this.controller.axis.dpadVert.setValue(value); // Horizontal DPAD
                break;
            default:
                err = false;
        }
    }

    if(this.controller.updateMode == "manual")
    {
        this.update();
    }
    return err;
}

//--------------------------------------------------[ XBOX 360 Feeder ]--------------------------------------------------//

}

module.exports = feeder;`

USB Vendor and Product ID setting doesn't take effect

When setting the USB VID and PID, the VID and PID don't change in Device Manager, I'm guessing this is an issue with my code?
Code:

client.connect();
let controller = client.createX360Controller();
controller.connect();
controller.vendorID = 0x1BAD;
controller.productID = 0x0003;

Left trigger and right trigger for xBox controller?

Hello again, as you suggested I switched to using ViGEm :)

This is working perfectly, except I can't figure out how to enable/disable the left an right triggers on an xbox controller? How can I do this?

I've tried using LEFT/RIGHT_SHOULDER and LEFT/RIGHT_THUMB to no avail.

Trouble Connecting to Client

Issue: Trouble Connecting to Client

What

  • The client will not connect with client.connect()
    image
    image

When

  • This is a new issue, until recently everything was working as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.