From 83bd0ac4ea960e60b1603b066a9971ccc73154b1 Mon Sep 17 00:00:00 2001 From: gryf Date: Wed, 23 Jun 2021 15:35:36 +0200 Subject: [PATCH] Added initialization part. Sometimes the usb2lin06 device need to be initialized. Added that part to the init of LinakDevice class. --- linak_ctrl.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/linak_ctrl.py b/linak_ctrl.py index 303c0af..2cc0a2d 100755 --- a/linak_ctrl.py +++ b/linak_ctrl.py @@ -14,9 +14,12 @@ REQ_TYPE_GET_INTERFACE = 0xa1 REQ_TYPE_SET_INTERFACE = 0x21 HID_GET_REPORT = 0x01 HID_SET_REPORT = 0x09 +INIT = 0x0303 MOVE = 0x0305 GET_STATUS = 0x0304 BUF_LEN = 64 +MODE_OF_OPERATION = 0x03 +MODE_OF_OPERATION_DEFAULT = 0x04 class Logger: @@ -109,6 +112,17 @@ class LinakDevice: self._dev = usb.core.find(idVendor=LinakDevice.VEND, idProduct=LinakDevice.PROD) + # init device + buf = [0 for _ in range(BUF_LEN)] + buf[0] = MODE_OF_OPERATION # 0x03 Feature report ID = 3 + buf[1] = MODE_OF_OPERATION_DEFAULT # 0x04 mode of operation + buf[2] = 0x00 # ? + buf[3] = 0xfb # ? + self._dev.ctrl_transfer(REQ_TYPE_SET_INTERFACE, HID_SET_REPORT, INIT, + 0, array.array('B', buf)) + # hold a little bit, to make it effect. + time.sleep(0.5) + # detach kernel driver, if attached if self._dev.is_kernel_driver_active(0): self._dev.detach_kernel_driver(0)