better logging in cli tools
This commit is contained in:
parent
ecf3539ba2
commit
c6427ab4a6
|
@ -11,7 +11,8 @@ def read_next(handle, timeout=1000, ignore_nodata=False):
|
|||
print "!! Read failed, aborting"
|
||||
raise Exception()
|
||||
if reply:
|
||||
print ">> %s %s" % (hexlify(reply), repr(reply))
|
||||
hexs = hexlify(reply)
|
||||
print ">> [%s %s %s %s] %s" % (hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(reply))
|
||||
return True
|
||||
|
||||
if not ignore_nodata:
|
||||
|
@ -25,7 +26,7 @@ def console_cycle(handle):
|
|||
continue
|
||||
|
||||
line = raw_input('!! Enter packet to send (hex bytes) or ^C to abort: ')
|
||||
line = line.strip()
|
||||
line = line.strip().replace(' ', '').replace('-', '')
|
||||
if not line:
|
||||
continue
|
||||
if len(line) % 2 == 1:
|
||||
|
@ -36,7 +37,8 @@ def console_cycle(handle):
|
|||
except:
|
||||
print "!! Invalid input."
|
||||
continue
|
||||
print "<< %s %s" % (hexlify(data), repr(data))
|
||||
hexs = hexlify(data)
|
||||
print "<< [%s %s %s %s] %s" % (hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data))
|
||||
hidapi.write(handle, data)
|
||||
read_next(handle)
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ def scan_devices(receiver):
|
|||
|
||||
for devinfo in devices:
|
||||
print "Device [%d] %s (%s)" % (devinfo.number, devinfo.name, devinfo.type)
|
||||
print " Protocol %s" % devinfo.protocol
|
||||
|
||||
for fw in devinfo.firmware:
|
||||
print " %s firmware: %s version %s build %d" % (fw.type, fw.name, fw.version, fw.build)
|
||||
|
||||
|
@ -51,11 +53,12 @@ if __name__ == '__main__':
|
|||
log_level = logging.root.level - 10 * args.verbose
|
||||
logging.root.setLevel(log_level if log_level > 0 else 1)
|
||||
|
||||
receiver = api.open()
|
||||
if receiver:
|
||||
print "!! Logitech Unifying Receiver found."
|
||||
scan_devices(receiver)
|
||||
for rawdevice in api._base.list_receiver_devices():
|
||||
receiver = api._base.try_open(rawdevice.path)
|
||||
if receiver:
|
||||
print "!! Logitech Unifying Receiver found (%s)." % rawdevice.path
|
||||
scan_devices(receiver)
|
||||
api.close(receiver)
|
||||
break
|
||||
else:
|
||||
print "!! Logitech Unifying Receiver not found."
|
||||
|
||||
api.close(receiver)
|
||||
|
|
Loading…
Reference in New Issue