receiver: support GESTURE2 specs
This commit is contained in:
parent
7498febc3a
commit
09394cfbf5
|
@ -32,6 +32,7 @@ from .common import FirmwareInfo as _FirmwareInfo
|
||||||
from .common import KwException as _KwException
|
from .common import KwException as _KwException
|
||||||
from .common import NamedInt as _NamedInt
|
from .common import NamedInt as _NamedInt
|
||||||
from .common import NamedInts as _NamedInts
|
from .common import NamedInts as _NamedInts
|
||||||
|
from .common import bytes2int as _bytes2int
|
||||||
from .common import pack as _pack
|
from .common import pack as _pack
|
||||||
from .common import unpack as _unpack
|
from .common import unpack as _unpack
|
||||||
|
|
||||||
|
@ -854,6 +855,33 @@ class Param(object):
|
||||||
return feature_request(self._device, FEATURE.GESTURE_2, 0x80, self.index, bytes, 0xFF)
|
return feature_request(self._device, FEATURE.GESTURE_2, 0x80, self.index, bytes, 0xFF)
|
||||||
|
|
||||||
|
|
||||||
|
class Spec:
|
||||||
|
def __init__(self, device, low, high):
|
||||||
|
self._device = device
|
||||||
|
self.id = low
|
||||||
|
self.spec = SPEC[low]
|
||||||
|
self.byte_count = high & 0x0F
|
||||||
|
self._value = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
if self._value is None:
|
||||||
|
self._value = self.read()
|
||||||
|
return self._value
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
try:
|
||||||
|
value = feature_request(self._device, FEATURE.GESTURE_2, 0x50, self.id, 0xFF)
|
||||||
|
except FeatureCallError:
|
||||||
|
# I don't know if this should happen, but I get an error
|
||||||
|
# with spec 5
|
||||||
|
return None
|
||||||
|
return _bytes2int(value[:self.byte_count])
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'[{self.spec}={self.value}]'
|
||||||
|
|
||||||
|
|
||||||
class Gestures(object):
|
class Gestures(object):
|
||||||
"""Information about the gestures that a device supports.
|
"""Information about the gestures that a device supports.
|
||||||
Right now only some information fields are supported.
|
Right now only some information fields are supported.
|
||||||
|
@ -863,6 +891,7 @@ class Gestures(object):
|
||||||
self.device = device
|
self.device = device
|
||||||
self.gestures = {}
|
self.gestures = {}
|
||||||
self.params = {}
|
self.params = {}
|
||||||
|
self.specs = {}
|
||||||
index = 0
|
index = 0
|
||||||
field_high = 0x00
|
field_high = 0x00
|
||||||
while field_high != 0x01: # end of fields
|
while field_high != 0x01: # end of fields
|
||||||
|
@ -884,6 +913,10 @@ class Gestures(object):
|
||||||
elif field_high == 0x04:
|
elif field_high == 0x04:
|
||||||
if field_low != 0x00:
|
if field_low != 0x00:
|
||||||
_log.error(f'Unimplemented GESTURE_2 grouping {field_low} {field_high} found.')
|
_log.error(f'Unimplemented GESTURE_2 grouping {field_low} {field_high} found.')
|
||||||
|
elif field_high & 0xF0 == 0x40:
|
||||||
|
spec = Spec(device, field_low, field_high)
|
||||||
|
self.specs[spec.spec] = spec
|
||||||
|
print(spec)
|
||||||
else:
|
else:
|
||||||
_log.warn(f'Unimplemented GESTURE_2 field {field_low} {field_high} found.')
|
_log.warn(f'Unimplemented GESTURE_2 field {field_low} {field_high} found.')
|
||||||
index += 1
|
index += 1
|
||||||
|
|
|
@ -204,11 +204,16 @@ def _print_device(dev, num=None):
|
||||||
report_fmt = report_fmt if report_fmt else 'default'
|
report_fmt = report_fmt if report_fmt else 'default'
|
||||||
print(' reporting: %s' % (report_fmt))
|
print(' reporting: %s' % (report_fmt))
|
||||||
if dev.online and dev.gestures:
|
if dev.online and dev.gestures:
|
||||||
print(' Has %d gestures and %d param:' % (len(dev.gestures.gestures), len(dev.gestures.params)))
|
print(
|
||||||
|
' Has %d gesture(s), %d param(s) and %d spec(s):' %
|
||||||
|
(len(dev.gestures.gestures), len(dev.gestures.params), len(dev.gestures.specs))
|
||||||
|
)
|
||||||
for k in dev.gestures.gestures.values():
|
for k in dev.gestures.gestures.values():
|
||||||
print(' %-26s Enabled (%4s): %s' % (k.gesture, k.index, k.enabled()))
|
print(' %-26s Enabled (%4s): %s' % (k.gesture, k.index, k.enabled()))
|
||||||
for k in dev.gestures.params.values():
|
for k in dev.gestures.params.values():
|
||||||
print(' %-26s Value (%4s): %s' % (k.param, k.index, k.value()))
|
print(' %-26s Value (%4s): %s' % (k.param, k.index, k.value()))
|
||||||
|
for k in dev.gestures.specs.values():
|
||||||
|
print(' %-26s Spec (%4s): %s' % (k.spec, k.id, k.value))
|
||||||
if dev.online:
|
if dev.online:
|
||||||
battery = _hidpp20.get_battery(dev)
|
battery = _hidpp20.get_battery(dev)
|
||||||
if battery is None:
|
if battery is None:
|
||||||
|
|
Loading…
Reference in New Issue