From 5cf6777340404b3a530f232ce6e7a3b0a4c71fe5 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sat, 8 Jun 2013 21:06:52 +0200 Subject: [PATCH] more tweaks to idle polling --- lib/logitech/unifying_receiver/base.py | 2 +- lib/logitech/unifying_receiver/listener.py | 4 ++-- lib/logitech/unifying_receiver/receiver.py | 8 ++++---- lib/solaar/listener.py | 11 +++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/logitech/unifying_receiver/base.py b/lib/logitech/unifying_receiver/base.py index 9ab84c98..b5c5cbc4 100644 --- a/lib/logitech/unifying_receiver/base.py +++ b/lib/logitech/unifying_receiver/base.py @@ -397,7 +397,7 @@ def request(handle, devnumber, request_id, *params): # _log.debug("(%s) still waiting for reply, delta %f", handle, delta) if delta >= timeout: - _log.warn("timeout on device %d request {%04X} params[%s]", devnumber, request_id, _strhex(params)) + _log.warn("timeout on device %d request {%04X} params [%s]", devnumber, request_id, _strhex(params)) break # raise DeviceUnreachable(number=devnumber, request=request_id) diff --git a/lib/logitech/unifying_receiver/listener.py b/lib/logitech/unifying_receiver/listener.py index 47f92adb..eeffeac1 100644 --- a/lib/logitech/unifying_receiver/listener.py +++ b/lib/logitech/unifying_receiver/listener.py @@ -106,7 +106,7 @@ _EVENT_READ_TIMEOUT = 0.5 # After this many reads that did not produce a packet, call the tick() method. # This only happens if tick_period is enabled (>0) for the Listener instance. -_IDLE_READS = 5 +_IDLE_READS = (5 / 0.5) # wait at least 5 seconds between ticks class EventsListener(_threading.Thread): @@ -140,7 +140,7 @@ class EventsListener(_threading.Thread): last_tick = 0 # the first idle read -- delay it a bit, and make sure to stagger # idle reads for multiple receivers - idle_reads = _IDLE_READS * 2 + (ihandle % 3) * 3 + idle_reads = _IDLE_READS * 2 + (ihandle % 3) * 4 while self._active: if self._queued_notifications.empty(): diff --git a/lib/logitech/unifying_receiver/receiver.py b/lib/logitech/unifying_receiver/receiver.py index cf1b41a2..2e79b047 100644 --- a/lib/logitech/unifying_receiver/receiver.py +++ b/lib/logitech/unifying_receiver/receiver.py @@ -176,8 +176,8 @@ class PairedDevice(object): if enable: set_flag_bits = ( _hidpp10.NOTIFICATION_FLAG.battery_status - + _hidpp10.NOTIFICATION_FLAG.wireless - + _hidpp10.NOTIFICATION_FLAG.software_present ) + | _hidpp10.NOTIFICATION_FLAG.wireless + | _hidpp10.NOTIFICATION_FLAG.software_present ) else: set_flag_bits = 0 ok = _hidpp10.set_notification_flags(self, set_flag_bits) @@ -282,8 +282,8 @@ class Receiver(object): if enable: set_flag_bits = ( _hidpp10.NOTIFICATION_FLAG.battery_status - + _hidpp10.NOTIFICATION_FLAG.wireless - + _hidpp10.NOTIFICATION_FLAG.software_present ) + | _hidpp10.NOTIFICATION_FLAG.wireless + | _hidpp10.NOTIFICATION_FLAG.software_present ) else: set_flag_bits = 0 ok = _hidpp10.set_notification_flags(self, set_flag_bits) diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index dd8d9f8a..9a7f58ce 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -38,7 +38,7 @@ def _ghost(device): # how often to poll devices that haven't updated their statuses on their own # (through notifications) -_POLL_TICK = 4 * 60 # seconds +_POLL_TICK = 5 * 60 # seconds class ReceiverListener(_listener.EventsListener): @@ -193,7 +193,8 @@ class ReceiverListener(_listener.EventsListener): # # -# all currently running receiver listeners +# all known receiver listeners +# listeners that stop on their own may remain here _all_listeners = {} @@ -214,9 +215,11 @@ def stop_all(): _all_listeners.clear() for l in listeners: - l.stop() + if l: + l.stop() for l in listeners: - l.join() + if l: + l.join() _status_callback = None