endstop_phase: Use new GCodeCommand wrappers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-04-24 22:41:23 -04:00
parent 153c1cbe60
commit 947569d347
1 changed files with 11 additions and 11 deletions

View File

@ -115,14 +115,14 @@ class EndstopPhase:
class EndstopPhases:
def __init__(self, config):
self.printer = config.get_printer()
self.tracking = {}
# Register handlers
self.printer.register_event_handler("homing:home_rails_end",
self.handle_home_rails_end)
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("ENDSTOP_PHASE_CALIBRATE",
self.cmd_ENDSTOP_PHASE_CALIBRATE,
desc=self.cmd_ENDSTOP_PHASE_CALIBRATE_help)
self.tracking = {}
# Register event handler
self.printer.register_event_handler(
"homing:home_rails_end", self.handle_home_rails_end)
def lookup_rail(self, stepper, stepper_name):
mod_name = "endstop_phase %s" % (stepper_name,)
m = self.printer.lookup_object(mod_name, None)
@ -155,21 +155,21 @@ class EndstopPhases:
self.tracking[stepper_name] = info
self.update_rail(self.tracking[stepper_name], stepper)
cmd_ENDSTOP_PHASE_CALIBRATE_help = "Calibrate stepper phase"
def cmd_ENDSTOP_PHASE_CALIBRATE(self, params):
stepper_name = self.gcode.get_str('STEPPER', params, None)
def cmd_ENDSTOP_PHASE_CALIBRATE(self, gcmd):
stepper_name = gcmd.get('STEPPER', None)
if stepper_name is None:
self.report_stats()
return
info = self.tracking.get(stepper_name)
if info is None:
raise self.gcode.error("Stats not available for stepper %s" % (
stepper_name,))
raise gcmd.error("Stats not available for stepper %s"
% (stepper_name,))
endstop_phase = self.generate_stats(stepper_name, info)
configfile = self.printer.lookup_object('configfile')
section = 'endstop_phase %s' % stepper_name
configfile.remove_section(section)
configfile.set(section, "endstop_phase", endstop_phase)
self.gcode.respond_info(
gcmd.respond_info(
"The SAVE_CONFIG command will update the printer config\n"
"file with these parameters and restart the printer.")
def generate_stats(self, stepper_name, info):
@ -189,8 +189,8 @@ class EndstopPhases:
if wph[j]]
best_phase = best % phases
lo, hi = found[0] % phases, found[-1] % phases
self.gcode.respond_info("%s: endstop_phase=%d (range %d to %d)" % (
stepper_name, best_phase, lo, hi))
self.gcode.respond_info("%s: endstop_phase=%d (range %d to %d)"
% (stepper_name, best_phase, lo, hi))
return best_phase
def report_stats(self):
if not self.tracking: