mirror of https://github.com/Desuuuu/klipper.git
graph_temp_sensor: Add support for graphing sensor resistance
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
fc85675145
commit
9b2816477b
|
@ -77,6 +77,27 @@ def plot_adc_resolution(config, sensors):
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
|
def plot_resistance(config, sensors):
|
||||||
|
# Temperature list
|
||||||
|
all_temps = [float(i) for i in range(1, 351)]
|
||||||
|
# Build plot
|
||||||
|
fig, ax = matplotlib.pyplot.subplots()
|
||||||
|
pullup = config.getfloat('pullup_resistor', 0.)
|
||||||
|
ax.set_title("Temperature Sensor (pullup=%.0f)" % (pullup,))
|
||||||
|
ax.set_ylabel('Resistance (Ohms)')
|
||||||
|
for sensor in sensors:
|
||||||
|
sc = config.do_create_sensor(sensor)
|
||||||
|
adcs = [sc.calc_adc(t) for t in all_temps]
|
||||||
|
rs = [pullup * adc / (1.0 - adc) for adc in adcs]
|
||||||
|
ax.plot(all_temps, rs, label=sensor, alpha=0.6)
|
||||||
|
fontP = matplotlib.font_manager.FontProperties()
|
||||||
|
fontP.set_size('x-small')
|
||||||
|
ax.legend(loc='best', prop=fontP)
|
||||||
|
ax.set_xlabel('Temperature (C)')
|
||||||
|
ax.grid(True)
|
||||||
|
fig.tight_layout()
|
||||||
|
return fig
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Startup
|
# Startup
|
||||||
|
@ -111,6 +132,8 @@ def main():
|
||||||
default=5., help="pullup resistor")
|
default=5., help="pullup resistor")
|
||||||
opts.add_option("-s", "--sensors", type="string", dest="sensors",
|
opts.add_option("-s", "--sensors", type="string", dest="sensors",
|
||||||
default="", help="list of sensors (comma separated)")
|
default="", help="list of sensors (comma separated)")
|
||||||
|
opts.add_option("-r", "--resistance", action="store_true",
|
||||||
|
help="graph sensor resistance")
|
||||||
options, args = opts.parse_args()
|
options, args = opts.parse_args()
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
opts.error("Incorrect number of arguments")
|
opts.error("Incorrect number of arguments")
|
||||||
|
@ -129,7 +152,10 @@ def main():
|
||||||
|
|
||||||
# Draw graph
|
# Draw graph
|
||||||
setup_matplotlib(options.output is not None)
|
setup_matplotlib(options.output is not None)
|
||||||
fig = plot_adc_resolution(config, sensors)
|
if options.resistance:
|
||||||
|
fig = plot_resistance(config, sensors)
|
||||||
|
else:
|
||||||
|
fig = plot_adc_resolution(config, sensors)
|
||||||
|
|
||||||
# Show graph
|
# Show graph
|
||||||
if options.output is None:
|
if options.output is None:
|
||||||
|
|
Loading…
Reference in New Issue