Skip to content

Commit

Permalink
receiver: gather host names from HOSTS_INFO feature and show them
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Jul 9, 2020
1 parent d386f43 commit c38d10a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
29 changes: 28 additions & 1 deletion lib/logitech_receiver/hidpp20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/solaar/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c38d10a

Please sign in to comment.