mirror of
https://github.com/gryf/linak-ctrl.git
synced 2026-04-25 16:01:31 +02:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32b49bd278 | |||
| 9a33f742e1 | |||
| e9ea91f2c3 | |||
| aa5aecb205 | |||
| 2013dffcf9 |
+28
@@ -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
-19
@@ -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.')
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
pbr
|
||||
pyusb>=1.1.1
|
||||
@@ -0,0 +1,34 @@
|
||||
[metadata]
|
||||
name = linak-ctrl
|
||||
summary = Control Linak powered desks using USB2LIN06 cable.
|
||||
description-file = README.rst
|
||||
author = Roman Dobosz
|
||||
author-email = gryf73@gmail.com
|
||||
home-page = https://gihtub.com/gryf/linak-ctrl
|
||||
license = BSD
|
||||
classifier =
|
||||
Development Status :: 5 - Production/Stable
|
||||
Environment :: Console
|
||||
Intended Audience :: End Users/Desktop
|
||||
License :: OSI Approved :: BSD License
|
||||
Operating System :: POSIX :: Linux
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
Programming Language :: Python :: 3.9
|
||||
Topic :: System :: Networking
|
||||
|
||||
[install]
|
||||
record = install.log
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
linak-ctrl= linak_ctrl:main
|
||||
|
||||
[options]
|
||||
install_requires =
|
||||
pyusb
|
||||
|
||||
[bdist_wheel]
|
||||
universal = 1
|
||||
Reference in New Issue
Block a user