multidpi_range_choice_xy

The “multidpi_range_choice_xy” type alows to pick values in an input range and transforms it into values from a fixed output list. If the input values do not correspond to one of the available output choices, they are rounded to match the nearest DPI.

Unlike the “multidpi_range_choice” handler, “multidpi_range_choice_xy” allows to set a different DPI on X and Y axis.

This type is used to support devices where we can configure from 1 to n DPI settings in a single command, like the Rival 3 Gen 2.

For example with an input range like [0, 1000, 100] and an output range like {0: 0, 100: 1, 200: 2, 300: 4,...}, you can have the following pair:

  • 0 -> 0

  • 100 -> 1

  • 110 -> 1 (1100 rounded to 100)

  • 190 -> 2 (1900 rounded to 200)

  • 200 -> 2

  • 300 -> 4

Device Profile

Example of a multidpi_range_choice value type in a device profile:

profile = {

    # ...

    "settings": {

        "sensitivity1": {
            "label": "Sensitivity presets",
            "description": "Set sensitivity presets (DPI)",
            "cli": ["-s", "--sensitivity"],
            "report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
            "command": [0x0B, 0x00],
            "value_type": "multidpi_range_choice_xy",
            "input_range": [100, 18000, 100],
            "output_choices": {
                100: 0x00,
                200: 0x02,
                300: 0x03,
                400: 0x04,
                ...
                18000: 0xD6,
            },
            "xy_mapping": "xyxy",     # "xyxy" or "xxyy"
            "dpi_length_byte": 1,  # Little endian
            "first_preset": 1,
            "max_preset_count": 5,
            "default": "800:800, 1600:1600",
        },

    },

    # ...

}

CLI

Example of CLI option generated with this handler:

-s SENSITIVITY, --sensitivity SENSITIVITY
                     Set sensitivity preset (DPI) (up to 5 settings, from 200 dpi to 8500
                     dpi, default (x1:y1,x2:y2): '800:800, 1600:1600')

Example of CLI usage:

rivalcfg --sensitivity 1600                         # 1 preset;  x1=1600dpi:y1=1600dpi
rivalcfg --sensitivity 1600:1600                    # 1 preset;  x1=1600dpi:y1=1600dpi
rivalcfg --sensitivity "800,1600"                   # 2 presets; x1=800dpi:y1=800dpi, x2=1600dpi:y2=1600dpi
rivalcfg --sensitivity "800:1000, 1600:2000"        # 2 presets; x1=800dpi:y1=1000dpi, x2=1600dpi:y2=2000dpi
rivalcfg --sensitivity "200, 400, 800, 1600, 8000"  # 5 presets; ...

Functions

rivalcfg.handlers.multidpi_range_choice_xy.add_cli_option(cli_parser, setting_name, setting_info)

Add the given “range” type setting to the given CLI arguments parser.

Parameters:
  • cli_parser (ArgumentParser) – An ArgumentParser instance.

  • setting_name (str) – The name of the setting.

  • setting_info (dict) – The information dict of the setting from the device profile.

rivalcfg.handlers.multidpi_range_choice_xy.normalize_value(value)

Normalize input value to the following format:

[[x1: int, y1: int], [x2: int, y2: int], ...]
>>> normalize_value(100)
[[100, 100]]
>>> normalize_value([100, 200])
[[100, 100], [200, 200]]
>>> normalize_value([[100]])
[[100, 100]]
>>> normalize_value([[100, 150], [200, 250]])
[[100, 150], [200, 250]]
>>> normalize_value([[100, 150], 200])
[[100, 150], [200, 200]]
>>> normalize_value("100")
[[100, 100]]
>>> normalize_value("100:100")
[[100, 100]]
>>> normalize_value("100,200")
[[100, 100], [200, 200]]
>>> normalize_value(" 100:150, 200: 250 ")
[[100, 150], [200, 250]]
>>> normalize_value("100:150, 200")
[[100, 150], [200, 200]]
rivalcfg.handlers.multidpi_range_choice_xy.process_value(setting_info, value, selected_preset=None)

Called by the rivalcfg.mouse.Mouse class when processing a “multidpi_range_choice” type setting.

Parameters:
  • setting_info (dict) – The information dict of the setting from the device profile.

  • value – The input value.

  • selected_preset (int) – The DPI preset to select (0 is always the first preset).

Return type:

list[int]