adc_temperature: Support defining custom sensors in the config file
Allow the user to define a custom sensor with their own set of temperature/voltage measurements. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
c463893a5e
commit
6466af6313
|
@ -395,7 +395,7 @@
|
||||||
|
|
||||||
|
|
||||||
# Custom thermistors (one may define any number of sections with a
|
# Custom thermistors (one may define any number of sections with a
|
||||||
# "thermistor" prefix). A custom thermistor may be used in the
|
# "thermistor" prefix). A custom thermistor may be used in the
|
||||||
# sensor_type field of a heater config section. (For example, if one
|
# sensor_type field of a heater config section. (For example, if one
|
||||||
# defines a "[thermistor my_thermistor]" section then one may use a
|
# defines a "[thermistor my_thermistor]" section then one may use a
|
||||||
# "sensor_type: my_thermistor" when defining a heater.) Be sure to
|
# "sensor_type: my_thermistor" when defining a heater.) Be sure to
|
||||||
|
@ -410,7 +410,7 @@
|
||||||
#resistance3:
|
#resistance3:
|
||||||
# Three resistance measurements (in Ohms) at the given temperatures
|
# Three resistance measurements (in Ohms) at the given temperatures
|
||||||
# (in Celsius). The three measurements will be used to calculate the
|
# (in Celsius). The three measurements will be used to calculate the
|
||||||
# Steinhart-Hart coefficients for the thermistor. These parameters
|
# Steinhart-Hart coefficients for the thermistor. These parameters
|
||||||
# must be provided when using Steinhart-Hart to define the
|
# must be provided when using Steinhart-Hart to define the
|
||||||
# thermistor.
|
# thermistor.
|
||||||
#beta:
|
#beta:
|
||||||
|
@ -419,6 +419,28 @@
|
||||||
# provided when using "beta" to define the thermistor.
|
# provided when using "beta" to define the thermistor.
|
||||||
|
|
||||||
|
|
||||||
|
# Custom ADC temperature sensors (one may define any number of
|
||||||
|
# sections with an "adc_temperature" prefix). This allows one to
|
||||||
|
# define a custom temperature sensor that measures a voltage on an
|
||||||
|
# Analog to Digital Converter (ADC) pin and uses linear interpolation
|
||||||
|
# between a set of configured temperature/voltage measurements to
|
||||||
|
# determine the temperature. The resulting sensor can be used as a
|
||||||
|
# sensor_type in a heater section. (For example, if one defines a
|
||||||
|
# "[adc_temperature my_sensor]" section then one may use a
|
||||||
|
# "sensor_type: my_sensor" when defining a heater.) Be sure to place
|
||||||
|
# the sensor section in the config file above its first use in a
|
||||||
|
# heater section.
|
||||||
|
#[adc_temperature my_sensor]
|
||||||
|
#temperature1:
|
||||||
|
#voltage1:
|
||||||
|
#temperature2:
|
||||||
|
#voltage2:
|
||||||
|
#...
|
||||||
|
# A set of temperatures (in Celsius) and voltages (in Ohms) to use
|
||||||
|
# as reference when converting a temperature. At least two
|
||||||
|
# measurements must be provided.
|
||||||
|
|
||||||
|
|
||||||
# Replicape support - see the generic-replicape.cfg file for further
|
# Replicape support - see the generic-replicape.cfg file for further
|
||||||
# details.
|
# details.
|
||||||
#[replicape]
|
#[replicape]
|
||||||
|
|
|
@ -72,6 +72,20 @@ class Linear:
|
||||||
gain, offset = self.slope_samples[pos]
|
gain, offset = self.slope_samples[pos]
|
||||||
return (temp - offset) / gain
|
return (temp - offset) / gain
|
||||||
|
|
||||||
|
# Custom defined sensors from the config file
|
||||||
|
class CustomLinear:
|
||||||
|
def __init__(self, config):
|
||||||
|
self.name = " ".join(config.get_name().split()[1:])
|
||||||
|
self.params = []
|
||||||
|
for i in range(1, 1000):
|
||||||
|
t = config.getfloat("temperature%d" % (i,), None)
|
||||||
|
if t is None:
|
||||||
|
break
|
||||||
|
v = config.getfloat("voltage%d" % (i,))
|
||||||
|
self.params.append((t, v))
|
||||||
|
def create(self, config):
|
||||||
|
return Linear(config, self.params)
|
||||||
|
|
||||||
AD595 = [
|
AD595 = [
|
||||||
(0., .0027), (10., .101), (20., .200), (25., .250), (30., .300), (40., .401),
|
(0., .0027), (10., .101), (20., .200), (25., .250), (30., .300), (40., .401),
|
||||||
(50., .503), (60., .605), (80., .810), (100., 1.015), (120., 1.219),
|
(50., .503), (60., .605), (80., .810), (100., 1.015), (120., 1.219),
|
||||||
|
@ -99,3 +113,8 @@ def load_config(config):
|
||||||
for sensor_type, params in [("AD595", AD595), ("PT100 INA826", PT100)]:
|
for sensor_type, params in [("AD595", AD595), ("PT100 INA826", PT100)]:
|
||||||
func = (lambda config, params=params: Linear(config, params))
|
func = (lambda config, params=params: Linear(config, params))
|
||||||
pheater.add_sensor(sensor_type, func)
|
pheater.add_sensor(sensor_type, func)
|
||||||
|
|
||||||
|
def load_config_prefix(config):
|
||||||
|
linear = CustomLinear(config)
|
||||||
|
pheater = config.get_printer().lookup_object("heater")
|
||||||
|
pheater.add_sensor(linear.name, linear.create)
|
||||||
|
|
Loading…
Reference in New Issue