浏览代码

Improve sensor detection for Linux gamepad v2

Detecting by name such as "Accelerometer and "Motion Sensor" may be too broad.
Sensors on Dualshock and Switch gamepad are correctly detected by SDL_EVDEV_GuessDeviceClass(). 
Use vendor and product ID for Wii extension controls.
Mathieu Eyraud 2 年之前
父节点
当前提交
bcf239e413
共有 1 个文件被更改,包括 2 次插入27 次删除
  1. 2 27
      src/joystick/linux/SDL_sysjoystick.c

+ 2 - 27
src/joystick/linux/SDL_sysjoystick.c

@@ -46,6 +46,7 @@
 #include "../../core/linux/SDL_evdev.h"
 #include "../SDL_sysjoystick.h"
 #include "../SDL_joystick_c.h"
+#include "../usb_ids.h"
 #include "../steam/SDL_steamcontroller.h"
 #include "SDL_sysjoystick_c.h"
 #include "../hidapi/SDL_hidapijoystick_c.h"
@@ -317,43 +318,17 @@ static int IsJoystick(const char *path, int fd, char **name_return, SDL_Joystick
 static int IsSensor(const char *path, int fd)
 {
     struct input_id inpid;
-    char *name;
-    char product_string[128];
 
     if (ioctl(fd, EVIOCGID, &inpid) < 0) {
         return 0;
     }
 
-    if (ioctl(fd, EVIOCGNAME(sizeof(product_string)), product_string) < 0) {
-        return 0;
-    }
-
-    name = SDL_CreateJoystickName(inpid.vendor, inpid.product, NULL, product_string);
-    if (name == NULL) {
-        return 0;
-    }
-
-    if (SDL_endswith(name, " Motion Sensors")) {
-        /* PS3 and PS4 motion controls */
-        SDL_free(name);
-        return 1;
-    }
-    if (SDL_strncmp(name, "Nintendo ", 9) == 0 && SDL_strstr(name, " IMU") != NULL) {
-        /* Nintendo Switch Joy-Con and Pro Controller IMU */
-        SDL_free(name);
-        return 1;
-    }
-    if (SDL_endswith(name, " Accelerometer") ||
-        SDL_endswith(name, " IR") ||
-        SDL_endswith(name, " Motion Plus") ||
-        SDL_endswith(name, " Nunchuk")) {
+    if (inpid.vendor == USB_VENDOR_NINTENDO && inpid.product == USB_PRODUCT_NINTENDO_WII_REMOTE) {
         /* Wii extension controls */
         /* These may create 3 sensor devices but we only support reading from 1: ignore them */
-        SDL_free(name);
         return 0;
     }
 
-    SDL_free(name);
     return GuessIsSensor(fd);
 }