diff --git a/data/devices/device.example b/data/devices/device.example index 83973489..87f39922 100644 --- a/data/devices/device.example +++ b/data/devices/device.example @@ -77,7 +77,10 @@ DpiRange=100:16000@100 # Device quirks # Quirk=DOUBLE_DPI;STRIX_PROFILE -[Driver/sinowealth/devices/ADeviceNameWithoutSpaces] +# Replace `FEED` in the group name with firmware version of the device. +# To find the right value, see the output of ratbagd and search a message like: +# "ratbag error: Device with firmware version FEED is not supported" +[Driver/sinowealth/devices/FEED] # Number of buttons. # Default to 0. Buttons=6 @@ -85,13 +88,6 @@ Buttons=6 # Device name DeviceName=CoolVendor CoolMouse -# Firmware version of the device. -# This field is used for determining the mouse in the list. -# If not specified, the entry will be ignored. -# To find the right value, see the output of ratbagd and search a message like: -# "ratbag error: Device with firmware version XXX is not supported" -FwVersion=FEED - # The order of LED pins on the mouse. # Change this to `RBG` if LED colors are weird. # Use `None` if there are no LEDs on the mouse. diff --git a/data/devices/glorious-model-d.device b/data/devices/glorious-model-d.device index 8d316b94..3a5a7ab4 100644 --- a/data/devices/glorious-model-d.device +++ b/data/devices/glorious-model-d.device @@ -4,9 +4,8 @@ DeviceMatch=usb:258a:0033 DeviceType=mouse Driver=sinowealth -[Driver/sinowealth/devices/GloriousModelD] +[Driver/sinowealth/devices/V102] Buttons=6 DeviceName=Glorious Model D -FwVersion=V102 LedType=RBG SensorType=PMW3360 diff --git a/data/devices/glorious-model-o.device b/data/devices/glorious-model-o.device index 160cff70..ccbb8d8d 100644 --- a/data/devices/glorious-model-o.device +++ b/data/devices/glorious-model-o.device @@ -4,9 +4,8 @@ DeviceMatch=usb:258a:0036 DeviceType=mouse Driver=sinowealth -[Driver/sinowealth/devices/GloriousModelO] +[Driver/sinowealth/devices/V103] Buttons=6 DeviceName=Glorious Model O/O- (updated firmware) -FwVersion=V103 LedType=RBG SensorType=PMW3360 diff --git a/data/devices/sinowealth-0027.device b/data/devices/sinowealth-0027.device index afe6ba55..4a5c50db 100644 --- a/data/devices/sinowealth-0027.device +++ b/data/devices/sinowealth-0027.device @@ -4,36 +4,32 @@ DeviceType=mouse Driver=sinowealth Name=SinoWealth Generic Mouse (0027) -[Driver/sinowealth/devices/DreamMachinesDM5Blink] +[Driver/sinowealth/devices/3106] Buttons=8 DeviceName=DreamMachines DM5 Blink -FwVersion=3106 LedType=RGB SensorType=PMW3389 -[Driver/sinowealth/devices/GWolvesHatiHTM] +[Driver/sinowealth/devices/V161] Buttons=6 # Can be both `Ace` and `Classic` version. DeviceName=G-Wolves Hati HT-M Wired -FwVersion=V161 LedType=None # Can also be PMW3389 SensorType=PMW3360 -[Driver/sinowealth/devices/GenesysXenon770] +[Driver/sinowealth/devices/3110] # There are 5 main buttons. # Side buttons are detachable. # There can be either 3 or 9 buttons on the side. # Going for the maximum count: 5 + 9 = 14. Buttons=14 DeviceName=Genesys Xenon 770 -FwVersion=3110 LedType=RGB SensorType=PMW3327 -[Driver/sinowealth/devices/GloriousModelOOld] +[Driver/sinowealth/devices/V102] Buttons=6 DeviceName=Glorious Model O (old firmware) -FwVersion=V102 LedType=RBG SensorType=PMW3360 diff --git a/data/devices/sinowealth-0029.device b/data/devices/sinowealth-0029.device index 05f76be0..dae0f961 100644 --- a/data/devices/sinowealth-0029.device +++ b/data/devices/sinowealth-0029.device @@ -6,9 +6,8 @@ Name=SinoWealth Generic Mouse (0029) # Configuration data size: 131 bytes. # https://github.com/libratbag/libratbag/issues/1361 -[Driver/sinowealth/devices/MachenikeM620] +[Driver/sinowealth/devices/V127] Buttons=6 DeviceName=Machenike M620 -FwVersion=V127 LedType=RGB SensorType=PMW3389 diff --git a/data/devices/sinowealth-0051.device b/data/devices/sinowealth-0051.device index a07c9926..4051ab03 100644 --- a/data/devices/sinowealth-0051.device +++ b/data/devices/sinowealth-0051.device @@ -6,10 +6,9 @@ Name=Sinowealth Generic Mouse (0051) # Configuration data size: 123 bytes. # https://github.com/libratbag/libratbag/issues/1444. -[Driver/sinowealth/devices/TDaggerImperialTTGM310] +[Driver/sinowealth/devices/2642] Buttons=8 DeviceName=T-Dagger Imperial T-TGM310 -FwVersion=2642 LedType=RGB Profiles=2 SensorType=PMW3212 diff --git a/data/devices/sinowealth-1007.device b/data/devices/sinowealth-1007.device index f0dffa82..4ceb0fc7 100644 --- a/data/devices/sinowealth-1007.device +++ b/data/devices/sinowealth-1007.device @@ -6,18 +6,16 @@ Name=SinoWealth Generic Mouse (1007) # This does NOT work. See libratbag/libratbag#1296. # For future: ID of A3050 sensor is 0x2, and maximum DPI is 4000. -#[Driver/sinowealth/devices/AntEsportsGM500] +#[Driver/sinowealth/devices/0910] #Buttons=7 #DeviceName=Ant Esports GM500 -#FwVersion=0910 #LedType=RBG #SensorType=A3050 # Configuration size: 123 bytes. # https://github.com/libratbag/libratbag/issues/1091 -[Driver/sinowealth/devices/MarvoScorpionG961] +[Driver/sinowealth/devices/9677] Buttons=6 DeviceName=Marvo Scorpion G961 -FwVersion=9677 LedType=RGB SensorType=PMW3327 diff --git a/src/driver-sinowealth.c b/src/driver-sinowealth.c index 89837c40..5cb0417f 100644 --- a/src/driver-sinowealth.c +++ b/src/driver-sinowealth.c @@ -117,8 +117,6 @@ _Static_assert(SINOWEALTH_NUM_PROFILES_MAX <= 3, "Too many profiles enabled"); /* Maximum amount of real events in a macro. */ #define SINOWEALTH_MACRO_LENGTH_MAX 168 -#define SINOWEALTH_FW_VERSION_LEN 4 - static const unsigned int SINOWEALTH_DEBOUNCE_TIMES[] = { 4, 6, 8, 10, 12, 14, 16 }; diff --git a/src/driver-sinowealth.h b/src/driver-sinowealth.h index 310f4e9f..018bfa9d 100644 --- a/src/driver-sinowealth.h +++ b/src/driver-sinowealth.h @@ -25,6 +25,8 @@ #include "libratbag-util.h" +#define SINOWEALTH_FW_VERSION_LEN 4 + enum sinowealth_led_format { SINOWEALTH_LED_TYPE_NONE, SINOWEALTH_LED_TYPE_RBG, diff --git a/src/libratbag-data.c b/src/libratbag-data.c index 55555910..7a302eba 100644 --- a/src/libratbag-data.c +++ b/src/libratbag-data.c @@ -243,11 +243,21 @@ init_data_sinowealth(struct ratbag *ratbag, for (size_t i = 0; i < group_count; ++i) { const char *device_group = groups[i]; - if (startswith(device_group, devices_group) == NULL) + const char* fw_version = startswith(device_group, devices_group); + if (fw_version == NULL) continue; + rc = (int)strlen(fw_version); + if (rc != SINOWEALTH_FW_VERSION_LEN) { + log_error(ratbag, + "Group '%s': incorrect firmware version string length `%d` (must be `%d`)\n", + device_group, rc, SINOWEALTH_FW_VERSION_LEN); + continue; + } struct sinowealth_device_data *device = zalloc(sizeof(struct sinowealth_device_data)); + device->fw_version = strdup_safe(fw_version); + rc = g_key_file_get_integer(keyfile, device_group, "Buttons", &error); if (rc != 0 && !error) { device->button_count = rc; @@ -259,9 +269,6 @@ init_data_sinowealth(struct ratbag *ratbag, device->device_name = g_key_file_get_string(keyfile, device_group, "DeviceName", &error); g_clear_error(&error); - device->fw_version = g_key_file_get_string(keyfile, device_group, "FwVersion", &error); - g_clear_error(&error); - _cleanup_free_ char *led_type_str = g_key_file_get_string(keyfile, device_group, "LedType", &error); if (led_type_str) { if (streq(led_type_str, "RGB")) { diff --git a/test/data-parse-test.py b/test/data-parse-test.py index b4b2ec04..1c081801 100755 --- a/test/data-parse-test.py +++ b/test/data-parse-test.py @@ -275,10 +275,10 @@ def validate_data_file_name(path: str): ) +SINOWEALTH_FW_VERSION_LEN = 4 SINOWEALTH_DEVICE_SECTION_PREFIX = "Driver/sinowealth/devices/" SINOWEALTH_REQUIRED_KEYS = ( "DeviceName", - "FwVersion", "LedType", ) SINOWEALTH_PERMITTED_KEYS = ( @@ -310,6 +310,8 @@ def parse_data_file(path: str): for device_section_name in data.sections(): if not device_section_name.startswith(SINOWEALTH_DEVICE_SECTION_PREFIX): continue + fw_version = device_section_name[len(SINOWEALTH_DEVICE_SECTION_PREFIX) :] + assert len(fw_version) == SINOWEALTH_FW_VERSION_LEN device_section = data[device_section_name] for key in SINOWEALTH_REQUIRED_KEYS: