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

[GamePi20 controller] Need help configuring buttons(possibly working) #5

Closed
Kay-Wolfe opened this issue Jan 13, 2021 · 15 comments
Closed
Labels
bug Something isn't working Controller Controller related issue documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed

Comments

@Kay-Wolfe
Copy link

I have GamePi20 kit and retropie and McAirpos is running perfectly on that. I only have trouble configuring the buttons for it. On my /opt/retropie/configs/all/retroarch-joypads/GPIO Controller 1.cfg:

input_device = "GPIO Controller 1"
input_driver = "udev"
input_l_btn = "3"
input_load_state_btn = "3"
input_start_axis = "+1"
input_exit_emulator_axis = "+1"
input_down_btn = "11"
input_r_btn = "6"
input_save_state_btn = "6"
input_right_axis = "+0"
input_state_slot_increase_axis = "+0"
input_select_axis = "-1"
input_left_btn = "10"
input_state_slot_decrease_btn = "10"
input_up_axis = "-0"
input_a_btn = "7"
input_b_btn = "1"
input_reset_btn = "1"
input_enable_hotkey_axis = "-1"
input_x_btn = "4"
input_menu_toggle_btn = "4"
input_y_btn = "0"

how do I translate this into McAirpos? i've tried changing arcade.dfg.controller.

ps: my son made this to help me out https://makecode.com/_00RXmREYfK9q

@Vegz78
Copy link
Owner

Vegz78 commented Jan 13, 2021

Hi @Kay-Wolfe,

With reference to issue #3, I was sadly a little naive when I just before Christmas wanted to share working code based on my PS3 Controllers, which were the only controllers I had at hand at that moment. I turns out that the PS3 controller's RAW "DPAD" key events were not at all so universally used on other gamepads as I thought. Having ordered and just received a couple of new controllers, I'm currently working on some thoughts on a solution that supports more controllers out of the box AND let's the users configure it more freely(which at the moment unfortunately is hardcoded together with the autodetection of (PS3)controllers and blocks the edits of the arcade.py mapping files).

Thank you very much for your input above, and what would be very helpful for my soon to come fix is if you could please provide me with the RAW event info which both the game elf files and McAirpos launcher and ui-mapper uses for controllers?:

  1. The /dev/input/eventX number for your controller if it exists(Either install and run evtest or run more /proc/bus/input/devices
  2. A copy of your controller's RAW event key layout(/home/pi/McAirpos/McAirpos/uinput-mapper/input-read -v -p /dev/input/eventX)

This would be of great help to me for making a fix(and amends for, in retrospect, a little premature advertising...) sooner.

Hope to hear back from you again soon with the requested information.

Br,
Vegard

PS: The more such copies of such key layouts as in point 2 above I get, for as many different controllers as possible, the more generic patterns and solutions I expect to find. If others could contribute, too, I would really appreciate it. ;-)

@Kay-Wolfe
Copy link
Author

Kay-Wolfe commented Jan 13, 2021

Hey there,

Here's the info you've requested

  1. more /proc/bus/input/devices
I: Bus=0015 Vendor=0001 Product=0005 Version=0100
N: Name="GPIO Controller 1"
P: Phys=input0
S: Sysfs=/devices/virtual/input/input2
U: Uniq=
H: Handlers=js0 event2 
B: PROP=0
B: EV=b
B: KEY=fff0000 0 0 0 0 0 0 0 0 0
B: ABS=3
  1. /home/pi/McAirpos/McAirpos/uinput-mapper/input-read -v -p /dev/input/event2
pi@retropie:/etc/udev/rules.d $ /home/pi/McAirpos/McAirpos/uinput-mapper/input-read -v -p /dev/input/event2
Input: 0 Type: EV_KEY
     BTN_SOUTH  → ([0, EV_KEY], BTN_SOUTH)
     BTN_B  → ([0, EV_KEY], BTN_B)
     BTN_C  → ([0, EV_KEY], BTN_C)
     BTN_X  → ([0, EV_KEY], BTN_X)
     BTN_Y  → ([0, EV_KEY], BTN_Y)
     BTN_Z  → ([0, EV_KEY], BTN_Z)
     BTN_TL  → ([0, EV_KEY], BTN_TL)
     BTN_TR  → ([0, EV_KEY], BTN_TR)
     BTN_TL2  → ([0, EV_KEY], BTN_TL2)
     BTN_TR2  → ([0, EV_KEY], BTN_TR2)
     BTN_SELECT  → ([0, EV_KEY], BTN_SELECT)
     BTN_START  → ([0, EV_KEY], BTN_START)
Input: 0 Type: EV_ABS
     ABS_X  → ([0, EV_ABS], ABS_X)
Properties: Max: 1 Min: -1 Fuzz: 0 Flat: 0
     ABS_Y  → ([0, EV_ABS], ABS_Y)
Properties: Max: 1 Min: -1 Fuzz: 0 Flat: 0

Additional info:
The hat uses https://github.com/waveshare/mk_arcade_joystick_rpi joystick driver. With the config for Gamepi20 (/etc/modprobe.d/joystick.conf):

options mk_arcade_joystick_rpi map=5 gpio=16,26,12,13,20,21,17,4,23,22,5,6

Running their test tool jstest /dev/input/js0

pi@retropie:/etc/modprobe.d $ jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (GPIO Controller 1) has 2 axes (X, Y)
and 12 buttons (BtnA, BtnB, BtnC, BtnX, BtnY, BtnZ, BtnTL, BtnTR, BtnTL2, BtnTR2, BtnSelect, BtnStart).
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0 Buttons:  0:off  1:off  2:off  3:off  4:off  5:off  6:off  7:off  8:off  9:off 10:off 11:off 

@Vegz78
Copy link
Owner

Vegz78 commented Jan 13, 2021

Thank you very much, @Kay-Wolfe!!!

@Kay-Wolfe
Copy link
Author

Hey there,

I'm not familiar with C (webdev here). But digging around I see this code

   if (numberOfPads == 0) {
      strcat(defaultEvent, tempString);
      defaultEvent[strlen(defaultEvent)-1] = 0;
   }
   snprintf(sedCommand, 100, "sed -i \"1s&.*&\"%s\"&\" /sd/arcade.cfg", defaultEvent);

It seems like your code forced to change the /sd/arcade.cfg to 0, when no gamepad is detected. GPIO based like mine slips the check.
(p/s I think the strlen -1 thing is a bug waiting to happen with > 9 item).

So what I did for now is:

  • comment out the snprintf line above to use event2
  • remap the whole gpio config so axis x & y is on buttons unused by arcade (L1, R1, X, Y)
    options mk_arcade_joystick_rpi map=5 gpio=17,22,5,6,26,16,21,13,4,20,12,23 (if anyone using this device is googling)
  • remap the whole retropie
  • reconfigure /sd/arcade.cfg with new button layout
  • lose player 2, but its not relevant on this device

@Vegz78
Copy link
Owner

Vegz78 commented Jan 15, 2021

Great work, @Kay-Wolfe!

You are right about a number of things here.

  • It defaults to keyboard if no gamepad is found. For keeping 2 player option, I would suggest instead to change the line ...grep...’DPAD’... to e.g. BTN_START which increases the number of controllers detected, should also discover yours(I have already done this at home and can commit for you to test).
  • uinput-mapper seems to handle every possible remapping option except EV_ABS(axis) to EV_KEY(button or key). This is where I am stuck at the moment, trying to split e.g. ABS_X into two different buttons(left for negative axis values and right for positive) but the «code» field in the config files seems hardcoded to one integer constant, wheras e.g. the «value» field can. take functions and variables, giving full freedom. Most controllers except PS3 dpad seem to use EV_ABS for directional movements, and cannot be hardwired to other EV_KEY buttons, like you have done.

But your workaround here should do the trick for now, and I will include it right away, so that we at least have increased working gamepad support from only PS3 controllers(and clones) to all rewireable arcade gamepads as well.

Could you please upload your arcade1.py config file here, which I hope to include in the repo?

My hope is to collect and make different config files for different gamepad types, which then easily can be customized and copied over the arcadeX.py files by the users.

Thanks for your help and what do you think?

@Vegz78
Copy link
Owner

Vegz78 commented Jan 15, 2021

UPDATE:
Had a eureka moment here just now, when I discovered a way to solve the uinput-mapping from EV_ABS to EV_KEY in both directions, by reading the same eventX input twice and mapping negative and postive axis values seperately to different keys on the same output device.

Hopefully it will work also for your controller, without the need to rewire physically and remap buttons in RetroPie, when I just figure how to implement this with the least amount of possible mess.

@Kay-Wolfe
Copy link
Author

yep EV_ABS to EV_KEY seems to be a pain. Which is why I abandoned uinput-mapper.

For future referrence:

Users of :

My driver config (/etc/modprobe.d/joystick.conf):

options mk_arcade_joystick_rpi map=5 gpio=17,22,5,6,26,16,21,13,4,20,12,23

which will map X and Y axis away from any buttons for arcade (to R1, L1, X and Y)

SCAN_CODES=/dev/input/event0
BTN_LEFT=304
BTN_RIGHT=305
BTN_UP=307
BTN_DOWN=308
BTN_A=311
BTN_B=310
BTN_RESET=0
BTN_EXIT=314
BTN_MENU=315
BTN_RESET=0

note: I removed my debugging keyboard so it's event0 now.

During my struggle I found:

BTN_A=12,16
BTN_B=6,13
BTN_MENU=20
BTN_EXIT=22,23
BTN_RESET=26
JOYSTICK_ADDR=0x48

I'm not sure whether that works with elf's arcade.cfg.

My opinion:
Maybe set an arg in the launcher to skip the input remapping for the tinkerers. Thanks for your hard work 😊

@Vegz78
Copy link
Owner

Vegz78 commented Jan 15, 2021

My opinion:
Maybe set an arg in the launcher to skip the input remapping for the tinkerers. Thanks for your hard work

Thanks for all your help and tips, @Kay-Wolfe!

I've added the "nomap" argument you requested, so that you can skip auto-detection and -setup of controllers and manually use /sd/arcade.cfg directly with the elf game files instead.

I have also expanded and tested successfully autoconf and EV_ABS to EV_KEY mapping with uinput-mapper on a range of new controllers, which I would really appreciate if you also could test and confirm if it works with your GamePi20 controller(I hope) without the rewirings and remappings you were forced to do earlier.

I will then close this issue in a few days, if there are no unresolved related things pending.

@Vegz78 Vegz78 added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed labels Jan 16, 2021
@Vegz78 Vegz78 changed the title Need help configuring buttons (GamePi20 controller)Need help configuring buttons Jan 16, 2021
@lars-derichter
Copy link

lars-derichter commented Jan 17, 2021

I think I have a similar problem, with EG Start Arcade setup

@Vegz78
Copy link
Owner

Vegz78 commented Jan 17, 2021

I think I have a similar problem, with EG Start Arcade setup

Hi @lars-derichter,
I have replied and moved your post to a new issue

@Kay-Wolfe
Copy link
Author

I think we're overcomplicating the joypad situation.

A uinput-remapper replacement (or launcharc itself) that would:

  1. Parse all cfg in /opt/retropie/configs/all/retroarch-joypads/
  2. Look for settings we ask user to add during install like arc_player = 1 and arc_device = 0 (jsid)
  3. Map/simulate keyboard presses based on those.

Which will probably covers most use case, with minor config change (jsid and player num above)

@Vegz78
Copy link
Owner

Vegz78 commented Jan 18, 2021

I think we're overcomplicating the joypad situation.

You're probably right... Did you ever, with the new nomap option, figure out how to set up a joystick directly in "one of the arcade.cfg included (the bonnet one) that you found?

I'm thinking about simplifying the uinput mapping for a 2nd/2 player controller to a fixed main 1 player controller in /sd/arcade.cfg, now that it is possible to auto-map without keyboard connected. There is some occasional instability, which might be caused by certain keyboard key combinations and/or heavy arcadeX.py mapping functions.

A uinput-remapper replacement (or launcharc itself) that would:

  1. Parse all cfg in /opt/retropie/configs/all/retroarch-joypads/
  2. Look for settings we ask user to add during install like arc_player = 1 and arc_device = 0 (jsid)
  3. Map/simulate keyboard presses based on those.

Which will probably covers most use case, with minor config change (jsid and player num above)

Great inputs, and I agree that there are still room for improvements and simplifications, and hopefully reuse of some existing solutions. I've been under the impression that the MakeCode Arcade elf game files have been locked to digital EV_KEY buttons, but if the bonnet arcade.cfg works, and works with EV_ABS, a lot would be much easier.

With the most recent reorganizations of the launCharc code, the uinput-mapper part is more or less a self contained module, which quite easily and with another option argument can be supplemented with with your parser idea here, or maybe one of the mappers you mentioned in your earlier comments.

At the moment, though, I need a small brake before I can start with bigger new ideas, and I would like to see if the increased flexibility with the namap option solves some use cases, and whether I can(or definitely can not) get adequate controller support, stability and customizability through the existing uinput-mapper route.

But, if you have a working prototype for your idea(s), I would gladly have a look at it/accept a pull-request to incorporate it as an additional/optional module.

Thanks for your support and thorough efforts!!!

@Vegz78
Copy link
Owner

Vegz78 commented Jan 24, 2021

Hi @Kay-Wolfe,

Did you get your GamePi20 controller to work?

@Vegz78
Copy link
Owner

Vegz78 commented Jan 28, 2021

Closed due to missing response from @Kay-Wolfe. Unconfirmed whether the GamePi20 controller works or not.

Please update if you have new info regarding the GamePi20.

@Vegz78 Vegz78 closed this as completed Jan 28, 2021
@Vegz78 Vegz78 changed the title (GamePi20 controller)Need help configuring buttons (GamePi20 controller)Need help configuring buttons(unconfirmed) Jan 28, 2021
@Vegz78
Copy link
Owner

Vegz78 commented Jul 14, 2021

Hi @Kay-Wolfe,

It seems, with similar suggestions by the Waveshare Service Team, that your described attempt here with only using /sd/arcade.cfg, the nomap option and remapping the GamePi20 driver GPIO button sequence itself should be working:
#5 (comment)

However, there was a new attempt with the GamePi20, which has been confirmed to work with a special uinput-mapper arcade1.py configuration file, here:
#18

@Vegz78 Vegz78 reopened this Jul 14, 2021
@Vegz78 Vegz78 closed this as completed Jul 22, 2021
@Vegz78 Vegz78 changed the title (GamePi20 controller)Need help configuring buttons(unconfirmed) (GamePi20 controller)Need help configuring buttons(possibly working) Jul 29, 2021
@Vegz78 Vegz78 changed the title (GamePi20 controller)Need help configuring buttons(possibly working) [GamePi20 controller] Need help configuring buttons(possibly working) Sep 2, 2021
@Vegz78 Vegz78 added the Controller Controller related issue label Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Controller Controller related issue documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants