Skip to content
Snippets Groups Projects
Commit b4bd3231 authored by Samuel Tardieu's avatar Samuel Tardieu
Browse files

Check WHO_AM_I at start

parent 5d34f19c
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,10 @@ class FirmwareVersionMismatch(Exception):
pass
class WhoAmIMismatch(Exception):
pass
class Controller:
I2C_ADDR = 0x57
......@@ -31,6 +35,7 @@ class Controller:
self.i2c_bus = i2c_bus
self.i2c = smbus.SMBus(self.i2c_bus)
self.check_who_am_i()
self.check_firmware_version()
def _read(self, command, n, unpack_spec) -> tuple:
......@@ -47,6 +52,16 @@ class Controller:
should return the same value as Controller.I2C_ADDR."""
return self._read(self.WHO_AM_I, 1, "B")[0]
def check_who_am_i(self):
"""Check that the device answers to WHO_AM_I is correct."""
w = self.who_am_i()
if w != self.I2C_ADDR:
error = (
f"WHO_AM_I returns {w:#04x} "
f"instead of the expected {self.I2C_ADDR:#04x}"
)
raise WhoAmIMismatch(error)
def set_max_percentage(self, percent: float):
"""Set the maximum percentage of power which will be used
(between 1 and 100) for further speed instructions. This has
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment