Skip to content

Commit

Permalink
receiver: delay device sending first messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Feb 12, 2024
1 parent faa65b3 commit 9a3ef39
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/logitech_receiver/hidpp10.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
REGISTERS = _NamedInts(
# only apply to receivers
receiver_connection=0x02,
devices_configuration=0x03,
receiver_pairing=0xB2,
devices_activity=0x2B3,
receiver_info=0x2B5,
Expand Down Expand Up @@ -379,6 +380,19 @@ def set_notification_flags(device, *flag_bits):
return result is not None


def get_configuration_pending_flags(receiver):
assert not receiver.isDevice
result = read_register(receiver, REGISTERS.devices_configuration)
if result is not None:
return ord(result[:1])


def set_configuration_pending_flags(receiver, devices):
assert not receiver.isDevice
result = write_register(receiver, REGISTERS.devices_configuration, devices)
return result is not None


def get_device_features(device):
assert device is not None

Expand Down
3 changes: 3 additions & 0 deletions lib/logitech_receiver/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ def _process_hidpp10_notification(device, status, n):
bool(flags & 0x10), link_encrypted, link_established, bool(flags & 0x80)
)
status[_K.LINK_ENCRYPTED] = link_encrypted
if not link_established and device.receiver:
print('FLAGS OFFLINE', _hidpp10.get_configuration_pending_flags(device.receiver))
_hidpp10.set_configuration_pending_flags(device.receiver, 0xFF)
status.changed(active=link_established)
return True

Expand Down
2 changes: 2 additions & 0 deletions lib/logitech_receiver/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def __init__(self, handle, path, product_id):
self._firmware = None
self._devices = {}
self._remaining_pairings = None
print('FLAGS', _hidpp10.get_configuration_pending_flags(self))
_hidpp10.set_configuration_pending_flags(self, 0xFF)

def close(self):
handle, self.handle = self.handle, None
Expand Down
4 changes: 4 additions & 0 deletions lib/logitech_receiver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,10 @@ def key_action(self, key): # acction to take when some other diverted key is pr


def apply_all_settings(device):
if device.receiver:
from . import hidpp10 as _hidpp10
print(device, device.receiver)
print('FLAGS APPLY', _hidpp10.get_configuration_pending_flags(device.receiver))
if device.features and _hidpp20.FEATURE.HIRES_WHEEL in device.features:
_sleep(0.2) # delay to try to get out of race condition with Linux HID++ driver
persister = getattr(device, 'persister', None)
Expand Down
6 changes: 6 additions & 0 deletions lib/solaar/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def _print_receiver(receiver):
print(' Device path :', receiver.path)
print(' USB id : 046d:%s' % receiver.product_id)
print(' Serial :', receiver.serial)
pending = _hidpp10.get_configuration_pending_flags(receiver)
if pending:
print(' C Pending : %02x' % pending)
if receiver.firmware:
for f in receiver.firmware:
print(' %-11s: %s' % (f.kind, f.version))
Expand Down Expand Up @@ -222,6 +225,9 @@ def _print_device(dev, num=None):
print(' Unit ID: %s Model ID: %s Transport IDs: %s' % (unitId, modelId, tid_map))
elif feature == _hidpp20.FEATURE.REPORT_RATE or feature == _hidpp20.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE:
print(' Report Rate: %s' % _hidpp20.get_polling_rate(dev))
elif feature == _hidpp20.FEATURE.CONFIG_CHANGE:
response = dev.feature_request(_hidpp20.FEATURE.CONFIG_CHANGE, 0x10)
print(' Configuration: %s' % response.hex())
elif feature == _hidpp20.FEATURE.REMAINING_PAIRING:
print(' Remaining Pairings: %d' % _hidpp20.get_remaining_pairing(dev))
elif feature == _hidpp20.FEATURE.ONBOARD_PROFILES:
Expand Down

0 comments on commit 9a3ef39

Please sign in to comment.