batocera-linux / batocera.linux

batocera.linux
https://batocera.org
Other
2.02k stars 523 forks source link

evmapy.py generates an incomplete mapping file #12927

Open lulol opened 3 days ago

lulol commented 3 days ago

Batocera build version

40 2024/08/03 05:52

Your architecture

-

Your Graphic Processor Unit(s) (GPU)

-

Issue description

Using the PAD TO KEYBOARD CONFIGURATION gui to map pad events to keyboard key presses creates a <rom>.keys with the configured mappings. Then when launching the rom evmapy.py generates an incomplete event.json file for evmapy.

Detailed reproduction steps

Details of any attempts to fix this yourself

Manually editing the corresponding event.json file and adding the missing ABS axis configuration and restarting evmpy with the corrected mapping while the game is still running confirms that the ABS vertical axis mapping works just fine.

Running evmapy in a tty console [Ctrl-Alt-F3] using the fixed mapping file also shows the translated key pressed fine.

The known_axes_codes and copy-paste bugs in v40 are also present in the current master. https://github.com/batocera-linux/batocera.linux/blob/4e5217b6051eccaec8b53af644a901a72081b54e/package/batocera/core/batocera-configgen/configgen/configgen/utils/evmapy.py#L357-L363

Not sure about absbasey_positive but all the 6 game pads and controllers I tested show (up, left).min = 0 and (down, right).max = 255 with the current logic the up/down axis is inverted. https://github.com/batocera-linux/batocera.linux/blob/4e5217b6051eccaec8b53af644a901a72081b54e/package/batocera/core/batocera-configgen/configgen/configgen/utils/evmapy.py#L200

Details of any modifications you have made to Batocera.

Bugfix PR #12928

Logs and data

No response

nadenislamarre commented 3 days ago

i don't reproduce the issue. it is working correctly on my side. it generates the file like this:

    {
        "trigger": "joystick1up",
        "type": "key",
        "target": "KEY_Q"
    },
    {
        "trigger": "joystick1down",
        "type": "key",
        "target": "KEY_A"
    },
    {
        "trigger": "joystick1left",
        "type": "key",
        "target": "KEY_O"
    },
    {
        "trigger": "joystick1right",
        "type": "key",
        "target": "KEY_P"
    },
nadenislamarre commented 3 days ago

can you explain your issue, and give a specific case, and show the file generated so that i undertand the issue. i hardly understand what's wrong on your side because you're describing how to solve, but not what happen, and i can't reproduce on my side. Don't hesitate to come on discord and ask susan34, it will be maybe easier.

lulol commented 3 days ago

Sure, my issue is related to the processing of the ABSBASEY axis only. (But of course also can happen for ABSBASEX).

When the 'up' input.name is processed first this issue won't happen.

When 'down' is processes first then the known_axes_codes[input.code] flag is populated before the Y axis mapping is generated and according to the current code logic when later 'up' arrives any further processing will be skipped and the mapping for the Y axis ignored.

This condition can happen because json.load() objects may not keep the original order.

rom.keys file:

{
    "actions_player1": [
        {
            "trigger": "up",
            "type": "key",
            "target": "KEY_W"
        },
        {
            "trigger": "down",
            "type": "key",
            "target": "KEY_S"
        },
        {
            "trigger": "left",
            "type": "key",
            "target": "KEY_H"
        },
        {
            "trigger": "right",
            "type": "key",
            "target": "KEY_J"
        },
        {
            "trigger": "start",
            "type": "key",
            "target": "KEY_Y"
        },
        {
            "trigger": "a",
            "type": "key",
            "target": "KEY_V"
        },
        {
            "trigger": "b",
            "type": "key",
            "target": "KEY_1"
        },
        {
            "trigger": "x",
            "type": "key",
            "target": "KEY_3"
        },
        {
            "trigger": "y",
            "type": "key",
            "target": "KEY_2"
        },
        {
            "trigger": "pageup",
            "type": "key",
            "target": "KEY_L"
        },
        {
            "trigger": "pagedown",
            "type": "key",
            "target": "KEY_R"
        },
        {
            "trigger": "l2",
            "type": "key",
            "target": "KEY_M"
        },
        {
            "trigger": "r2",
            "type": "key",
            "target": "KEY_G"
        }
    ]
}

generated event.json file:

{
    "axes": [
        {
            "name": "ABSBASEX",
            "code": 0,
            "min": 63.75,
            "max": 191.25
        }
    ],
    "buttons": [
        {
            "name": "a",
            "code": 289
        },
        {
            "name": "b",
            "code": 290
        },
        {
            "name": "hotkey",
            "code": 296
        },
        {
            "name": "l2",
            "code": 294
        },
        {
            "name": "pagedown",
            "code": 293
        },
        {
            "name": "pageup",
            "code": 292
        },
        {
            "name": "r2",
            "code": 295
        },
        {
            "name": "start",
            "code": 297
        },
        {
            "name": "x",
            "code": 288
        },
        {
            "name": "y",
            "code": 291
        }
    ],
    "grab": false,
    "actions": [
        {
            "trigger": "ABSBASEX:min",
            "type": "key",
            "target": "KEY_H"
        },
        {
            "trigger": "ABSBASEX:max",
            "type": "key",
            "target": "KEY_J"
        },
        {
            "trigger": "start",
            "type": "key",
            "target": "KEY_Y"
        },
        {
            "trigger": "a",
            "type": "key",
            "target": "KEY_V"
        },
        {
            "trigger": "b",
            "type": "key",
            "target": "KEY_1"
        },
        {
            "trigger": "x",
            "type": "key",
            "target": "KEY_3"
        },
        {
            "trigger": "y",
            "type": "key",
            "target": "KEY_2"
        },
        {
            "trigger": "pageup",
            "type": "key",
            "target": "KEY_L"
        },
        {
            "trigger": "pagedown",
            "type": "key",
            "target": "KEY_R"
        },
        {
            "trigger": "l2",
            "type": "key",
            "target": "KEY_M"
        },
        {
            "trigger": "r2",
            "type": "key",
            "target": "KEY_G"
        }
    ]
}

This event.json is missing from the axes list:

--- event3.json 2024-11-11 23:43:12.903696886 +0100
+++ event3.json.fix     2024-11-11 23:40:05.516736069 +0100
@@ -5,6 +5,12 @@
             "code": 0,
             "min": 63.75,
             "max": 191.25
+        },
+        {
+            "name": "ABSBASEY",
+            "code": 1,
+            "min": 63.75,
+            "max": 191.25
         }
     ],
     "buttons": [
@@ -52,6 +58,16 @@
     "grab": false,
     "actions": [
         {
+            "trigger": "ABSBASEY:min",
+            "type": "key",
+            "target": "KEY_W"
+        },
+        {
+            "trigger": "ABSBASEY:max",
+            "type": "key",
+            "target": "KEY_S"
+        },
+        {
             "trigger": "ABSBASEX:min",
             "type": "key",
             "target": "KEY_H"

And about the later use of the absbasex_positive and absbasey_positive variables, the mapping assignations for the Y axis are being made checking existence of the X axis found in known_buttons_names, not the corresponding Y axis, probably a copy-paste typo, but I think that this is won't be an issue unless someone has a joystick with only a Y axis and no X axis.

evtest.log evtest.log