Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gravis Gamepad Pro #63

Open
Kikketer opened this issue Sep 9, 2024 · 1 comment
Open

Gravis Gamepad Pro #63

Kikketer opened this issue Sep 9, 2024 · 1 comment

Comments

@Kikketer
Copy link

Kikketer commented Sep 9, 2024

I realize this is an old style controller but I had a couple laying around and figured it would work fairly well with this setup.

Gravis Gamepad Pro:
Gravis Gamepad Pro

I checked the inputs and this is what I found:

South button:
Event: time 1725810126.146713, type 1 (EV_KEY), code 305 (BTN_EAST), value 1
West button:
Event: time 1725810170.171810, type 1 (EV_KEY), code 304 (BTN_SOUTH), value 1
North button:
Event: time 1725810185.757512, type 1 (EV_KEY), code 307 (BTN_NORTH), value 1
East button:
Event: time 1725810197.535289, type 1 (EV_KEY), code 306 (BTN_C), value 1

Start button:
Event: time 1725810244.986398, type 1 (EV_KEY), code 313 (BTN_TR2), value 1
Select button:
Event: time 1725810255.380207, type 1 (EV_KEY), code 312 (BTN_TL2), value 1

Triggers Lower L:
Event: time 1725810217.416919, type 1 (EV_KEY), code 310 (BTN_TL), value 1
Triggers Lower R:
Event: time 1725810800.340259, type 1 (EV_KEY), code 311 (BTN_TR), value 1

I then updated the arcade1.py file to match these events:

# Button mapping config
# Uses two inputs per controller, to map and convert from EV_ABS to EV_KEY in both directions
config = {
    # EV_ABS to EV_KEY mappings for 1st direction of controller 1
    (0, EV_ABS): {
        # X-axis initially towards less than/negative of center(normally left)
        ABS_X: {
            'type': (0, EV_KEY),
            'code': 30,  # Output key 'a'
            'value': lambda x: digitizeNeg1(x) if not invertXLEFT1 else digitizePos1(x)
            # lambda calls function with joystick value dependent on if axis is inverted or not
        },
        # Y-axis initially towards less than/negative of center(normally up)
        ABS_Y: {
            'type': (0, EV_KEY),
            'code': 17,  # Output key 'w'
            'value': lambda y: digitizeNeg1(y) if not invertYUP1 else digitizePos1(y)
            # lambda calls function with joystick value dependent on if axis is inverted or not
        },
        ABS_HAT0X: {
            # HAT0X-axis initially towards greater than/positive of center(normally right)
            'type': (0, EV_KEY),
            'code': 32,  # etc.
            'value': hat0Pos1  # Joystick value variable x is implied for function hat0Pos
        },
        # HAT0Y-axis initially towards greater than/positive of center(normally down)
        ABS_HAT0Y: {
            'type': (0, EV_KEY),
            'code': 31,
            'value': hat0Pos1
        }
    },
    # EV_ABS to EV_KEY mappings for 2nd direction of controller 1
    (1, EV_ABS): {
        # X-axis initially towards greater than/positive of center(normally right)
        ABS_X: {
            'type': (0, EV_KEY),
            'code': 32,
            'value': lambda x: digitizePos1(x) if not invertXLEFT1 else digitizeNeg1(x)

        },
        # Y-axis initially towards greater than/positive of center(normally down)
        ABS_Y: {
            'type': (0, EV_KEY),
            'code': 31,
            'value': lambda y: digitizePos1(y) if not invertYUP1 else digitizeNeg1(y)
        },
        # HAT0X-axis initially towards less than/negative of center(normally left)
        ABS_HAT0X: {
            'type': (0, EV_KEY),
            'code': 30,
            'value': hat0Neg1
        },
        # HAT0Y-axis initially towards less than/negative of center(normally up)
        ABS_HAT0Y: {
            'type': (0, EV_KEY),
            'code': 17,
            'value': hat0Neg1
        },
        # Start button conversion for some controllers without start button
        ABS_Z: {
            'type': (0, EV_KEY),
            'code': 1,
            'value': hat0Pos1
        },
        # Select button conversion for some controllers without select button
        ABS_RZ: {
            'type': (0, EV_KEY),
            'code': 59,
            'value': hat0Pos1
        }
    },
    # First EV_KEY to EV_KEY mappings for controller 1
    (0, EV_KEY): {
        BTN_DPAD_UP: {
            'type': (0, EV_KEY),
            'code': 17,
            'value': None
        },
        BTN_DPAD_DOWN: {
            'type': (0, EV_KEY),
            'code': 31,
            'value': None
        },
        BTN_DPAD_LEFT: {
            'type': (0, EV_KEY),
            'code': 30,
            'value': None
        },
        BTN_DPAD_RIGHT: {
            'type': (0, EV_KEY),
            'code': 32,
            'value': None
        },
        BTN_SOUTH: {  # (BTN_A synonym)
            'type': (0, EV_KEY),
            'code': 305,
            'value': None
        },
        BTN_B: {
            'type': (0, EV_KEY),
            'code': 304,
            'value': None
        },
        BTN_START: {
            'type': (0, EV_KEY),
            'code': 313,
            'value': None
        },
        BTN_SELECT: {
            'type': (0, EV_KEY),
            'code': 312,
            'value': None
        },
        BTN_MODE: {
            'type': (0, EV_KEY),
            'code': 311,
            'value': None
        }
    },
    # Second EV_KEY to EV_KEY mappings for controller 1
    (1, EV_KEY): {
        BTN_THUMB: {
            'type': (0, EV_KEY),
            'code': 29,
            'value': None
        },
        BTN_THUMB2: {
            'type': (0, EV_KEY),
            'code': 42,
            'value': None
        },
        BTN_BASE4: {
            'type': (0, EV_KEY),
            'code': 1,
            'value': None
        },
        BTN_BASE3: {
            'type': (0, EV_KEY),
            'code': 59,
            'value': None
        },
        KEY_HOMEPAGE: {
            'type': (0, EV_KEY),
            'code': 310,
            'value': None
        }
    },
    # Maps keyboard player 2 to WASD keys
    (2, EV_KEY): {
        KEY_A: {
            'type': (0, EV_KEY),
            'code': 105,
            'value': None
        },
        KEY_D: {
            'type': (0, EV_KEY),
            'code': 106,
            'value': None
        },
        KEY_W: {
            'type': (0, EV_KEY),
            'code': 103,
            'value': None
        },
        KEY_S: {
            'type': (0, EV_KEY),
            'code': 108,
            'value': None
        },
        KEY_LEFTCTRL: {
            'type': (0, EV_KEY),
            'code': 100,
            'value': None
        },
        KEY_LEFTSHIFT: {
            'type': (0, EV_KEY),
            'code': 57,
            'value': None
        },
        KEY_ESC: {
            'type': (0, EV_KEY),
            'code': 1,
            'value': None
        },
        KEY_F1: {
            'type': (0, EV_KEY),
            'code': 59,
            'value': None
        },
        KEY_F2: {
            'type': (0, EV_KEY),
            'code': 60,
            'value': None
        }
    }
}

However I find that none of the buttons trigger events properly. The directional pad does work properly so it's very close. Am I missing something around remapping the controller or would this simply not work due to some underlying low-level thing with these controllers?

I used the code and resulting .elf file from here to test the buttons:
https://arcade.makecode.com/developer/button-tester
https://arcade.makecode.com/S28558-81115-41523-70869

@x-logan23
Copy link
Contributor

Hi i just figured out how to map correctly my controller and i think i can help you with yours
From the output of the evtest in your previous comment and you said that the directional pad does work properly then we only need to modify one part of the arcade1.py file.

Try to modify the # First EV_KEY to EV_KEY mappings for controller 1 with this fragment

 # First EV_KEY to EV_KEY mappings for controller 1
    (0, EV_KEY): {
        BTN_DPAD_UP: {
            'type': (0, EV_KEY),
            'code': 17,
            'value': None
        },
        BTN_DPAD_DOWN: {
            'type': (0, EV_KEY),
            'code': 31,
            'value': None
        },
        BTN_DPAD_LEFT: {
            'type': (0, EV_KEY),
            'code': 30,
            'value': None
        },
        BTN_DPAD_RIGHT: {
            'type': (0, EV_KEY),
            'code': 32,
            'value': None
        },
        BTN_EAST: {  # (BTN_A synonym)
            'type': (0, EV_KEY),
            'code': 29,
            'value': None
        },
        BTN_SOUTH: {
            'type': (0, EV_KEY),
            'code': 42,
            'value': None
        },
        BTN_TR2: {
            'type': (0, EV_KEY),
            'code': 1,
            'value': None
        },
        BTN_TL2: {
            'type': (0, EV_KEY),
            'code': 59,
            'value': None
        },
        BTN_TL: {
            'type': (0, EV_KEY),
            'code': 60,
            'value': None
        }
    },

With this configuration it should work,

Let me know if it works or we need to try something else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants