From 5b8c983ab37ccaea03e35c67c414f3e1c6eea04a Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sat, 24 Nov 2012 22:48:31 +0200 Subject: [PATCH] some speed tweaks to hidconsole batch mode --- lib/hidapi/hidconsole.py | 15 ++++++++++----- .../unifying_receiver/tests/test_00_hidapi.py | 17 ----------------- 2 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 lib/logitech/unifying_receiver/tests/test_00_hidapi.py diff --git a/lib/hidapi/hidconsole.py b/lib/hidapi/hidconsole.py index e7787f6f..7496b082 100644 --- a/lib/hidapi/hidconsole.py +++ b/lib/hidapi/hidconsole.py @@ -5,7 +5,7 @@ import sys from select import select as _select import time from binascii import hexlify, unhexlify -_hex = lambda d: hexlify(d).decode('ascii').upper() +strhex = lambda d: hexlify(d).decode('ascii').upper() interactive = os.isatty(0) @@ -24,7 +24,7 @@ def _print(marker, data, scroll=False): sys.stdout.write('\033[S') # scroll up sys.stdout.write('\033[A\033[L\033[G') # insert new line above the current one, position on first column - hexs = _hex(data) + hexs = strhex(data) s = '%s (% 8.3f) [%s %s %s %s] %s' % (marker, t, hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data)) sys.stdout.write(s) @@ -34,7 +34,7 @@ def _print(marker, data, scroll=False): sys.stdout.write('\n') -def _continuous_read(handle, timeout=1000): +def _continuous_read(handle, timeout=2000): while True: reply = hidapi.read(handle, 128, timeout) if reply is None: @@ -95,8 +95,13 @@ if __name__ == '__main__': hidapi.write(handle, data) # wait for some kind of reply if not interactive: - rlist, wlist, xlist = _select([handle], [], [], 1) - time.sleep(0.1) + if data[1:2] == b'\xFF': + # the receiver will reply very fast, in a few milliseconds + time.sleep(0.010) + else: + # the devices might reply quite slow + rlist, wlist, xlist = _select([handle], [], [], 1) + time.sleep(0.050) except EOFError: pass except Exception as e: diff --git a/lib/logitech/unifying_receiver/tests/test_00_hidapi.py b/lib/logitech/unifying_receiver/tests/test_00_hidapi.py deleted file mode 100644 index 15a89bc8..00000000 --- a/lib/logitech/unifying_receiver/tests/test_00_hidapi.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# test loading the hidapi library -# - -import logging -import unittest - - -class Test_Import_HIDAPI(unittest.TestCase): - def test_00_import_hidapi(self): - import hidapi - self.assertIsNotNone(hidapi) - logging.info("hidapi loaded native implementation %s", hidapi.native_implementation) - - -if __name__ == '__main__': - unittest.main()