mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-01-06 01:19:38 +00:00
Tidy up broadcast in python client
This commit is contained in:
parent
e9206d2b16
commit
87fd4b42f5
@ -25,6 +25,7 @@ class {{ name }}(namedtuple('{{ name }}', '{{ members }}')):
|
|||||||
{% set type_definitions = [
|
{% set type_definitions = [
|
||||||
{'name':'XAPRequest', 'members': 'token length data', 'fmt':'<HB61s'},
|
{'name':'XAPRequest', 'members': 'token length data', 'fmt':'<HB61s'},
|
||||||
{'name':'XAPResponse', 'members': 'token flags length data', 'fmt':'<HBB60s'},
|
{'name':'XAPResponse', 'members': 'token flags length data', 'fmt':'<HBB60s'},
|
||||||
|
{'name':'XAPBroadcast', 'members': 'token event length data', 'fmt':'<HBB60s'},
|
||||||
{'name':'XAPConfigBacklight', 'members': 'enable mode val', 'fmt':'<BBB'},
|
{'name':'XAPConfigBacklight', 'members': 'enable mode val', 'fmt':'<BBB'},
|
||||||
{'name':'XAPConfigRgblight', 'members': 'enable mode hue sat val speed', 'fmt':'<BBBBBB'},
|
{'name':'XAPConfigRgblight', 'members': 'enable mode hue sat val speed', 'fmt':'<BBBBBB'},
|
||||||
{'name':'XAPConfigRgbMatrix', 'members': 'enable mode hue sat val speed flags', 'fmt':'<BBBBBBB'}
|
{'name':'XAPConfigRgbMatrix', 'members': 'enable mode hue sat val speed flags', 'fmt':'<BBBBBBB'}
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
type_docs: {
|
type_docs: {
|
||||||
bool:
|
bool:
|
||||||
'''
|
'''
|
||||||
Data type that contains values 0 and 1. Implementaed as an alias of `u8`.
|
Data type that contains values 0 and 1. Implemented as an alias of `u8`.
|
||||||
'''
|
'''
|
||||||
u64:
|
u64:
|
||||||
'''
|
'''
|
||||||
|
@ -10,7 +10,7 @@ from typing import Optional
|
|||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
from platform import platform
|
from platform import platform
|
||||||
|
|
||||||
from .types import XAPSecureStatus, XAPFlags, XAPRequest, XAPResponse
|
from .types import XAPSecureStatus, XAPFlags, XAPRequest, XAPResponse, XAPBroadcast
|
||||||
from .routes import XAPRoutes, XAPRouteError
|
from .routes import XAPRoutes, XAPRouteError
|
||||||
|
|
||||||
|
|
||||||
@ -116,8 +116,8 @@ class XAPDeviceBase:
|
|||||||
while not hasattr(event, '_ret'):
|
while not hasattr(event, '_ret'):
|
||||||
event.wait(timeout=0.25)
|
event.wait(timeout=0.25)
|
||||||
|
|
||||||
r = XAPResponse.from_bytes(event._ret)
|
r = XAPBroadcast.from_bytes(event._ret)
|
||||||
return (r.flags, r.data[:r.length])
|
return (r.event, r.data[:r.length])
|
||||||
|
|
||||||
|
|
||||||
class XAPDevice(XAPDeviceBase):
|
class XAPDevice(XAPDeviceBase):
|
||||||
|
@ -59,6 +59,20 @@ class XAPResponse(namedtuple('XAPResponse', 'token flags length data')):
|
|||||||
return self.fmt.pack(*list(self))
|
return self.fmt.pack(*list(self))
|
||||||
|
|
||||||
|
|
||||||
|
class XAPBroadcast(namedtuple('XAPBroadcast', 'token event length data')):
|
||||||
|
fmt = Struct('<HBB60s')
|
||||||
|
|
||||||
|
def __new__(cls, *args):
|
||||||
|
return super().__new__(cls, *args)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_bytes(cls, data):
|
||||||
|
return cls._make(cls.fmt.unpack(data))
|
||||||
|
|
||||||
|
def to_bytes(self):
|
||||||
|
return self.fmt.pack(*list(self))
|
||||||
|
|
||||||
|
|
||||||
class XAPConfigBacklight(namedtuple('XAPConfigBacklight', 'enable mode val')):
|
class XAPConfigBacklight(namedtuple('XAPConfigBacklight', 'enable mode val')):
|
||||||
fmt = Struct('<BBB')
|
fmt = Struct('<BBB')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user