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 223b11f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion liquidctl/driver/commander_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def initialize(self, **kwargs):
fw_version = (res[3], res[4], res[5])

status = [('Firmware version', '{}.{}.{}'.format(*fw_version), '')]

# Get LEDs per fan
res = self._read_data(_MODE_LED_COUNT, _DATA_TYPE_LED_COUNT)
num_devices = res[0]
Expand Down 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
10 changes: 7 additions & 3 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 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[channel] is None:
self._modes[channel] = data[4:6]
self._is_reset = False
else:
raise NotImplementedError('Already set channel')
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 223b11f

Please sign in to comment.