Skip to content

Commit

Permalink
Merge branch 'device-prime-mini' (closes #227)
Browse files Browse the repository at this point in the history
  • Loading branch information
flozz committed Jan 13, 2024
2 parents bd38e53 + 9a06ab2 commit 08f3f93
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Supported Devices
+------------------------------------------------------------------------+-----------+
| SteelSeries Prime CS:GO Neo Noir Edition | 1038:1856 |
+------------------------------------------------------------------------+-----------+
| **SteelSeries Prime Mini** |
+------------------------------------------------------------------------+-----------+
| SteelSeries Prime Mini | 1038:184d |
+------------------------------------------------------------------------+-----------+
| **SteelSeries Prime Wireless** |
+------------------------------------------------------------------------+-----------+
| SteelSeries Prime Wireless (wired mode) | 1038:1842 |
Expand Down Expand Up @@ -240,6 +244,7 @@ Changelog

* **[NEXT]** (changes on ``master`` that have not been released yet):

* feat: Added Prime Mini support (@flozz, @NextWork123, #227)
* chore: Added Python 3.12 support
* chore!: Dropped Python 3.7 support

Expand Down
1 change: 1 addition & 0 deletions doc/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Supported Devices
./kanav2.rst
./kinzuv2.rst
./prime.rst
./prime_mini.rst
./prime_wireless.rst
./rival3.rst
./rival3_wireless.rst
Expand Down
81 changes: 81 additions & 0 deletions doc/devices/prime_mini.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
SteelSeries Prime Mini
======================


.. NOTE::

* For Prime Mini Wireless, see :doc:`./prime_wireless`.


Supported Models
----------------

.. rivalcfg_device_family:: prime_mini


Command-Line Usage
------------------

.. rivalcfg_device_cli:: prime_mini


Sensitivity (DPI)
-----------------

This mouse supports up to 5 sensitivity presets. You can define them like this:

::

rivalcfg --sensitivity 800 # one preset
rivalcfg --sensitivity 800,1600 # two presets

You can switch preset using the button under the mouse wheel.

.. NOTE::

When you set the sensitivity through the CLI, the selected preset always
back to the first one.


.. NOTE:: From Python API, you can pass an ``int``, a ``tuple`` or a ``list``
as parameter. You are also able to change the currently selected preset::

mouse.sensitivity(800)
mouse.sensitivity("800, 1600")
mouse.sensitivity([800, 1600])
# select the second preset (1600 dpi)
mouse.sensitivity([800, 1600, 2000, 4000], selected_preset=2)


Colors
------

This mouse supports colors. Various formats are supported.

.. include:: ./_colors.rst

.. IMPORTANT::

On newer SteelSeries mice, the color settings are not saved in the onboard
memory anymore (see Default Lighting bellow).


Default Lighting
----------------

.. include:: ./_default_lighting.rst


Buttons
-------

.. figure:: ./images/prime_buttons.svg
:alt: Prime buttons schema

.. include:: ./_buttons.rst


Python API
----------

TODO
4 changes: 4 additions & 0 deletions doc/devices/prime_wireless.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
SteelSeries Prime Wireless
==========================

.. NOTE::

* For Prime Mini (non-wireless version), see :doc:`./prime_mini`.


Supported Models
----------------
Expand Down
1 change: 1 addition & 0 deletions rivalcfg/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def _generate_profiles():
kanav2,
kinzuv2,
prime,
prime_mini,
prime_wireless_wired,
prime_wireless_wireless,
rival3,
Expand Down
100 changes: 100 additions & 0 deletions rivalcfg/devices/prime_mini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from .. import usbhid


profile = {
"name": "SteelSeries Prime Mini",
"models": [
{
"name": "SteelSeries Prime Mini",
"vendor_id": 0x1038,
"product_id": 0x184D,
"endpoint": 3,
},
],
"settings": {
"sensitivity": {
"label": "Sensitivity presets",
"description": "Set sensitivity preset (DPI)",
"cli": ["-s", "--sensitivity"],
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x2D],
"value_type": "multidpi_range",
"input_range": [50, 18000, 50],
"output_range": [0x01, 0x0168, 1],
"dpi_length_byte": 2,
"count_mode": "number",
"first_preset": 0,
"max_preset_count": 5,
"default": "400, 800, 1200, 2400, 3200",
},
"polling_rate": {
"label": "Polling rate",
"description": "Set polling rate (Hz)",
"cli": ["-p", "--polling-rate"],
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x2B],
"value_type": "choice",
"choices": {
125: 0x04,
250: 0x03,
500: 0x02,
1000: 0x01,
},
"default": 1000,
},
"color": {
"label": "LED color",
"description": "Set the mouse LED color",
"cli": ["-c", "--color"],
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x21, 0x00],
"value_type": "rgbcolor",
"default": "red",
},
"buttons_mapping": {
"label": "Buttons mapping",
"description": "Set the mapping of the buttons",
"cli": ["-b", "--buttons"],
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x2A],
"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": "dpi"},
"ScrollUp" : {"id": 0x31, "offset": 0x1E, "default": "scrollup"},
"ScrollDown": {"id": 0x32, "offset": 0x23, "default": "scrolldown"},
},
"button_field_length": 5,
"button_disable": 0x00,
"button_keyboard": 0x51,
"button_multimedia": 0x61,
"button_dpi_switch": 0x30,
"button_scroll_up": None,
"button_scroll_down": None,
# fmt: on
"default": "buttons(button1=button1; button2=button2; button3=button3; button4=button4; button5=button5; button6=dpi; scrollup=scrollup; scrolldown=scrolldown; layout=qwerty)",
},
"default_lighting": {
"label": "Default lighting",
"description": "Set default lighting at mouse startup",
"cli": ["-d", "--default-lighting"],
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x27],
"value_type": "choice",
"choices": {
"off": 0x00,
"rainbow": 0x01,
},
"default": "rainbow",
},
},
"save_command": {
"report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
"command": [0x11, 0x00],
},
}
149 changes: 149 additions & 0 deletions test/devices/test_prime_mini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import pytest

from rivalcfg import usbhid
from rivalcfg import mouse
from rivalcfg.devices import prime_mini
from rivalcfg import mouse_settings


class TestDevice(object):
@pytest.fixture
def mouse(self):
settings = mouse_settings.FakeMouseSettings(
0x1038,
0xBAAD,
prime_mini.profile,
)
return mouse.Mouse(
usbhid.FakeDevice(),
prime_mini.profile,
settings,
)

@pytest.mark.parametrize(
"value,expected_hid_report",
[
(100, b"\x02\x00\x2D\x01\x00\x02\x00"),
("100", b"\x02\x00\x2D\x01\x00\x02\x00"),
("500,2500", b"\x02\x00\x2D\x02\x00\x0A\x00\x32\x00"),
(
"500,2500,11050,18000",
b"\x02\x00\x2D\x04\x00\x0A\x00\x32\x00\xDD\x00\x68\x01",
),
],
)
def test_set_sensitivity(self, mouse, value, expected_hid_report):
mouse.set_sensitivity(value)
mouse._hid_device.bytes.seek(0)
hid_report = mouse._hid_device.bytes.read()
assert hid_report == expected_hid_report

@pytest.mark.parametrize(
"value,expected_hid_report",
[
(125, b"\x02\x00\x2b\x04"),
(250, b"\x02\x00\x2b\x03"),
(500, b"\x02\x00\x2b\x02"),
(1000, b"\x02\x00\x2b\x01"),
],
)
def test_set_polling_rate(self, mouse, value, expected_hid_report):
mouse.set_polling_rate(value)
mouse._hid_device.bytes.seek(0)
hid_report = mouse._hid_device.bytes.read()
assert hid_report == expected_hid_report

@pytest.mark.parametrize(
"value,expected_hid_report",
[
("#ABCDEF", b"\x02\x00\x21\x00\xAB\xCD\xEF"),
("red", b"\x02\x00\x21\x00\xFF\x00\x00"),
],
)
def test_set_color(self, mouse, value, expected_hid_report):
mouse.set_color(value)
mouse._hid_device.bytes.seek(0)
hid_report = mouse._hid_device.bytes.read()
assert hid_report == expected_hid_report

@pytest.mark.parametrize(
"value,expected_hid_report",
[
(
"default",
b"\x02\x00"
b"\x2a"
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"\x30\x00\x00\x00\x00"
b"\x31\x00\x00\x00\x00"
b"\x32\x00\x00\x00\x00",
),
(
"buttons(button2=button6)",
b"\x02\x00"
b"\x2a"
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"\x30\x00\x00\x00\x00"
b"\x31\x00\x00\x00\x00"
b"\x32\x00\x00\x00\x00",
),
(
{"buttons": {"button2": "button6"}},
b"\x02\x00"
b"\x2a"
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"\x30\x00\x00\x00\x00"
b"\x31\x00\x00\x00\x00"
b"\x32\x00\x00\x00\x00",
),
(
"buttons(ScrollUp=ScrollDown; ScrollDown=ScrollUp)",
b"\x02\x00"
b"\x2a"
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"\x30\x00\x00\x00\x00"
b"\x32\x00\x00\x00\x00"
b"\x31\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

@pytest.mark.parametrize(
"value,expected_hid_report",
[
("off", b"\x02\x00\x27\x00"),
("rainbow", b"\x02\x00\x27\x01"),
],
)
def test_set_default_lighting(self, mouse, value, expected_hid_report):
mouse.set_default_lighting(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)
hid_report = mouse._hid_device.bytes.read()
assert hid_report == b"\x02\x00\x11\x00"

0 comments on commit 08f3f93

Please sign in to comment.