From bc9f39873e56641a997a04a1d29d5916d6ed9a15 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Thu, 11 Oct 2012 22:02:13 +0300 Subject: [PATCH] api function to query receiver info --- lib/logitech/unifying_receiver/api.py | 25 +++++++++++++++++++++++++ lib/logitech/ur_scanner.py | 23 ++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/logitech/unifying_receiver/api.py b/lib/logitech/unifying_receiver/api.py index b16c0873..0db33221 100644 --- a/lib/logitech/unifying_receiver/api.py +++ b/lib/logitech/unifying_receiver/api.py @@ -33,6 +33,31 @@ open = _base.open close = _base.close +def get_receiver_info(handle): + serial = None + reply = _base.request(handle, 0xff, b'\x83\xB5', b'\x03') + if reply and reply[0:1] == b'\x03': + serial = _hexlify(reply[1:5]) + + firmware = '??.??' + reply = _base.request(handle, 0xff, b'\x81\xF1', b'\x01') + if reply and reply[0:1] == b'\x01': + fw_version = _hexlify(reply[1:3]) + firmware = fw_version[0:2] + '.' + fw_version[2:4] + + reply = _base.request(handle, 0xff, b'\x81\xF1', b'\x02') + if reply and reply[0:1] == b'\x02': + firmware += '.B' + _hexlify(reply[1:3]) + + bootloader = None + reply = _base.request(handle, 0xff, b'\x81\xF1', b'\x04') + if reply and reply[0:1] == b'\x04': + bl_version = _hexlify(reply[1:3]) + bootloader = bl_version[0:2] + '.' + bl_version[2:4] + + return (serial, firmware, bootloader) + + def request(handle, devnumber, feature, function=b'\x00', params=b'', features=None): """Makes a feature call to the device, and returns the reply data. diff --git a/lib/logitech/ur_scanner.py b/lib/logitech/ur_scanner.py index 49f79f0c..30753aff 100644 --- a/lib/logitech/ur_scanner.py +++ b/lib/logitech/ur_scanner.py @@ -6,33 +6,18 @@ logging.basicConfig(level=logging.DEBUG) from binascii import hexlify -from .unifying_receiver import (api, base) +from .unifying_receiver import api from .unifying_receiver.constants import * def print_receiver(receiver): print ("Unifying Receiver") - reply = base.request(receiver, 0xff, b'\x83\xB5', b'\x03') - if reply and reply[0:1] == b'\x03': - print (" Serial: %s" % hexlify(reply[1:5])) + serial, firmware, bootloader = api.get_receiver_info(receiver) - reply = base.request(receiver, 0xff, b'\x81\xF1', b'\x01') - if reply and reply[0:1] == b'\x01': - fw_version = hexlify(reply[1:3]) - firmware = fw_version[0:2] + '.' + fw_version[2:4] - else: - firmware = '??.??' - - reply = base.request(receiver, 0xff, b'\x81\xF1', b'\x02') - if reply and reply[0:1] == b'\x02': - firmware += '.B' + hexlify(reply[1:3]) + print (" Serial: %s" % serial) print (" Firmware version: %s" % firmware) - - reply = base.request(receiver, 0xff, b'\x81\xF1', b'\x04') - if reply and reply[0:1] == b'\x04': - bl_version = hexlify(reply[1:3]) - print (" Bootloader: %s.%s" % (bl_version[0:2], bl_version[2:4])) + print (" Bootloader: %s" % bootloader) print ("--------")