This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdpg_command.py
85 lines (55 loc) · 1.67 KB
/
dpg_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import codecs
import struct
from .desk_position import DeskPosition
class DPGCommand:
@classmethod
def wrap_read_command(cls, value):
return struct.pack('BBB', 0x7F, value, 0x0)
@classmethod
def build_command(cls, data):
command_type = data[1]
command_data = data[2:]
if command_type == 0x07 and len(command_data) >= 6:
subcommand_type = command_data[5]
if subcommand_type == 0x03:
return MemorySetting1Command(command_data)
elif subcommand_type == 0x06:
return MemorySetting2Command(command_data)
return COMMAND_TYPES.get(command_type, cls)(command_data)
def __init__(self, data):
self._data = data
@property
def raw_value(self):
return codecs.encode(self._data, 'hex')
@property
def decoded_value(self):
return self.raw_value
class UserIDCommand(DPGCommand):
pass
class CapabilitiesCommand(DPGCommand):
pass
class ReminderSettingsCommand(DPGCommand):
pass
class DeskOffsetCommand(DPGCommand):
@property
def decoded_value(self):
if self._data[0] != 0x01:
return -1
return self.offset
@property
def offset(self):
return DeskPosition.from_bytes(self._data[1:3])
class MemorySettingCommand(DeskOffsetCommand):
pass
class MemorySetting1Command(MemorySettingCommand):
pass
class MemorySetting2Command(MemorySettingCommand):
pass
COMMAND_TYPES = {
0x02: CapabilitiesCommand,
0x03: DeskOffsetCommand,
0x07: MemorySetting2Command,
0x0b: ReminderSettingsCommand,
0x0d: MemorySetting1Command,
0x11: UserIDCommand,
}