Skip to content

Commit

Permalink
Fix error with new firmware version by changing command flow
Browse files Browse the repository at this point in the history
    Inside _send_command, read until response doesn't start by 0x00
  • Loading branch information
Meriemi-git committed Aug 31, 2022
1 parent 7817639 commit 4cc4069
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions liquidctl/driver/commander_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ def _get_temps(self):
return temps

def _read_data(self, mode, data_type):
self._send_command(_CMD_RESET)
self._send_command(_CMD_SET_MODE, mode)
raw_data = self._send_command(_CMD_READ)

self._send_command(_CMD_RESET)
if tuple(raw_data[3:5]) != data_type:
raise ExpectationNotMet('device returned incorrect data type')

Expand All @@ -227,7 +226,10 @@ def _send_command(self, command, data=()):
self.device.clear_enqueued_reports()
self.device.write(buf)

buf = bytes(self.device.read(_RESPONSE_LENGTH))
res = self.device.read(_RESPONSE_LENGTH)
while res[0] != 0x00:
res = self.device.read(_RESPONSE_LENGTH)
buf = bytes(res)
assert buf[1] == command[0], 'response does not match command'
return buf

Expand All @@ -242,7 +244,6 @@ def _wake_device_context(self):
def _write_data(self, mode, data_type, data):
self._read_data(mode, data_type) # Will ensure we are writing the correct data type to avoid breakage

self._send_command(_CMD_RESET)
self._send_command(_CMD_SET_MODE, mode)

buf = bytearray(len(data) + len(data_type) + 4)
Expand All @@ -251,6 +252,7 @@ def _write_data(self, mode, data_type, data):
buf[4 + len(data_type):] = data

self._send_command(_CMD_WRITE, buf)
self._send_command(_CMD_RESET)

def _fan_to_channel(self, fan):
if self._has_pump:
Expand Down

0 comments on commit 4cc4069

Please sign in to comment.