fixed event detection
This commit is contained in:
parent
205d25e341
commit
e2909f6165
|
@ -240,9 +240,9 @@ def make_event(devnumber, data):
|
|||
if devnumber == 0xFF:
|
||||
if sub_id == 0x4A: # receiver lock event
|
||||
return _Event(devnumber, sub_id, ord(data[1:2]), data[2:])
|
||||
else:
|
||||
elif sub_id & 0x80 != 0x80:
|
||||
address = ord(data[1:2])
|
||||
if sub_id > 0x00 and (sub_id >= 0x40 or (address & 0x01 == 0)):
|
||||
if sub_id >= 0x40 or address & 0x01 == 0:
|
||||
return _Event(devnumber, sub_id, address, data[2:])
|
||||
|
||||
|
||||
|
|
|
@ -85,6 +85,11 @@ class NamedInts(object):
|
|||
def flag_names(self, value):
|
||||
return ', '.join(str(self._indexed[k]) for k in self._indexed if k & value == k)
|
||||
|
||||
def index(self, value):
|
||||
if value in self._values:
|
||||
return self._values.index(value)
|
||||
raise IndexError('%s not found' % value)
|
||||
|
||||
def __getitem__(self, index):
|
||||
if type(index) == int:
|
||||
if index in self._indexed:
|
||||
|
|
|
@ -44,7 +44,7 @@ _D('Wireless Trackball M570')
|
|||
_D('Touch Mouse M600')
|
||||
_D('Marathon Mouse M705',
|
||||
registers=_NamedInts(battery=0x0D),
|
||||
settings=[hidpp10.SmoothScroll_Setting(0x01)]
|
||||
settings=[hidpp10.SmoothScroll_Setting(0x01)],
|
||||
)
|
||||
_D('Wireless Keyboard K270')
|
||||
_D('Wireless Keyboard K350')
|
||||
|
@ -59,7 +59,7 @@ _D('Anywhere Mouse MX', codename='Anywhere MX')
|
|||
_D('Performance Mouse MX', codename='Performance MX',
|
||||
settings=[
|
||||
hidpp10.MouseDPI_Setting(0x63, _NamedInts(**dict((str(x * 100), 0x80 + x) for x in range(1, 16)))),
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
del namedtuple
|
||||
|
|
|
@ -31,7 +31,7 @@ ERROR='error'
|
|||
|
||||
# if not updates have been receiver from the device for a while, assume
|
||||
# it has gone offline and clear all its know properties.
|
||||
_STATUS_TIMEOUT = 180 # seconds
|
||||
_STATUS_TIMEOUT = 120 # seconds
|
||||
|
||||
#
|
||||
#
|
||||
|
@ -157,6 +157,8 @@ class DeviceStatus(dict):
|
|||
self._changed(active=False, alert=ALERT.LOW, timestamp=timestamp)
|
||||
|
||||
def process_event(self, event):
|
||||
assert event.sub_id < 0x80
|
||||
|
||||
if event.sub_id == 0x40:
|
||||
if event.address == 0x02:
|
||||
# device un-paired
|
||||
|
@ -191,7 +193,7 @@ class DeviceStatus(dict):
|
|||
|
||||
return True
|
||||
|
||||
if event.sub_id == 0x04B:
|
||||
if event.sub_id == 0x4B:
|
||||
if event.address == 0x01:
|
||||
_log.debug("device came online? %d", event.devnumber)
|
||||
self._changed(alert=ALERT.LOW, reason='powered on')
|
||||
|
@ -199,12 +201,6 @@ class DeviceStatus(dict):
|
|||
_log.warn("unknown event %s", event)
|
||||
return True
|
||||
|
||||
if event.sub_id >= 0x80:
|
||||
# this can't possibly be an event, can it?
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
_log.debug("ignoring %s (not an event)", event)
|
||||
return False
|
||||
|
||||
if event.sub_id >= 0x40:
|
||||
_log.warn("don't know how to handle event %s", event)
|
||||
return False
|
||||
|
@ -214,7 +210,11 @@ class DeviceStatus(dict):
|
|||
_log.warn("device %d got event from unknown feature index %02X", self._device.number, event.sub_id)
|
||||
return False
|
||||
|
||||
feature = self._device.features[event.sub_id]
|
||||
try:
|
||||
feature = self._device.features[event.sub_id]
|
||||
except IndexError:
|
||||
_log.warn("don't know how to handle event %s for feature with invalid index %02X", event, event.sub_id)
|
||||
return False
|
||||
|
||||
if feature == _hidpp20.FEATURE.BATTERY:
|
||||
if event.address == 0x00:
|
||||
|
@ -288,4 +288,4 @@ class DeviceStatus(dict):
|
|||
_log.debug("TOUCH MOUSE status: button_down=%s mouse_lifted=%s", button_down, mouse_lifted)
|
||||
return True
|
||||
|
||||
_log.warn("don't know how to handle event %s for feature %s", event, feature)
|
||||
_log.warn("don't know how to handle event %s for feature %s (%02X)", event, feature, event.sub_id)
|
||||
|
|
Loading…
Reference in New Issue