Skip to content

Commit

Permalink
settings: get and use current host number for K375sFnSwap because of …
Browse files Browse the repository at this point in the history
…bug in firmware of MX Keys S
  • Loading branch information
pfps committed May 3, 2024
1 parent 297e79c commit c54ed2a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/logitech_receiver/settings_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,25 @@ class _PerformanceMXDpi(RegisterDpi):


# ignore the capabilities part of the feature - all devices should be able to swap Fn state
# just use the current host (first byte = 0xFF) part of the feature to read and set the Fn state
# can't just use the first byte = 0xFF (for current host) because of a bug in the firmware of the MX Keys S
class K375sFnSwap(FnSwapVirtual):
feature = _F.K375S_FN_INVERSION
rw_options = {"prefix": b"\xFF"}
validator_options = {"true_value": b"\x01", "false_value": b"\x00", "read_skip_byte_count": 1}

class rw_class(_FeatureRW):
def find_current_host(self, device):
if not self.prefix:
response = device.feature_request(_F.HOSTS_INFO, 0x00)
self.prefix = response[3:4] if response else b"\xFF"

def read(self, device, data_bytes=b""):
self.find_current_host(device)
return super().read(device, data_bytes)

def write(self, device, data_bytes):
self.find_current_host(device)
return super().write(device, data_bytes)


class FnSwap(FnSwapVirtual):
feature = _F.FN_INVERSION
Expand Down
14 changes: 14 additions & 0 deletions tests/logitech_receiver/test_setting_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ class FeatureTest:
hidpp.Response("FF0001", 0x0600, "FF"),
hidpp.Response("FF0101", 0x0610, "FF01"),
),
Setup(
FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06),
hidpp.Response("050001", 0x0000, "1815"), # HOSTS_INFO
hidpp.Response("FF0001", 0x0600, "FF"),
hidpp.Response("FF0101", 0x0610, "FF01"),
),
Setup(
FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06),
hidpp.Response("050001", 0x0000, "1815"), # HOSTS_INFO
hidpp.Response("07050301", 0x0500), # current host is 0x01, i.e., host 2
hidpp.Response("010001", 0x0600, "01"),
hidpp.Response("010101", 0x0610, "0101"),
),
Setup(
FeatureTest(settings_templates.FnSwap, True, False),
hidpp.Response("01", 0x0400),
Expand Down Expand Up @@ -473,6 +486,7 @@ def mock_gethostname(mocker):
@pytest.mark.parametrize("test", simple_tests)
def test_simple_template(test, mocker, mock_gethostname):
tst = test.test
print("TEST", tst.sclass.feature)
device = hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version)
spy_request = mocker.spy(device, "request")

Expand Down

0 comments on commit c54ed2a

Please sign in to comment.