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

Mapping issues NVIDIA Controller v01.03 #642

Closed
davyhollevoet opened this issue Mar 18, 2018 · 0 comments
Closed

Mapping issues NVIDIA Controller v01.03 #642

davyhollevoet opened this issue Mar 18, 2018 · 0 comments

Comments

@davyhollevoet
Copy link

I was experiencing some issues while mapping my "NVIDIA Corporation NVIDIA Controller v01.03" gamepad, connected over USB. It seems to me that mapping other controllers might give the same problems, but I can't check that.

With some work and the patches (against d452411) listed below, I did manage to get the following mapping:
03000000550900001072000011010000,NVIDIA Corporation NVIDIA Controller v01.03,a:b0,b:b1,x:b2,y:b3,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a10,righttrigger:a9,platform:Linux

  • Unable to register movement of "Right Stick Up", "Left Trigger" and "Right Trigger". I believe that this is due to the gap in ABS code: ABS_Z is 2 and ABS_RZ is 5, with nothing in between. A few empty slots later, there is ABS_GAS and ABS_BRAKE at 9 and 10. The following patch fixes the confusion between index and value in abs_map.
diff --git a/src/input/evdev.c b/src/input/evdev.c
index 5f78716..fb2903f 100644
--- a/src/input/evdev.c
+++ b/src/input/evdev.c
@@ -403,7 +403,7 @@ static bool evdev_handle_mapping_event(struct input_event *ev, struct input_devi
       } else if (ev->value < parms.avg - parms.range/2) {
         *currentAbs = dev->abs_map[ev->code];
         *currentReverse = true;
-      } else if (ev->code == *currentAbs)
+      } else if (dev->abs_map[ev->code] == *currentAbs)
         return false;
     } else if (currentHat != NULL) {
       if (hat_index >= 0 && hat_index < 4) {
@@ -532,13 +532,12 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose) {
       devices[dev].key_map[i - BTN_MISC] = nbuttons++;
   }
 
-  int naxes = 0;
   for (int i = 0; i < ABS_MAX; ++i) {
     /* Skip hats */
     if (i == ABS_HAT0X)
       i = ABS_HAT3Y;
     else if (libevdev_has_event_code(devices[dev].dev, EV_ABS, i))
-      devices[dev].abs_map[i] = naxes++;
+      devices[dev].abs_map[i] = i;
   }
 
   devices[dev].controllerId = -1;
  • The "D-Pad Up" and "D-Pad Down" were being mapped to dpup:h0.9 and dpdown:h0.12 instead of dpup:h0.1 and dpdown:h0.4. Resetting hats_state after deciding each hat button fixes that:
diff --git a/src/input/evdev.c b/src/input/evdev.c
index e04bf9c..5f78716 100644
--- a/src/input/evdev.c
+++ b/src/input/evdev.c
@@ -409,6 +409,9 @@ static bool evdev_handle_mapping_event(struct input_event *ev, struct input_devi
       if (hat_index >= 0 && hat_index < 4) {
         *currentHat = hat_index;
         *currentHatDir = hat_constants[dev->hats_state[hat_index][1] + 1][dev->hats_state[hat_index][0] + 1];
+        //reset the states for the next hat button
+        dev->hats_state[hat_index][1] = 0;
+        dev->hats_state[hat_index][0] = 0;
         return false;
       }
     }
  • In the final mapping output, the name is blank, which makes the mapping reader skip a:b0 (strtok does that for empty fields). The cause of the blank name is an off-by-one(?) overflow due to the wrong size for strncpy.
diff --git a/src/input/evdev.c b/src/input/evdev.c
index fb2903f..e29c958 100644
--- a/src/input/evdev.c
+++ b/src/input/evdev.c
@@ -636,7 +636,7 @@ void evdev_map(char* device) {
   
   struct mapping map;
   strncpy(map.name, libevdev_get_name(evdev), sizeof(map.name));
-  strncpy(map.guid, str_guid, sizeof(map.name));
+  strncpy(map.guid, str_guid, sizeof(map.guid));
 
   libevdev_free(evdev);
   close(fd);

One remaining issue is that, to map "Left Trigger" and "Right Trigger", one should only tap the triggers only very shortly: the detection code does not take into account that the value starts at 0 instead of halfway.

Finally, more as FYI, the "Back" and "Home" buttons on the gamepad don't do anything during the mapping because their codes (KEY_BACK, KEY_HOMEPAGE) are not within the correct ranges. Since I wanted to get the same behavior as with the Nvidia GameStream app, I used the patch below. This prolly interferes with keyboard input, but is good enough for me personally.

diff --git a/src/input/evdev.c b/src/input/evdev.c
index 7fc1181..e04bf9c 100644
--- a/src/input/evdev.c
+++ b/src/input/evdev.c
@@ -244,6 +244,14 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev)
       case BTN_RIGHT:
         mouseCode = BUTTON_RIGHT;
         break;
+      case KEY_BACK:
+        gamepadModified = true;
+        gamepadCode = BACK_FLAG;
+        break;
+      case KEY_HOMEPAGE:
+        gamepadModified = true;
+        gamepadCode = SPECIAL_FLAG;
+        break;
       default:
         gamepadModified = true;
         if (dev->map == NULL)
@cgutman cgutman closed this as completed in 4b41692 Aug 8, 2021
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

1 participant