receiver: gather host names from HOSTS_INFO feature and show them

This commit is contained in:
Peter F. Patel-Schneider 2020-07-09 07:27:54 -04:00
parent d386f4369b
commit c38d10a654
3 changed files with 33 additions and 2 deletions

View File

@ -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: |

View File

@ -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

View File

@ -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)