aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/query_adc.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-11-07 19:23:20 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-11-07 19:28:27 -0500
commit0bfb655f665c2f29efa14c28d4dc5c47f151d09a (patch)
treea0b3b006ef33c1db0d65c3459ce10c7a2d757585 /klippy/extras/query_adc.py
parent124ba12485c7f4720959270b3151a5ebbcb7cf6b (diff)
downloadkutter-0bfb655f665c2f29efa14c28d4dc5c47f151d09a.tar.gz
kutter-0bfb655f665c2f29efa14c28d4dc5c47f151d09a.tar.xz
kutter-0bfb655f665c2f29efa14c28d4dc5c47f151d09a.zip
query_adc: Add a new module to help query and debug analog pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/query_adc.py')
-rw-r--r--klippy/extras/query_adc.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/klippy/extras/query_adc.py b/klippy/extras/query_adc.py
new file mode 100644
index 00000000..eb065396
--- /dev/null
+++ b/klippy/extras/query_adc.py
@@ -0,0 +1,36 @@
+# Utility for querying the current state of adc pins
+#
+# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+
+class QueryADC:
+ def __init__(self, config):
+ self.printer = config.get_printer()
+ self.adc = {}
+ gcode = self.printer.lookup_object('gcode')
+ gcode.register_command("QUERY_ADC", self.cmd_QUERY_ADC,
+ desc=self.cmd_QUERY_ADC_help)
+ def register_adc(self, name, mcu_adc):
+ self.adc[name] = mcu_adc
+ cmd_QUERY_ADC_help = "Report the last value of an analog pin"
+ def cmd_QUERY_ADC(self, params):
+ gcode = self.printer.lookup_object('gcode')
+ name = gcode.get_str('NAME', params, None)
+ if name not in self.adc:
+ objs = ['"%s"' % (n,) for n in sorted(self.adc.keys())]
+ msg = "Available ADC objects: %s" % (', '.join(objs),)
+ gcode.respond_info(msg)
+ return
+ value, timestamp = self.adc[name].get_last_value()
+ msg = 'ADC object "%s" has value %.6f (timestamp %.3f)' % (
+ name, value, timestamp)
+ pullup = gcode.get_float('PULLUP', params, None, above=0.)
+ if pullup is not None:
+ v = max(.00001, min(.99999, value))
+ r = pullup * v / (1.0 - v)
+ msg += "\n resistance %.3f (with %.0f pullup)" % (r, pullup)
+ gcode.respond_info(msg)
+
+def load_config(config):
+ return QueryADC(config)