Skip to content

Commit

Permalink
feat(rival600): Added button mapping support
Browse files Browse the repository at this point in the history
  • Loading branch information
flozz committed Apr 4, 2024
1 parent 35bdfd9 commit 1c8d0ce
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
27 changes: 27 additions & 0 deletions rivalcfg/devices/rival600.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,33 @@
"led_id": 0x07,
"default": _DEFAULT_RGBGRADIENT,
},
"buttons_mapping": {
"label": "Buttons mapping",
"description": "Set the mapping of the buttons",
"cli": ["-b", "--buttons"],
"report_type": usbhid.HID_REPORT_TYPE_FEATURE,
"command": [0x31, 0x00],
"value_type": "buttons",
# fmt: off
"buttons": {
"Button1": {"id": 0x01, "offset": 0x00, "default": "button1"},
"Button2": {"id": 0x02, "offset": 0x05, "default": "button2"},
"Button3": {"id": 0x03, "offset": 0x0A, "default": "button3"},
"Button4": {"id": 0x04, "offset": 0x0F, "default": "button4"},
"Button5": {"id": 0x05, "offset": 0x14, "default": "button5"},
"Button6": {"id": 0x06, "offset": 0x19, "default": "disabled"},
"Button7": {"id": 0x00, "offset": 0x1E, "default": "dpi"},
},
"button_field_length": 5,
"button_disable": 0x00,
"button_keyboard": 0x51,
"button_multimedia": 0x61,
"button_dpi_switch": 0x30,
"button_scroll_up": 0x31,
"button_scroll_down": 0x32,
# fmt: on
"default": "buttons(button1=button1; button2=button2; button3=button3; button4=button4; button5=button5; button6=disabled; button7=dpi)",
},
},
"save_command": {
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
Expand Down
59 changes: 59 additions & 0 deletions test/devices/test_rival600.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,65 @@ def test_set_z7_color(self, mouse):

assert hid_report == expected_hid_report

@pytest.mark.parametrize(
"value,expected_hid_report",
[
(
"default",
b"\x03\x00"
b"\x31\x00"
b"\x01\x00\x00\x00\x00"
b"\x02\x00\x00\x00\x00"
b"\x03\x00\x00\x00\x00"
b"\x04\x00\x00\x00\x00"
b"\x05\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00"
b"\x30\x00\x00\x00\x00",
),
(
"buttons(button2=button6)",
b"\x03\x00"
b"\x31\x00"
b"\x01\x00\x00\x00\x00"
b"\x06\x00\x00\x00\x00"
b"\x03\x00\x00\x00\x00"
b"\x04\x00\x00\x00\x00"
b"\x05\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00"
b"\x30\x00\x00\x00\x00",
),
(
{"buttons": {"button2": "button6"}},
b"\x03\x00"
b"\x31\x00"
b"\x01\x00\x00\x00\x00"
b"\x06\x00\x00\x00\x00"
b"\x03\x00\x00\x00\x00"
b"\x04\x00\x00\x00\x00"
b"\x05\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00"
b"\x30\x00\x00\x00\x00",
),
(
"buttons(Button1=ScrollDown; Button2=ScrollUp)",
b"\x03\x00"
b"\x31\x00"
b"\x32\x00\x00\x00\x00"
b"\x31\x00\x00\x00\x00"
b"\x03\x00\x00\x00\x00"
b"\x04\x00\x00\x00\x00"
b"\x05\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00"
b"\x30\x00\x00\x00\x00",
),
],
)
def test_set_buttons_mapping(self, mouse, value, expected_hid_report):
mouse.set_buttons_mapping(value)
mouse._hid_device.bytes.seek(0)
hid_report = mouse._hid_device.bytes.read()
assert hid_report == expected_hid_report

def test_save(self, mouse):
mouse.save()
mouse._hid_device.bytes.seek(0)
Expand Down

0 comments on commit 1c8d0ce

Please sign in to comment.