2018-01-20 06:14:52 +01:00
|
|
|
# AD5206 digipot code
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
import pins
|
|
|
|
|
|
|
|
class ad5206:
|
|
|
|
def __init__(self, config):
|
|
|
|
printer = config.get_printer()
|
|
|
|
enable_pin_params = pins.get_printer_pins(printer).lookup_pin(
|
|
|
|
'digital_out', config.get('enable_pin'))
|
2018-02-18 05:18:10 +01:00
|
|
|
if enable_pin_params['invert']:
|
|
|
|
raise pins.error("ad5206 can not invert pin")
|
2018-01-20 06:14:52 +01:00
|
|
|
self.mcu = enable_pin_params['chip']
|
|
|
|
self.pin = enable_pin_params['pin']
|
|
|
|
self.mcu.add_config_object(self)
|
|
|
|
scale = config.getfloat('scale', 1., above=0.)
|
|
|
|
self.channels = [None] * 6
|
|
|
|
for i in range(len(self.channels)):
|
|
|
|
val = config.getfloat('channel_%d' % (i+1,), None,
|
|
|
|
minval=0., maxval=scale)
|
|
|
|
if val is not None:
|
|
|
|
self.channels[i] = int(val * 256. / scale + .5)
|
|
|
|
def build_config(self):
|
|
|
|
for i, val in enumerate(self.channels):
|
|
|
|
if val is not None:
|
|
|
|
self.mcu.add_config_cmd(
|
|
|
|
"send_spi_message pin=%s msg=%02x%02x" % (self.pin, i, val))
|
|
|
|
|
2018-02-03 18:53:11 +01:00
|
|
|
def load_config_prefix(config):
|
2018-01-20 06:14:52 +01:00
|
|
|
return ad5206(config)
|