From c38d10a65415cb422e4a74ac21bf9c9e27e2c770 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Thu, 9 Jul 2020 07:27:54 -0400 Subject: [PATCH] receiver: gather host names from HOSTS_INFO feature and show them --- docs/features.md | 2 +- lib/logitech_receiver/hidpp20.py | 29 ++++++++++++++++++++++++++++- lib/solaar/cli/show.py | 4 ++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/features.md b/docs/features.md index 7977b56431..46aefeb9bb 100644 --- a/docs/features.md +++ b/docs/features.md @@ -34,7 +34,7 @@ Feature | ID | Status | Notes `OOBSTATE` | `0x1805` | :x: | `CONFIG_DEVICE_PROPS` | `0x1806` | :x: | `CHANGE_HOST` | `0x1814` | :x: | -`HOSTS_INFO` | `0x1815` | :x: | +`HOSTS_INFO` | `0x1815` | :heavy_plus_sign: | `get_host_names`, partial listing only `BACKLIGHT` | `0x1981` | :x: | `BACKLIGHT2` | `0x1982` | :heavy_check_mark: | `_feature_backlight2` `BACKLIGHT3` | `0x1983` | :x: | diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 0a3415e62d..280a8498f9 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -651,9 +651,36 @@ def get_hires_wheel(device): def get_new_fn_inversion(device): state = feature_request(device, FEATURE.NEW_FN_INVERSION, 0x00) - if state: inverted, default_inverted = _unpack('!BB', state[:2]) inverted = (inverted & 0x01) != 0 default_inverted = (default_inverted & 0x01) != 0 return inverted, default_inverted + + +def get_host_names(device): + state = feature_request(device, FEATURE.HOSTS_INFO, 0x00) + host_names = {} + if state: + _ignore, _ignore, numHosts, currentHost = _unpack('!BBBB', state[:4]) + for host in range(0, numHosts): + hostinfo = feature_request(device, FEATURE.HOSTS_INFO, 0x10, host) + _ignore, status, _ignore, numPages, nameLen, _ignore = _unpack('!BBBBBB', hostinfo[:6]) + name = '' + remaining = nameLen + while remaining > 0: + name_piece = feature_request(device, FEATURE.HOSTS_INFO, 0x30, host, nameLen - remaining) + name += name_piece[2:2 + min(remaining, 14)].decode() + remaining = max(0, remaining - 14) + host_names[host] = (bool(status), name) + return host_names + + +def set_host_name(device, name): + state = feature_request(device, FEATURE.HOSTS_INFO, 0x00) + if state: + flags = _unpack('!B', state[:1])[0] + if flags & 0x02: + hn = name[:min(14, name.find('.'))] if name.find('.') >= 0 else name + response = feature_request(device, FEATURE.HOSTS_INFO, 0x40, 0xff, 0, hn) + return response diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index 948b272afa..05c52512b7 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -172,6 +172,10 @@ def _print_device(dev): inverted, default_inverted = _hidpp20.get_new_fn_inversion(dev) print(' Fn-swap:', 'enabled' if inverted else 'disabled') print(' Fn-swap default:', 'enabled' if default_inverted else 'disabled') + elif feature == _hidpp20.FEATURE.HOSTS_INFO: + host_names = _hidpp20.get_host_names(dev) + for host, (paired, name) in host_names.items(): + print(' Host %s (%s): %s' % (host, 'paired' if paired else 'unpaired', name)) for setting in dev_settings: if setting.feature == feature: v = setting.read(False)