dmadison / ArduinoXInput

XInput library for USB capable Arduino boards
http://www.partsnotincluded.com/arduino-xinput-library/
MIT License
362 stars 61 forks source link

Rumble/ Forcefeedack #96

Closed NafisAhnnaf closed 4 days ago

NafisAhnnaf commented 2 months ago

No Rumble data or forcefeedback data is being received by the callback function. Is anyone facing a similar issue? Using Arduino Micro.

xbox.setReceiveCallback(rumbleCallback);

Is this line of code enough to receive callback data. I mean in my pc the controller is working fine but there is no forcefeedback feature being shown. I am assuming more initialization codes need to be written in setup() to actually innitiate rumble feature. Also Is there any necessity of a receive() function in void loop() to look for async callbackks or rumble data.?

The callback function.

int rumble;
void rumbleCallback(uint8_t packetType) {
    // If we have an LED packet (0x01), do nothing
    if (packetType == (uint8_t) XInputReceiveType::LEDs) {
        return;
    }
    // If we have a rumble packet (0x00), see our rumble data on the LED
    else if (packetType == (uint8_t) XInputReceiveType::Rumble) {
        uint8_t rumbleValue = xbox.getRumbleRight();
        rumble = rumbleValue; 
    }
}
dmadison commented 2 months ago

What is xbox?

The library is meant to be used with the global XInput object. The callback from the USB handler calls XInput.receive(), other class instances will not receive data. If you want to use your own object for whatever reason, you will need to set the callback for the USB API (XInputUSB::setRecvCallback()) to a function that then calls XInputController::receive() in order to parse the data. If you want you can also bypass the library entirely and parse the data yourself, again using the lower level USB API.

It is not necessary to do anything in loop() to handle the data if you are using the callbacks.