addded custom swids to feature calls
This commit is contained in:
parent
c12364a7c7
commit
4b2d8a8d5a
|
|
@ -30,7 +30,7 @@ def _charge_status(data, hasLux=False):
|
||||||
|
|
||||||
def request_status(devinfo):
|
def request_status(devinfo):
|
||||||
reply = _api.request(devinfo.handle, devinfo.number,
|
reply = _api.request(devinfo.handle, devinfo.number,
|
||||||
feature=FEATURE.SOLAR_CHARGE, function=b'\x03', params=b'\x78\x01',
|
feature=FEATURE.SOLAR_CHARGE, function=b'\x06', params=b'\x78\x01',
|
||||||
features=devinfo.features)
|
features=devinfo.features)
|
||||||
if reply is None:
|
if reply is None:
|
||||||
return STATUS.UNAVAILABLE
|
return STATUS.UNAVAILABLE
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ class Receiver(object):
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def request(handle, devnumber, feature, function=b'\x00', params=b'', features=None):
|
def request(handle, devnumber, feature, function=b'\x04', params=b'', features=None):
|
||||||
"""Makes a feature call to the device, and returns the reply data.
|
"""Makes a feature call to the device, and returns the reply data.
|
||||||
|
|
||||||
Basically a write() followed by (possibly multiple) reads, until a reply
|
Basically a write() followed by (possibly multiple) reads, until a reply
|
||||||
|
|
@ -349,7 +349,7 @@ def get_device_features(handle, devnumber):
|
||||||
# even if unknown.
|
# even if unknown.
|
||||||
|
|
||||||
# get the number of active features the device has
|
# get the number of active features the device has
|
||||||
features_count = _base.request(handle, devnumber, fs_index + b'\x00')
|
features_count = _base.request(handle, devnumber, fs_index + b'\x05')
|
||||||
if not features_count:
|
if not features_count:
|
||||||
# this can happen if the device disappeard since the fs_index request
|
# this can happen if the device disappeard since the fs_index request
|
||||||
# otherwise we should get at least a count of 1 (the FEATURE_SET we've just used above)
|
# otherwise we should get at least a count of 1 (the FEATURE_SET we've just used above)
|
||||||
|
|
@ -362,7 +362,7 @@ def get_device_features(handle, devnumber):
|
||||||
features = [None] * 0x20
|
features = [None] * 0x20
|
||||||
for index in range(1, 1 + features_count):
|
for index in range(1, 1 + features_count):
|
||||||
# for each index, get the feature residing at that index
|
# for each index, get the feature residing at that index
|
||||||
feature = _base.request(handle, devnumber, fs_index + b'\x10', _pack('!B', index))
|
feature = _base.request(handle, devnumber, fs_index + b'\x15', _pack('!B', index))
|
||||||
if feature:
|
if feature:
|
||||||
# feature_flags = ord(feature[2:3]) & 0xE0
|
# feature_flags = ord(feature[2:3]) & 0xE0
|
||||||
feature = feature[0:2].upper()
|
feature = feature[0:2].upper()
|
||||||
|
|
@ -390,13 +390,13 @@ def get_device_firmware(handle, devnumber, features=None):
|
||||||
if fw_fi is None:
|
if fw_fi is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fw_count = _base.request(handle, devnumber, _pack('!BB', fw_fi, 0x00))
|
fw_count = _base.request(handle, devnumber, _pack('!BB', fw_fi, 0x05))
|
||||||
if fw_count:
|
if fw_count:
|
||||||
fw_count = ord(fw_count[:1])
|
fw_count = ord(fw_count[:1])
|
||||||
|
|
||||||
fw = []
|
fw = []
|
||||||
for index in range(0, fw_count):
|
for index in range(0, fw_count):
|
||||||
fw_info = _base.request(handle, devnumber, _pack('!BB', fw_fi, 0x10), params=index)
|
fw_info = _base.request(handle, devnumber, _pack('!BB', fw_fi, 0x15), params=index)
|
||||||
if fw_info:
|
if fw_info:
|
||||||
level = ord(fw_info[:1]) & 0x0F
|
level = ord(fw_info[:1]) & 0x0F
|
||||||
if level == 0 or level == 1:
|
if level == 0 or level == 1:
|
||||||
|
|
@ -431,7 +431,7 @@ def get_device_kind(handle, devnumber, features=None):
|
||||||
if name_fi is None:
|
if name_fi is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
d_kind = _base.request(handle, devnumber, _pack('!BB', name_fi, 0x20))
|
d_kind = _base.request(handle, devnumber, _pack('!BB', name_fi, 0x25))
|
||||||
if d_kind:
|
if d_kind:
|
||||||
d_kind = ord(d_kind[:1])
|
d_kind = ord(d_kind[:1])
|
||||||
# _log.debug("device %d type %d = %s", devnumber, d_kind, DEVICE_KIND[d_kind])
|
# _log.debug("device %d type %d = %s", devnumber, d_kind, DEVICE_KIND[d_kind])
|
||||||
|
|
@ -448,13 +448,13 @@ def get_device_name(handle, devnumber, features=None):
|
||||||
if name_fi is None:
|
if name_fi is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
name_length = _base.request(handle, devnumber, _pack('!BB', name_fi, 0x00))
|
name_length = _base.request(handle, devnumber, _pack('!BB', name_fi, 0x05))
|
||||||
if name_length:
|
if name_length:
|
||||||
name_length = ord(name_length[:1])
|
name_length = ord(name_length[:1])
|
||||||
|
|
||||||
d_name = b''
|
d_name = b''
|
||||||
while len(d_name) < name_length:
|
while len(d_name) < name_length:
|
||||||
name_fragment = _base.request(handle, devnumber, _pack('!BB', name_fi, 0x10), len(d_name))
|
name_fragment = _base.request(handle, devnumber, _pack('!BB', name_fi, 0x15), len(d_name))
|
||||||
if name_fragment:
|
if name_fragment:
|
||||||
name_fragment = name_fragment[:name_length - len(d_name)]
|
name_fragment = name_fragment[:name_length - len(d_name)]
|
||||||
d_name += name_fragment
|
d_name += name_fragment
|
||||||
|
|
@ -473,7 +473,7 @@ def get_device_battery_level(handle, devnumber, features=None):
|
||||||
"""
|
"""
|
||||||
bat_fi = _get_feature_index(handle, devnumber, FEATURE.BATTERY, features)
|
bat_fi = _get_feature_index(handle, devnumber, FEATURE.BATTERY, features)
|
||||||
if bat_fi is not None:
|
if bat_fi is not None:
|
||||||
battery = _base.request(handle, devnumber, _pack('!BB', bat_fi, 0))
|
battery = _base.request(handle, devnumber, _pack('!BB', bat_fi, 0x05))
|
||||||
if battery:
|
if battery:
|
||||||
discharge, dischargeNext, status = _unpack('!BBB', battery[:3])
|
discharge, dischargeNext, status = _unpack('!BBB', battery[:3])
|
||||||
_log.debug("device %d battery %d%% charged, next level %d%% charge, status %d = %s",
|
_log.debug("device %d battery %d%% charged, next level %d%% charge, status %d = %s",
|
||||||
|
|
@ -486,13 +486,13 @@ def get_device_keys(handle, devnumber, features=None):
|
||||||
if rk_fi is None:
|
if rk_fi is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
count = _base.request(handle, devnumber, _pack('!BB', rk_fi, 0))
|
count = _base.request(handle, devnumber, _pack('!BB', rk_fi, 0x05))
|
||||||
if count:
|
if count:
|
||||||
keys = []
|
keys = []
|
||||||
|
|
||||||
count = ord(count[:1])
|
count = ord(count[:1])
|
||||||
for index in range(0, count):
|
for index in range(0, count):
|
||||||
keydata = _base.request(handle, devnumber, _pack('!BB', rk_fi, 0x10), index)
|
keydata = _base.request(handle, devnumber, _pack('!BB', rk_fi, 0x15), index)
|
||||||
if keydata:
|
if keydata:
|
||||||
key, key_task, flags = _unpack('!HHB', keydata[:5])
|
key, key_task, flags = _unpack('!HHB', keydata[:5])
|
||||||
rki = _ReprogrammableKeyInfo(index, key, KEY_NAME[key], key_task, KEY_NAME[key_task], flags)
|
rki = _ReprogrammableKeyInfo(index, key, KEY_NAME[key], key_task, KEY_NAME[key_task], flags)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
from struct import pack as _pack
|
from struct import pack as _pack
|
||||||
from struct import unpack as _unpack
|
|
||||||
from binascii import hexlify as _hexlify
|
from binascii import hexlify as _hexlify
|
||||||
_hex = lambda d: _hexlify(d).decode('ascii').upper()
|
_hex = lambda d: _hexlify(d).decode('ascii').upper()
|
||||||
|
|
||||||
|
|
@ -313,7 +312,7 @@ def ping(handle, devnumber):
|
||||||
context = request_context
|
context = request_context
|
||||||
_unhandled = getattr(context, 'unhandled_hook')
|
_unhandled = getattr(context, 'unhandled_hook')
|
||||||
|
|
||||||
context.write(handle, devnumber, b'\x00\x10\x00\x00\xAA')
|
context.write(handle, devnumber, b'\x00\x11\x00\x00\xAA')
|
||||||
read_times = _MAX_READ_TIMES
|
read_times = _MAX_READ_TIMES
|
||||||
while read_times > 0:
|
while read_times > 0:
|
||||||
divisor = (1 + _MAX_READ_TIMES - read_times)
|
divisor = (1 + _MAX_READ_TIMES - read_times)
|
||||||
|
|
@ -335,14 +334,16 @@ def ping(handle, devnumber):
|
||||||
_unhandled(reply_code, reply_devnumber, reply_data)
|
_unhandled(reply_code, reply_devnumber, reply_data)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if reply_code == 0x11 and reply_data[:2] == b'\x00\x10' and reply_data[4:5] == b'\xAA':
|
if reply_code == 0x11 and reply_data[:2] == b'\x00\x11' and reply_data[4:5] == b'\xAA':
|
||||||
major, minor = _unpack('!BB', reply_data[2:4])
|
# HID 2.0+ device, currently connected
|
||||||
return major + minor / 10.0
|
return ord(reply_data[2:3]) + ord(reply_data[3:4]) / 10.0
|
||||||
|
|
||||||
if reply_code == 0x10 and reply_data == b'\x8F\x00\x10\x01\x00':
|
if reply_code == 0x10 and reply_data == b'\x8F\x00\x11\x01\x00':
|
||||||
|
# HID 1.0 device, currently connected
|
||||||
return 1.0
|
return 1.0
|
||||||
|
|
||||||
if reply_code == 0x10 and reply_data[:3] == b'\x8F\x00\x10':
|
if reply_code == 0x10 and reply_data[:3] == b'\x8F\x00\x11':
|
||||||
|
# a disconnected device
|
||||||
return None
|
return None
|
||||||
|
|
||||||
_log.warn("don't know how to interpret ping reply %s", reply)
|
_log.warn("don't know how to interpret ping reply %s", reply)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue