Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Gamepad support #1

Open
NoahAndrews opened this issue Dec 7, 2017 · 0 comments
Open

Gamepad support #1

NoahAndrews opened this issue Dec 7, 2017 · 0 comments

Comments

@NoahAndrews
Copy link
Member

You'll need to implement RobotCoreGamepadManager.

My suggestion is that you convert Gamepad into an abstract class that will handle all of the Robocol conversion stuff, but leave the interactions with the physical gamepad up to subclasses.

Assuming that we're using a library that requires us to poll the gamepads (as opposed to the event driven model we have in the Android gamepad API), I think we'll need to have a loop in its own thread that's updating the gamepad continuously. Polling the gamepads every time we want to send data sounds OK if it's fast enough, but probably isn't a good option if we want to set the "User" via the usual button combo.

This is the current code to actually send the joystick data to the RC. It can be tweaked, ofc. It gets called every 40 ms.

// send gamepads if we have the info to do so (which will only be on the DS)
if(parameters.gamepadManager != null) {
    long now = MyApp.Companion.getRuntime().msLong();

    for (Gamepad gamepad : parameters.gamepadManager.getGamepadsForTransmission()) {

    // don't send stale gamepads
        if (now - gamepad.timestamp > GAMEPAD_UPDATE_THRESHOLD && gamepad.atRest()) {
            continue;
        }

        gamepad.setSequenceNumber();
        RobocolDatagram packetGamepad = new RobocolDatagram(gamepad);
        send(packetGamepad);
     }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant