Skip to content

Commit

Permalink
util/agents/usb_hid_relay: add support for the LCTech USB HID relay
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Luebbe <[email protected]>
  • Loading branch information
jluebbe committed Aug 8, 2024
1 parent c9fc5bf commit a9d2d1c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ HIDRelay
++++++++
An :any:`HIDRelay` resource describes a single output of an HID protocol based
USB relays.
It currently supports the widely used *dcttech USBRelay*.
It currently supports the widely used *dcttech USBRelay* and *lctech LCUS*

.. code-block:: yaml
Expand Down
1 change: 1 addition & 0 deletions labgrid/resource/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def filter_match(self, device):
match = (device.properties.get('ID_VENDOR_ID'), device.properties.get('ID_MODEL_ID'))

if match not in [("16c0", "05df"), # dcttech USBRelay2
("5131", "2007"), # LC-US8
]:
return False

Expand Down
17 changes: 17 additions & 0 deletions labgrid/util/agents/usb_hid_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def __init__(self, **args):
if self._dev.idVendor == 0x16C0:
self.set_output = self.set_output_dcttech
self.get_output = self.get_output_dcttech
elif self._dev.idVendor == 0x5131:
self.set_output = self.set_output_lcus
self.get_output = self.get_output_lcus
else:
raise ValueError(f"Unknown vendor/protocol for VID {self._dev.idVendor:x}")

Expand Down Expand Up @@ -56,6 +59,20 @@ def get_output_dcttech(self, number):
)
return bool(resp[7] & (1 << (number - 1)))

def set_output_lcus(self, number, status):
assert 1 <= number <= 8
ep_in = self._dev[0][(0, 0)][0]
ep_out = self._dev[0][(0, 0)][1]
req = [0xA0, number, 0x01 if status else 0x00, 0x00]
req[3] = sum(req) & 0xFF
ep_out.write(req)
ep_in.read(64)

def get_output_lcus(self, number):
assert 1 <= number <= 8
# we have no information on how to read the current value
return False

def __del__(self):
usb.util.release_interface(self._dev, 0)

Expand Down

0 comments on commit a9d2d1c

Please sign in to comment.