From c6506b3508af7f156f36aca87999a9dcf56d878d Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sat, 11 Jul 2020 10:00:56 -0400 Subject: [PATCH] receiver: add option to not wait for a reply when requesting to device --- lib/logitech_receiver/base.py | 11 ++++++----- lib/logitech_receiver/hidpp20.py | 4 ++-- lib/logitech_receiver/receiver.py | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/logitech_receiver/base.py b/lib/logitech_receiver/base.py index 9700e424..f52ec13d 100644 --- a/lib/logitech_receiver/base.py +++ b/lib/logitech_receiver/base.py @@ -312,16 +312,14 @@ del namedtuple # -def request(handle, devnumber, request_id, *params): +# a very few requests (e.g., host switching) do not expect a reply, but use no_reply=True with extreme caution +def request(handle, devnumber, request_id, *params, no_reply=False): """Makes a feature call to a device and waits for a matching reply. - - This function will wait for a matching reply indefinitely. - :param handle: an open UR handle. :param devnumber: attached device number. :param request_id: a 16-bit integer. :param params: parameters for the feature call, 3 to 16 bytes. - :returns: the reply data, or ``None`` if some error occurred. + :returns: the reply data, or ``None`` if some error occurred. or no reply expected """ # import inspect as _inspect @@ -354,6 +352,9 @@ def request(handle, devnumber, request_id, *params): _skip_incoming(handle, ihandle, notifications_hook) write(ihandle, devnumber, request_data) + if no_reply: + return None + # we consider timeout from this point request_started = _timestamp() delta = 0 diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 280a8498..d045efb4 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -435,11 +435,11 @@ class KeysArray(object): # -def feature_request(device, feature, function=0x00, *params): +def feature_request(device, feature, function=0x00, *params, no_reply=False): if device.online and device.features: if feature in device.features: feature_index = device.features.index(int(feature)) - return device.request((feature_index << 8) + (function & 0xFF), *params) + return device.request((feature_index << 8) + (function & 0xFF), *params, no_reply=no_reply) def get_firmware(device): diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py index 3f23f35a..4c69b266 100644 --- a/lib/logitech_receiver/receiver.py +++ b/lib/logitech_receiver/receiver.py @@ -284,15 +284,15 @@ class PairedDevice(object): _log.info('%s: device notifications %s %s', self, 'enabled' if enable else 'disabled', flag_names) return flag_bits if ok else None - def request(self, request_id, *params): - return _base.request(self.receiver.handle, self.number, request_id, *params) + def request(self, request_id, *params, no_reply=False): + return _base.request(self.receiver.handle, self.number, request_id, *params, no_reply=no_reply) read_register = _hidpp10.read_register write_register = _hidpp10.write_register - def feature_request(self, feature, function=0x00, *params): + def feature_request(self, feature, function=0x00, *params, no_reply=False): if self.protocol >= 2.0: - return _hidpp20.feature_request(self, feature, function, *params) + return _hidpp20.feature_request(self, feature, function, *params, no_reply=no_reply) def ping(self): """Checks if the device is online, returns True of False"""