Skip to content

Commit

Permalink
Ensure device channel is reset before setting Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriemi-git committed Aug 31, 2022
1 parent 4cc4069 commit 40d8430
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions liquidctl/driver/commander_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _send_command(self, command, data=()):
def _wake_device_context(self):
try:
self._send_command(_CMD_WAKE)
self._send_command(_CMD_RESET)
yield
finally:
self._send_command(_CMD_SLEEP)
Expand Down
12 changes: 8 additions & 4 deletions tests/test_commander_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):

self._last_write = bytes()
self._modes = {}

self._is_reset = False
self._awake = False

self.response_prefix = ()
Expand All @@ -52,7 +52,7 @@ def read(self, length):
if self._awake:
if self._last_write[2] == 0x08: # Get data
channel = self._last_write[3]
mode = self._modes[channel]
mode = self._modes.get(channel)
if mode[1] == 0x00:
if mode[0] == 0x17: # Get speeds
data.extend([0x06, 0x00])
Expand Down Expand Up @@ -114,16 +114,20 @@ def write(self, data):

if data[2] == 0x0d:
channel = data[3]
if self._modes[channel] is None:
if (self._is_reset or not self._awake) and self._modes.get(channel) is None:
self._modes[channel] = data[4:6]
self._is_reset = False
else:
raise ExpectationNotMet('Previous channel was not reset')
elif data[2] == 0x05 and data[3] == 0x01:
self._modes[data[4]] = None
self._is_reset = True
elif data[2] == 0x01 and data[3] == 0x03 and data[4] == 0x00:
self._awake = data[5] == 0x02
elif self._awake:
if data[2] == 0x06: # Write command
channel = data[3]
mode = self._modes[channel]
mode = self._modes.get(channel)
length = u16le_from(data[4:6])
data_type = data[8:10]
written_data = data[10:8+length]
Expand Down

0 comments on commit 40d8430

Please sign in to comment.