diff options
Diffstat (limited to 'klippy/extras/mcp4451.py')
-rw-r--r-- | klippy/extras/mcp4451.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/klippy/extras/mcp4451.py b/klippy/extras/mcp4451.py index 12d3b6a0..ab6e43ef 100644 --- a/klippy/extras/mcp4451.py +++ b/klippy/extras/mcp4451.py @@ -7,24 +7,26 @@ from . import bus WiperRegisters = [0x00, 0x01, 0x06, 0x07] + class mcp4451: def __init__(self, config): self.i2c = bus.MCU_I2C_from_config(config) i2c_addr = self.i2c.get_i2c_address() if i2c_addr < 44 or i2c_addr > 47: raise config.error("mcp4451 address must be between 44 and 47") - scale = config.getfloat('scale', 1., above=0.) + scale = config.getfloat("scale", 1.0, above=0.0) # Configure registers - self.set_register(0x04, 0xff) - self.set_register(0x0a, 0xff) + self.set_register(0x04, 0xFF) + self.set_register(0x0A, 0xFF) for i in range(4): - val = config.getfloat('wiper_%d' % (i,), None, - minval=0., maxval=scale) + val = config.getfloat("wiper_%d" % (i,), None, minval=0.0, maxval=scale) if val is not None: - val = int(val * 255. / scale + .5) + val = int(val * 255.0 / scale + 0.5) self.set_register(WiperRegisters[i], val) + def set_register(self, reg, value): self.i2c.i2c_write([(reg << 4) | ((value >> 8) & 0x03), value]) + def load_config_prefix(config): return mcp4451(config) |