improved hid++ 1.0 support
This commit is contained in:
parent
6d70d2aada
commit
27403a08d2
|
@ -95,8 +95,8 @@ class ReceiverListener(_listener.EventsListener):
|
||||||
return
|
return
|
||||||
|
|
||||||
for dev in self.receiver:
|
for dev in self.receiver:
|
||||||
assert dev.status is not None
|
if dev.status is not None:
|
||||||
dev.status.poll(timestamp)
|
dev.status.poll(timestamp)
|
||||||
|
|
||||||
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
|
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
|
@ -125,8 +125,7 @@ class ReceiverListener(_listener.EventsListener):
|
||||||
assert event.devnumber > 0 and event.devnumber <= self.receiver.max_devices
|
assert event.devnumber > 0 and event.devnumber <= self.receiver.max_devices
|
||||||
already_known = event.devnumber in self.receiver
|
already_known = event.devnumber in self.receiver
|
||||||
dev = self.receiver[event.devnumber]
|
dev = self.receiver[event.devnumber]
|
||||||
if dev:
|
if dev and dev.status is not None:
|
||||||
assert dev.status is not None
|
|
||||||
dev.status.process_event(event)
|
dev.status.process_event(event)
|
||||||
if self.receiver.status.lock_open and not already_known:
|
if self.receiver.status.lock_open and not already_known:
|
||||||
# this should be the first event after a device was paired
|
# this should be the first event after a device was paired
|
||||||
|
@ -134,7 +133,7 @@ class ReceiverListener(_listener.EventsListener):
|
||||||
_log.info("pairing detected new device")
|
_log.info("pairing detected new device")
|
||||||
self.receiver.status.new_device = dev
|
self.receiver.status.new_device = dev
|
||||||
else:
|
else:
|
||||||
_log.warn("received event %s for invalid device %d", event, event.devnumber)
|
_log.warn("received event %s for invalid device %d: %s", event, event.devnumber, dev)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '<ReceiverListener(%s,%s)>' % (self.receiver.path, self.receiver.handle)
|
return '<ReceiverListener(%s,%s)>' % (self.receiver.path, self.receiver.handle)
|
||||||
|
|
|
@ -216,9 +216,11 @@ def unpair_device(receiver, args):
|
||||||
if dev is receiver:
|
if dev is receiver:
|
||||||
_fail("cannot unpair the receiver")
|
_fail("cannot unpair the receiver")
|
||||||
|
|
||||||
|
# query these
|
||||||
|
number, name, codename, serial = dev.number, dev.name, dev.codename, dev.serial
|
||||||
try:
|
try:
|
||||||
del receiver[dev.number]
|
del receiver[number]
|
||||||
print ("Unpaired %d: %s [%s:%s]" % (dev.number, dev.name, dev.codename, dev.serial))
|
print ("Unpaired %d: %s [%s:%s]" % (number, name, codename, serial))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_fail("failed to unpair device %s: %s" % (dev.name, e))
|
_fail("failed to unpair device %s: %s" % (dev.name, e))
|
||||||
|
|
||||||
|
|
|
@ -318,6 +318,9 @@ def request(handle, devnumber, request_id, *params):
|
||||||
# these replies have to match the first parameter as well
|
# these replies have to match the first parameter as well
|
||||||
if reply_data[2:3] == params[:1]:
|
if reply_data[2:3] == params[:1]:
|
||||||
return reply_data[2:]
|
return reply_data[2:]
|
||||||
|
else:
|
||||||
|
# hm, not mathing my request, and certainly not an event
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
return reply_data[2:]
|
return reply_data[2:]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -71,7 +71,12 @@ def get_battery(device):
|
||||||
reply = device.request(0x810D)
|
reply = device.request(0x810D)
|
||||||
if reply:
|
if reply:
|
||||||
charge = ord(reply[:1])
|
charge = ord(reply[:1])
|
||||||
return charge, None
|
status = ord(reply[2:3]) & 0xF0
|
||||||
|
status = ('discharging' if status == 0x30
|
||||||
|
else 'charging' if status == 0x50
|
||||||
|
else 'fully charged' if status == 0x90
|
||||||
|
else None)
|
||||||
|
return charge, status
|
||||||
|
|
||||||
|
|
||||||
def get_serial(device):
|
def get_serial(device):
|
||||||
|
|
|
@ -31,6 +31,7 @@ FEATURE = _NamedInts(
|
||||||
BATTERY=0x1000,
|
BATTERY=0x1000,
|
||||||
REPROGRAMMABLE_KEYS=0x1B00,
|
REPROGRAMMABLE_KEYS=0x1B00,
|
||||||
WIRELESS=0x1D4B,
|
WIRELESS=0x1D4B,
|
||||||
|
FN_TOGGLE=0x40A0,
|
||||||
SOLAR_CHARGE=0x4301,
|
SOLAR_CHARGE=0x4301,
|
||||||
TOUCH_MOUSE=0x6110)
|
TOUCH_MOUSE=0x6110)
|
||||||
FEATURE._fallback = lambda x: 'unknown:%04X' % x
|
FEATURE._fallback = lambda x: 'unknown:%04X' % x
|
||||||
|
|
|
@ -33,6 +33,7 @@ class PairedDevice(object):
|
||||||
self._protocol = None
|
self._protocol = None
|
||||||
self._wpid = None
|
self._wpid = None
|
||||||
self._power_switch = None
|
self._power_switch = None
|
||||||
|
self._polling_rate = None
|
||||||
self._codename = None
|
self._codename = None
|
||||||
self._name = None
|
self._name = None
|
||||||
self._kind = None
|
self._kind = None
|
||||||
|
@ -58,8 +59,16 @@ class PairedDevice(object):
|
||||||
if self._kind is None:
|
if self._kind is None:
|
||||||
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]
|
||||||
|
if self._polling_rate is None:
|
||||||
|
self._polling_rate = ord(pair_info[2:3])
|
||||||
return self._wpid
|
return self._wpid
|
||||||
|
|
||||||
|
@property
|
||||||
|
def polling_rate(self):
|
||||||
|
if self._polling_rate is None:
|
||||||
|
self.wpid, 0
|
||||||
|
return self._polling_rate
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def power_switch_location(self):
|
def power_switch_location(self):
|
||||||
if self._power_switch is None:
|
if self._power_switch is None:
|
||||||
|
|
|
@ -180,6 +180,14 @@ class DeviceStatus(dict):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if event.sub_id == 0x04B:
|
||||||
|
if event.address == 0x01:
|
||||||
|
_log.debug("device came online? %d", event.devnumber)
|
||||||
|
self._changed(alert=ALERT.LOW, reason='powered on')
|
||||||
|
else:
|
||||||
|
_log.warn("unknown event %s", event)
|
||||||
|
return True
|
||||||
|
|
||||||
if event.sub_id >= 0x80:
|
if event.sub_id >= 0x80:
|
||||||
# this can't possibly be an event, can it?
|
# this can't possibly be an event, can it?
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
|
@ -188,6 +196,7 @@ class DeviceStatus(dict):
|
||||||
|
|
||||||
if event.sub_id >= 0x40:
|
if event.sub_id >= 0x40:
|
||||||
_log.warn("don't know how to handle event %s", event)
|
_log.warn("don't know how to handle event %s", event)
|
||||||
|
return False
|
||||||
|
|
||||||
# this must be a feature event, assuming no device has more than 0x40 features
|
# this must be a feature event, assuming no device has more than 0x40 features
|
||||||
if event.sub_id >= len(self._device.features):
|
if event.sub_id >= len(self._device.features):
|
||||||
|
|
Loading…
Reference in New Issue