Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add waiting_time varible in Mouse class, replace hardcode #236

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions rivalcfg/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,36 @@ class Mouse:
#: The mouse settings (:class:`rivalcfg.mouse_settings.MouseSettings`)
mouse_settings = None

def __init__(self, hid_device, mouse_profile, mouse_settings):
#: Waiting time for the mouse to process and approve the command
# Setting the value too low may cause the device to freeze and potentially even break.
_MIN_COMMAND_APPROVE_DELAY = 0.001
_command_approve_delay = None

def __init__(self, hid_device, mouse_profile, mouse_settings, command_approve_delay=0.05):
"""Constructor."""
self._hid_device = hid_device
self.mouse_profile = mouse_profile
self.mouse_settings = mouse_settings
if command_approve_delay < self._MIN_COMMAND_APPROVE_DELAY:
raise ValueError(f"command_approve_delay is unsafe to use, with a delay of less than {self._MIN_COMMAND_APPROVE_DELAY} seconds")
else:
self._command_approve_delay = command_approve_delay

@property
def command_approve_delay(self):
"""
Waiting time for the mouse to process and approve the command

Setting the value too low may cause the device to freeze and potentially even break.
"""
return self._command_approve_delay

@command_approve_delay.setter
def command_approve_delay(self, new_value):
if new_value < self._MIN_COMMAND_APPROVE_DELAY:
raise ValueError(f"command_approve_delay is unsafe to use, with a delay of less than {self._MIN_COMMAND_APPROVE_DELAY} seconds")

self._command_approve_delay = new_value

@property
def name(self):
Expand Down Expand Up @@ -264,7 +289,7 @@ def _hid_write(
raise ValueError("Invalid HID report type: %2x" % report_type)

# Avoids sending multiple commands to quickly
time.sleep(0.05)
time.sleep(self._command_approve_delay)

def __getattr__(self, name):
# Handle every set_xxx methods generated from device's profiles
Expand Down
Loading