receiver: use symbolic identifiers for sub-registers
This commit is contained in:
parent
804ba267f6
commit
8c5800e536
|
@ -22,6 +22,7 @@ _log = getLogger(__name__)
|
||||||
del getLogger
|
del getLogger
|
||||||
|
|
||||||
_R = _hidpp10.REGISTERS
|
_R = _hidpp10.REGISTERS
|
||||||
|
_IR = _hidpp10.INFO_SUBREGISTERS
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -107,7 +108,7 @@ class Device(object):
|
||||||
self._kind = _hidpp10.DEVICE_KIND[kind]
|
self._kind = _hidpp10.DEVICE_KIND[kind]
|
||||||
else:
|
else:
|
||||||
# Not a notification, force a reading of the wpid
|
# Not a notification, force a reading of the wpid
|
||||||
pair_info = self.receiver.read_register(_R.receiver_info, 0x20 + number - 1)
|
pair_info = self.receiver.read_register(_R.receiver_info, _IR.pairing_information + number - 1)
|
||||||
if pair_info:
|
if pair_info:
|
||||||
# may be either a Unifying receiver, or an Unifying-ready
|
# may be either a Unifying receiver, or an Unifying-ready
|
||||||
# receiver
|
# receiver
|
||||||
|
@ -123,7 +124,7 @@ class Device(object):
|
||||||
kind = self.get_kind_from_index(number, receiver)
|
kind = self.get_kind_from_index(number, receiver)
|
||||||
self._kind = _hidpp10.DEVICE_KIND[kind]
|
self._kind = _hidpp10.DEVICE_KIND[kind]
|
||||||
else:
|
else:
|
||||||
# unifying protocol not supported, must be a Nano receiver
|
# unifying protocol not supported, probably an old Nano receiver
|
||||||
device_info = self.receiver.read_register(_R.receiver_info, 0x04)
|
device_info = self.receiver.read_register(_R.receiver_info, 0x04)
|
||||||
if device_info is None:
|
if device_info is None:
|
||||||
_log.error('failed to read Nano wpid for device %d of %s', number, receiver)
|
_log.error('failed to read Nano wpid for device %d of %s', number, receiver)
|
||||||
|
@ -151,7 +152,7 @@ class Device(object):
|
||||||
if self.descriptor is None:
|
if self.descriptor is None:
|
||||||
# Last chance to correctly identify the device; many Nano
|
# Last chance to correctly identify the device; many Nano
|
||||||
# receivers do not support this call.
|
# receivers do not support this call.
|
||||||
codename = self.receiver.read_register(_R.receiver_info, 0x40 + self.number - 1)
|
codename = self.receiver.read_register(_R.receiver_info, _IR.device_name + self.number - 1)
|
||||||
if codename:
|
if codename:
|
||||||
codename_length = ord(codename[1:2])
|
codename_length = ord(codename[1:2])
|
||||||
codename = codename[2:2 + codename_length]
|
codename = codename[2:2 + codename_length]
|
||||||
|
@ -198,7 +199,7 @@ class Device(object):
|
||||||
if self.online and self.protocol >= 2.0:
|
if self.online and self.protocol >= 2.0:
|
||||||
self._codename = _hidpp20.get_friendly_name(self)
|
self._codename = _hidpp20.get_friendly_name(self)
|
||||||
elif self.receiver:
|
elif self.receiver:
|
||||||
codename = self.receiver.read_register(_R.receiver_info, 0x40 + self.number - 1)
|
codename = self.receiver.read_register(_R.receiver_info, _IR.device_name + self.number - 1)
|
||||||
if codename:
|
if codename:
|
||||||
codename_length = ord(codename[1:2])
|
codename_length = ord(codename[1:2])
|
||||||
codename = codename[2:2 + codename_length]
|
codename = codename[2:2 + codename_length]
|
||||||
|
@ -250,7 +251,8 @@ class Device(object):
|
||||||
@property
|
@property
|
||||||
def kind(self):
|
def kind(self):
|
||||||
if not self._kind:
|
if not self._kind:
|
||||||
pair_info = self.receiver.read_register(_R.receiver_info, 0x20 + self.number - 1) if self.receiver else None
|
pair_info = self.receiver.read_register(_R.receiver_info, _IR.pairing_information + self.number - 1) \
|
||||||
|
if self.receiver else None
|
||||||
if pair_info:
|
if pair_info:
|
||||||
kind = ord(pair_info[7:8]) & 0x0F
|
kind = ord(pair_info[7:8]) & 0x0F
|
||||||
self._kind = _hidpp10.DEVICE_KIND[kind]
|
self._kind = _hidpp10.DEVICE_KIND[kind]
|
||||||
|
@ -270,7 +272,7 @@ class Device(object):
|
||||||
@property
|
@property
|
||||||
def serial(self):
|
def serial(self):
|
||||||
if not self._serial and self.receiver:
|
if not self._serial and self.receiver:
|
||||||
serial = self.receiver.read_register(_R.receiver_info, 0x30 + self.number - 1)
|
serial = self.receiver.read_register(_R.receiver_info, _IR.extended_pairing_information + self.number - 1)
|
||||||
if serial:
|
if serial:
|
||||||
ps = ord(serial[9:10]) & 0x0F
|
ps = ord(serial[9:10]) & 0x0F
|
||||||
self._power_switch = _hidpp10.POWER_SWITCH_LOCATION[ps]
|
self._power_switch = _hidpp10.POWER_SWITCH_LOCATION[ps]
|
||||||
|
@ -288,7 +290,7 @@ class Device(object):
|
||||||
@property
|
@property
|
||||||
def power_switch_location(self):
|
def power_switch_location(self):
|
||||||
if not self._power_switch and self.receiver:
|
if not self._power_switch and self.receiver:
|
||||||
ps = self.receiver.read_register(_R.receiver_info, 0x30 + self.number - 1)
|
ps = self.receiver.read_register(_R.receiver_info, _IR.extended_pairing_information + self.number - 1)
|
||||||
if ps:
|
if ps:
|
||||||
ps = ord(ps[9:10]) & 0x0F
|
ps = ord(ps[9:10]) & 0x0F
|
||||||
self._power_switch = _hidpp10.POWER_SWITCH_LOCATION[ps]
|
self._power_switch = _hidpp10.POWER_SWITCH_LOCATION[ps]
|
||||||
|
@ -299,7 +301,7 @@ class Device(object):
|
||||||
@property
|
@property
|
||||||
def polling_rate(self):
|
def polling_rate(self):
|
||||||
if not self._polling_rate and self.receiver:
|
if not self._polling_rate and self.receiver:
|
||||||
pair_info = self.receiver.read_register(_R.receiver_info, 0x20 + self.number - 1)
|
pair_info = self.receiver.read_register(_R.receiver_info, _IR.pairing_information + self.number - 1)
|
||||||
if pair_info:
|
if pair_info:
|
||||||
self._polling_rate = ord(pair_info[2:3])
|
self._polling_rate = ord(pair_info[2:3])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -127,6 +127,16 @@ REGISTERS = _NamedInts(
|
||||||
notifications=0x00,
|
notifications=0x00,
|
||||||
firmware=0xF1,
|
firmware=0xF1,
|
||||||
)
|
)
|
||||||
|
# Subregisters for receiver_info register
|
||||||
|
INFO_SUBREGISTERS = _NamedInts(
|
||||||
|
serial_number=0x01, # not found on many receivers
|
||||||
|
fw_version=0x02,
|
||||||
|
receiver_information=0x03,
|
||||||
|
pairing_information=0x20, # 0x2N, by connected device
|
||||||
|
extended_pairing_information=0x30, # 0x3N, by connected device
|
||||||
|
device_name=0x40, # 0x4N, by connected device
|
||||||
|
)
|
||||||
|
|
||||||
# Flags taken from https://drive.google.com/file/d/0BxbRzx7vEV7eNDBheWY0UHM5dEU/view?usp=sharing
|
# Flags taken from https://drive.google.com/file/d/0BxbRzx7vEV7eNDBheWY0UHM5dEU/view?usp=sharing
|
||||||
DEVICE_FEATURES = _NamedInts(
|
DEVICE_FEATURES = _NamedInts(
|
||||||
reserved1=0x010000,
|
reserved1=0x010000,
|
||||||
|
|
|
@ -34,6 +34,7 @@ _log = getLogger(__name__)
|
||||||
del getLogger
|
del getLogger
|
||||||
|
|
||||||
_R = _hidpp10.REGISTERS
|
_R = _hidpp10.REGISTERS
|
||||||
|
_IR = _hidpp10.INFO_SUBREGISTERS
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -61,7 +62,7 @@ class Receiver(object):
|
||||||
raise Exception('Unknown receiver type', self.product_id)
|
raise Exception('Unknown receiver type', self.product_id)
|
||||||
|
|
||||||
# read the serial immediately, so we can find out max_devices
|
# read the serial immediately, so we can find out max_devices
|
||||||
serial_reply = self.read_register(_R.receiver_info, 0x03)
|
serial_reply = self.read_register(_R.receiver_info, _IR.receiver_information)
|
||||||
if serial_reply:
|
if serial_reply:
|
||||||
self.serial = _strhex(serial_reply[1:5])
|
self.serial = _strhex(serial_reply[1:5])
|
||||||
self.max_devices = ord(serial_reply[6:7])
|
self.max_devices = ord(serial_reply[6:7])
|
||||||
|
|
Loading…
Reference in New Issue