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 1 commit
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
Prev Previous commit
Next Next commit
renaming and adding protection checks
  • Loading branch information
Miskler committed Aug 31, 2024
commit 3f9b082cbb6befc96e72a80d381aecc530c42dc3
31 changes: 26 additions & 5 deletions rivalcfg/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,36 @@ class Mouse:
#: The mouse settings (:class:`rivalcfg.mouse_settings.MouseSettings`)
mouse_settings = None

#: Waiting time for the mouse LED to change color
waiting_led = None
#: 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, waiting_led=0.05):
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
self.waiting_led = waiting_led
if command_approve_delay < self._MIN_COMMAND_APPROVE_DELAY:
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 @@ -268,7 +289,7 @@ def _hid_write(
raise ValueError("Invalid HID report type: %2x" % report_type)

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

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