Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d39c0995b6
|
@ -1,12 +1,40 @@
|
|||
# Notifications (r1_bit0 = battery status?)
|
||||
<< ( 0.113) [10 01 8100 000000] '\x10\x01\x81\x00\x00\x00\x00'
|
||||
>> ( 0.157) [10 01 8100 100000] '\x10\x01\x81\x00\x10\x00\x00'
|
||||
|
||||
short register 0x63: values 0x81 .. 0x8F
|
||||
set DPI as 100 .. 1500
|
||||
# ?
|
||||
<< ( 1.050) [10 01 8101 000000] '\x10\x01\x81\x01\x00\x00\x00'
|
||||
>> ( 1.097) [10 01 8101 020000] '\x10\x01\x81\x01\x02\x00\x00'
|
||||
|
||||
# battery (07 means full)
|
||||
<< ( 7.335) [10 01 8107 000000] '\x10\x01\x81\x07\x00\x00\x00'
|
||||
>> ( 7.382) [10 01 8107 070000] '\x10\x01\x81\x07\x07\x00\x00'
|
||||
|
||||
short register 0x51: set leds
|
||||
value: ab cd 00
|
||||
where a/b/c/d values are 1=off, 2=on, 3=flash
|
||||
a = lower led
|
||||
b = red led
|
||||
c = upper led
|
||||
d = middle led
|
||||
# Set LEDS - ab cd 00, where a/b/c/d values are 1=off, 2=on, 3=flash
|
||||
# a = lower led
|
||||
# b = red led
|
||||
# c = upper led
|
||||
# d = middle led
|
||||
# below: all leds are off
|
||||
<< ( 86.592) [10 01 8151 000000] '\x10\x01\x81Q\x00\x00\x00'
|
||||
>> ( 86.639) [10 01 8151 111100] '\x10\x01\x81Q\x11\x11\x00'
|
||||
|
||||
# DPI (values in range 0x81..0x8F; logical value: 100..1500)
|
||||
<< ( 108.430) [10 01 8163 000000] '\x10\x01\x81c\x00\x00\x00'
|
||||
>> ( 108.477) [10 01 8163 890000] '\x10\x01\x81c\x89\x00\x00'
|
||||
|
||||
# ?
|
||||
<< ( 240.505) [10 01 81D0 000000] '\x10\x01\x81\xd0\x00\x00\x00'
|
||||
>> ( 240.550) [10 01 81D0 000000] '\x10\x01\x81\xd0\x00\x00\x00'
|
||||
|
||||
# ?
|
||||
<< ( 245.690) [10 01 81D4 000000] '\x10\x01\x81\xd4\x00\x00\x00'
|
||||
>> ( 245.737) [10 01 81D4 000012] '\x10\x01\x81\xd4\x00\x00\x12'
|
||||
|
||||
# Firmware/bootloader version
|
||||
<< ( 281.016) [10 01 81F1 000000] '\x10\x01\x81\xf1\x00\x00\x00'
|
||||
>> ( 282.177) [10 01 8F81 F10300] '\x10\x01\x8f\x81\xf1\x03\x00'
|
||||
|
||||
# ?
|
||||
<< ( 284.106) [10 01 81F3 000000] '\x10\x01\x81\xf3\x00\x00\x00'
|
||||
>> ( 284.153) [10 01 81F3 000000] '\x10\x01\x81\xf3\x00\x00\x00'
|
||||
|
|
|
@ -6,6 +6,9 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||
|
||||
from binascii import hexlify as _hexlify
|
||||
from struct import pack as _pack
|
||||
# In Py3, unicode and str are equal (the unicode object does not exist)
|
||||
is_string = lambda d: isinstance(d, str) or \
|
||||
(False if type(u'') == str else isinstance(d, unicode))
|
||||
|
||||
|
||||
class NamedInt(int):
|
||||
|
@ -15,7 +18,7 @@ class NamedInt(int):
|
|||
(case-insensitive)."""
|
||||
|
||||
def __new__(cls, value, name):
|
||||
assert isinstance(name, str) or isinstance(name, unicode)
|
||||
assert is_string(name)
|
||||
obj = int.__new__(cls, value)
|
||||
obj.name = str(name)
|
||||
return obj
|
||||
|
@ -30,8 +33,12 @@ class NamedInt(int):
|
|||
return int(self) == int(other) and self.name == other.name
|
||||
if isinstance(other, int):
|
||||
return int(self) == int(other)
|
||||
if isinstance(other, str) or isinstance(other, unicode):
|
||||
if is_string(other):
|
||||
return self.name.lower() == other.lower()
|
||||
# this should catch comparisons with bytes in Py3
|
||||
if other is not None:
|
||||
raise TypeError("Unsupported type " + str(type(other)))
|
||||
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
@ -64,8 +71,8 @@ class NamedInts(object):
|
|||
|
||||
def __init__(self, **kwargs):
|
||||
def _readable_name(n):
|
||||
if not isinstance(n, str) and not isinstance(n, unicode):
|
||||
raise TypeError("expected string, got " + type(n))
|
||||
if not is_string(n):
|
||||
raise TypeError("expected string, got " + str(type(n)))
|
||||
return n.replace('__', '/').replace('_', ' ')
|
||||
|
||||
values = {k: NamedInt(v, _readable_name(k)) for (k, v) in kwargs.items()}
|
||||
|
@ -100,7 +107,7 @@ class NamedInts(object):
|
|||
self._values = sorted(self._values + [value])
|
||||
return value
|
||||
|
||||
elif isinstance(index, str) or isinstance(index, unicode):
|
||||
elif is_string(index):
|
||||
if index in self.__dict__:
|
||||
return self.__dict__[index]
|
||||
|
||||
|
@ -135,7 +142,7 @@ class NamedInts(object):
|
|||
if isinstance(name, NamedInt):
|
||||
assert int(index) == int(name), repr(index) + ' ' + repr(name)
|
||||
value = name
|
||||
elif isinstance(name, str) or isinstance(name, unicode):
|
||||
elif is_string(name):
|
||||
value = NamedInt(index, name)
|
||||
else:
|
||||
raise TypeError('name must be a string')
|
||||
|
@ -152,7 +159,7 @@ class NamedInts(object):
|
|||
def __contains__(self, value):
|
||||
if isinstance(value, int):
|
||||
return value in self._indexed
|
||||
if isinstance(value, str) or isinstance(value, unicode):
|
||||
elif is_string(value):
|
||||
return value in self.__dict__
|
||||
|
||||
def __iter__(self):
|
||||
|
|
Loading…
Reference in New Issue