fixed pairing in solaar-cli
This commit is contained in:
parent
44c79d71d7
commit
c328d6f6c6
|
@ -192,46 +192,39 @@ def pair_device(receiver, args):
|
||||||
# get all current devices
|
# get all current devices
|
||||||
known_devices = [dev.number for dev in receiver]
|
known_devices = [dev.number for dev in receiver]
|
||||||
|
|
||||||
from logitech.unifying_receiver import status
|
from logitech.unifying_receiver import base, hidpp10, status
|
||||||
r_status = status.ReceiverStatus(receiver, lambda *args, **kwargs: None)
|
r_status = status.ReceiverStatus(receiver, lambda *args, **kwargs: None)
|
||||||
|
|
||||||
done = [False]
|
# check if it's necessary to set the notification flags
|
||||||
|
notification_flags = hidpp10.get_notification_flags(receiver) or 0
|
||||||
|
if not notification_flags & hidpp10.NOTIFICATION_FLAG.wireless:
|
||||||
|
hidpp10.set_notification_flags(receiver, notification_flags | hidpp10.NOTIFICATION_FLAG.wireless)
|
||||||
|
|
||||||
def _notification_handler(n):
|
class HandleWithNotificationHook(int):
|
||||||
|
def notifications_hook(self, n):
|
||||||
|
assert n
|
||||||
if n.devnumber == 0xFF:
|
if n.devnumber == 0xFF:
|
||||||
r_status.process_notification(n)
|
r_status.process_notification(n)
|
||||||
if not r_status.lock_open:
|
|
||||||
done[0] = True
|
|
||||||
elif n.sub_id == 0x41 and n.address == 0x04:
|
elif n.sub_id == 0x41 and n.address == 0x04:
|
||||||
if n.devnumber not in known_devices:
|
if n.devnumber not in known_devices:
|
||||||
r_status.new_device = receiver[n.devnumber]
|
r_status.new_device = receiver[n.devnumber]
|
||||||
|
|
||||||
from logitech.unifying_receiver import base
|
timeout = 20 # seconds
|
||||||
base.notifications_hook = _notification_handler
|
receiver.handle = HandleWithNotificationHook(receiver.handle)
|
||||||
|
receiver.set_lock(False, timeout=timeout)
|
||||||
|
print ("Pairing: turn your new device on (timing out in", timeout, "seconds).")
|
||||||
|
|
||||||
# check if it's necessary to set the notification flags
|
while r_status.lock_open:
|
||||||
notification_flags = receiver.request(0x8100)
|
n = base.read(receiver.handle)
|
||||||
if notification_flags:
|
|
||||||
# just to see if any bits are set
|
|
||||||
notification_flags = ord(notification_flags[:1]) + ord(notification_flags[1:2]) + ord(notification_flags[2:3])
|
|
||||||
if not notification_flags:
|
|
||||||
# if there are any notifications set, just assume the one we need is already set
|
|
||||||
receiver.enable_notifications()
|
|
||||||
receiver.set_lock(False, timeout=20)
|
|
||||||
print ("Pairing: turn your new device on (timing out in 20 seconds).")
|
|
||||||
|
|
||||||
while not done[0]:
|
|
||||||
n = base.read(receiver.handle, 2000)
|
|
||||||
if n:
|
if n:
|
||||||
n = base.make_notification(*n)
|
n = base.make_notification(*n)
|
||||||
if n:
|
if n:
|
||||||
_notification_handler(n)
|
receiver.handle.notifications_hook(n)
|
||||||
|
|
||||||
if not notification_flags:
|
if not notification_flags & hidpp10.NOTIFICATION_FLAG.wireless:
|
||||||
# only clear the flags if they weren't set before, otherwise a
|
# only clear the flags if they weren't set before, otherwise a
|
||||||
# concurrently running Solaar app will stop working properly
|
# concurrently running Solaar app might stop working properly
|
||||||
receiver.enable_notifications(False)
|
hidpp10.set_notification_flags(receiver, notification_flags)
|
||||||
base.notifications_hook = None
|
|
||||||
|
|
||||||
if r_status.new_device:
|
if r_status.new_device:
|
||||||
dev = r_status.new_device
|
dev = r_status.new_device
|
||||||
|
|
Loading…
Reference in New Issue