1
0
mirror of https://github.com/gryf/linak-ctrl.git synced 2026-04-25 07:51:30 +02:00

10 Commits

Author SHA1 Message Date
gryf 3abdbfaa6a Removed license classifier in favor of SPDX entry. 2025-04-18 16:07:12 +02:00
gryf ab18c7d90f Move from setup.cfg to pyproject.toml. 2025-03-26 19:34:52 +01:00
gryf 4ae101603e Readme update. 2022-04-13 17:44:42 +02:00
gryf 13d2f008ad Make the package instead of bare module. 2022-04-13 17:39:43 +02:00
gryf 8793e55695 Fix typo in the url. 2022-04-08 18:20:03 +02:00
gryf 32b49bd278 Cover case when no device has been found. 2021-07-29 19:31:21 +02:00
gryf 9a33f742e1 Readme update. 2021-07-07 18:00:00 +02:00
gryf e9ea91f2c3 Detach kernel driver before doing anything with device.
Initialization of the device must be done after device is detached from
kernel, otherwise exception will be thrown about device is busy message.
2021-07-07 17:34:13 +02:00
gryf aa5aecb205 DRY. Simplifying get_status method. 2021-07-07 17:33:00 +02:00
gryf 2013dffcf9 Added installation bits. 2021-07-07 17:30:58 +02:00
4 changed files with 102 additions and 24 deletions
+3
View File
@@ -0,0 +1,3 @@
.venv
*.egg-info
build
+33 -5
View File
@@ -2,6 +2,9 @@
Linak-ctrl
==========
.. image:: https://badge.fury.io/py/linak-ctrl.svg
:target: https://badge.fury.io/py/linak-ctrl
Simple python script to control Linak powered desks and USB2LIN06 cable.
@@ -14,6 +17,31 @@ Requirements
* `pyusb`_
Installation
============
There are couple of different ways for installing ``linak-ctrl``. One of the
preferred ways is to use virtualenv and pip:
.. code:: shell-session
$ git clone https://github.com/gryf/linak-ctrl
$ cd linak-ctrl
linak-ctrl $ python -m venv linak
(linak) linak-ctrl $ pip install .
(linak) linak-ctrl $ linak-ctrl status
Position: 767, height: 78.80cm, moving: False
Or, you can install it system-wide:
.. code:: shell-session
# sudo pip install linak-ctrl
And finally, you could also install dependences from your system repositories,
and use script directly, by placing it somewhere in your ``$PATH``.
Usage
=====
@@ -24,7 +52,7 @@ number, and in centimeters, and information if desk is moving.
.. code:: shell-session
$ linak_ctrl.py status
$ linak_ctrl/__init__.py status
Position: 767, height: 78.80cm, moving: False
Note, that height was measured manually and may differ depending if desk have
@@ -35,7 +63,7 @@ information from USB2LIN06 device every 0.2 seconds:
.. code:: shell-session
$ linak_ctrl.py status -l
$ linak_ctrl/__init__.py status -l
Position: 2161, height: 100.25cm, moving: True
Position: 2109, height: 99.45cm, moving: True
Position: 2026, height: 98.17cm, moving: True
@@ -53,14 +81,14 @@ my case). For example:
.. code:: shell-session
$ linak_ctrl.py move 1000
$ linak_ctrl/__init__.py move 1000
For displaying debug information verbosity can be increased using ``--verbose``
parameter:
.. code:: shell-session
$ linak_ctrl.py -v move 1000
$ linak_ctrl/__init__.py -v move 1000
Current position: 771
Current position: 792
Current position: 825
@@ -73,7 +101,7 @@ Adding more `-v` will increase amount of information:
.. code:: shell-session
$ linak_ctrl.py -vv move 1000
$ linak_ctrl/__init__.py -vv move 1000
array('B', [4, 56, 17, 8, 3, 3, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0])
Current position: 771
array('B', [4, 56, 17, 0, 21, 3, 0, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0])
+24 -19
View File
@@ -111,6 +111,14 @@ class LinakDevice:
def __init__(self):
self._dev = usb.core.find(idVendor=LinakDevice.VEND,
idProduct=LinakDevice.PROD)
if not self._dev:
raise ValueError(f'Device {LinakDevice.VEND}:'
f'{LinakDevice.PROD:04d} '
f'not found!')
# detach kernel driver, if attached
if self._dev.is_kernel_driver_active(0):
self._dev.detach_kernel_driver(0)
# init device
buf = [0 for _ in range(BUF_LEN)]
@@ -123,25 +131,18 @@ class LinakDevice:
# 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)
def get_position(self, args):
if args.loop:
try:
while True:
report = self._get_report()
LOG.warning('Position: %s, height: %.2fcm, moving: %s',
report.position, report.position_in_cm,
report.moving)
time.sleep(0.2)
except KeyboardInterrupt:
return
else:
report = self._get_report()
LOG.warning('Position: %s, height: %.2fcm, moving: %s',
report.position, report.position_in_cm, report.moving)
try:
while True:
report = self._get_report()
LOG.warning('Position: %s, height: %.2fcm, moving: %s',
report.position, report.position_in_cm,
report.moving)
if not args.loop:
break
time.sleep(0.2)
except KeyboardInterrupt:
return
def move(self, args):
retry_count = 3
@@ -191,7 +192,11 @@ class LinakDevice:
def main():
device = LinakDevice()
try:
device = LinakDevice()
except ValueError as ex:
sys.stderr.write(ex.args[0] + '\n')
sys.exit(1)
parser = argparse.ArgumentParser('An utility to interact with USB2LIN06 '
'device.')
+42
View File
@@ -0,0 +1,42 @@
[build-system]
requires = ["setuptools >= 77.0"]
build-backend = "setuptools.build_meta"
[project]
name = "linak-ctrl"
version = "1.0.5"
requires-python = ">= 3.10"
description = "Control Linak powered desks using USB2LIN06 cable."
dependencies = [
"pyusb>=1.3.1"
]
readme = "README.rst"
authors = [
{name = "Roman Dobosz", email = "gryf73@gmail.com"}
]
license = "BSD-3-Clause"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: System :: Networking"
]
[tool.setuptools]
py-modules = ["linak_ctrl"]
[project.urls]
Repository = "https://github.com/gryf/linak-ctrl"
[project.scripts]
linak-ctrl = "linak_ctrl:main"
[tool.distutils.bdist_wheel]
universal = true