range_choice
The “range_choice” type alows to pick a value in an input range and transforms it into a value from a fixed output list. If the input value do not correspond to one of the available output choices, it is rounded to match the nearest DPI.
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->0100->1110->1(110rounded to100)190->2(190rounded to200)200->2300->3…
Device Profile
Example of a range_choice value type in a device profile:
profile = {
# ...
"settings": {
"sensitivity1": {
"label": "Sensitivity preset 1",
"description": "Set sensitivity preset 1 (DPI)",
"cli": ["-s", "--sensitivity1"],
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x03, 0x01],
"value_type": "range_choice",
"input_range": [200, 7200, 100],
"output_choices": {
200: 0x04,
300: 0x06,
400: 0x08,
...
7200: 0xA7,
},
"range_length_byte": 1, # optional, little endian
"default": 1000,
},
},
# ...
}
CLI
Example of CLI option generated with this handler:
-s SENSITIVITY1, --sensitivity1 SENSITIVITY1
Set sensitivity preset 1 (DPI) (from 200 to 7200,
default: 1000)
Example of CLI usage:
rivalcfg --sensitivity1=1000
Functions
- rivalcfg.handlers.range_choice.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
ArgumentParserinstance.setting_name (str) – The name of the setting.
setting_info (dict) – The information dict of the setting from the device profile.
- rivalcfg.handlers.range_choice.find_nearest_choice(choices, value)
Find the nearest value from choice list.
- Parameters:
choices (list[int]) – List of allowed values.
value (int) – the value to match with the ones of choices.
- Return type:
int
- Returns:
The nearest value from choices.
- rivalcfg.handlers.range_choice.process_range_choice(setting_info, value)
Called by the “range_choice” functions to process ‘value’ with the specified range settings in ‘setting_info’.
- Parameters:
setting_info (dict) – The information dict of the setting from the device profile.
value – The input value.
- Return type:
int
- rivalcfg.handlers.range_choice.process_value(setting_info, value)
Called by the
rivalcfg.mouse.Mouseclass when processing a “range” type setting.- Parameters:
setting_info (dict) – The information dict of the setting from the device profile.
value – The input value.
- Return type:
list[int]