query_adc: Use new GCodeCommand wrappers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a13e681b2e
commit
1f64ca4fd9
|
@ -14,23 +14,22 @@ class QueryADC:
|
||||||
def register_adc(self, name, mcu_adc):
|
def register_adc(self, name, mcu_adc):
|
||||||
self.adc[name] = mcu_adc
|
self.adc[name] = mcu_adc
|
||||||
cmd_QUERY_ADC_help = "Report the last value of an analog pin"
|
cmd_QUERY_ADC_help = "Report the last value of an analog pin"
|
||||||
def cmd_QUERY_ADC(self, params):
|
def cmd_QUERY_ADC(self, gcmd):
|
||||||
gcode = self.printer.lookup_object('gcode')
|
name = gcmd.get('NAME', None)
|
||||||
name = gcode.get_str('NAME', params, None)
|
|
||||||
if name not in self.adc:
|
if name not in self.adc:
|
||||||
objs = ['"%s"' % (n,) for n in sorted(self.adc.keys())]
|
objs = ['"%s"' % (n,) for n in sorted(self.adc.keys())]
|
||||||
msg = "Available ADC objects: %s" % (', '.join(objs),)
|
msg = "Available ADC objects: %s" % (', '.join(objs),)
|
||||||
gcode.respond_info(msg)
|
gcmd.respond_info(msg)
|
||||||
return
|
return
|
||||||
value, timestamp = self.adc[name].get_last_value()
|
value, timestamp = self.adc[name].get_last_value()
|
||||||
msg = 'ADC object "%s" has value %.6f (timestamp %.3f)' % (
|
msg = 'ADC object "%s" has value %.6f (timestamp %.3f)' % (
|
||||||
name, value, timestamp)
|
name, value, timestamp)
|
||||||
pullup = gcode.get_float('PULLUP', params, None, above=0.)
|
pullup = gcmd.get_float('PULLUP', None, above=0.)
|
||||||
if pullup is not None:
|
if pullup is not None:
|
||||||
v = max(.00001, min(.99999, value))
|
v = max(.00001, min(.99999, value))
|
||||||
r = pullup * v / (1.0 - v)
|
r = pullup * v / (1.0 - v)
|
||||||
msg += "\n resistance %.3f (with %.0f pullup)" % (r, pullup)
|
msg += "\n resistance %.3f (with %.0f pullup)" % (r, pullup)
|
||||||
gcode.respond_info(msg)
|
gcmd.respond_info(msg)
|
||||||
|
|
||||||
def load_config(config):
|
def load_config(config):
|
||||||
return QueryADC(config)
|
return QueryADC(config)
|
||||||
|
|
Loading…
Reference in New Issue