endstop_phase: Use new GCodeCommand wrappers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
153c1cbe60
commit
947569d347
|
@ -115,14 +115,14 @@ class EndstopPhase:
|
||||||
class EndstopPhases:
|
class EndstopPhases:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
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 = self.printer.lookup_object('gcode')
|
||||||
self.gcode.register_command("ENDSTOP_PHASE_CALIBRATE",
|
self.gcode.register_command("ENDSTOP_PHASE_CALIBRATE",
|
||||||
self.cmd_ENDSTOP_PHASE_CALIBRATE,
|
self.cmd_ENDSTOP_PHASE_CALIBRATE,
|
||||||
desc=self.cmd_ENDSTOP_PHASE_CALIBRATE_help)
|
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):
|
def lookup_rail(self, stepper, stepper_name):
|
||||||
mod_name = "endstop_phase %s" % (stepper_name,)
|
mod_name = "endstop_phase %s" % (stepper_name,)
|
||||||
m = self.printer.lookup_object(mod_name, None)
|
m = self.printer.lookup_object(mod_name, None)
|
||||||
|
@ -155,21 +155,21 @@ class EndstopPhases:
|
||||||
self.tracking[stepper_name] = info
|
self.tracking[stepper_name] = info
|
||||||
self.update_rail(self.tracking[stepper_name], stepper)
|
self.update_rail(self.tracking[stepper_name], stepper)
|
||||||
cmd_ENDSTOP_PHASE_CALIBRATE_help = "Calibrate stepper phase"
|
cmd_ENDSTOP_PHASE_CALIBRATE_help = "Calibrate stepper phase"
|
||||||
def cmd_ENDSTOP_PHASE_CALIBRATE(self, params):
|
def cmd_ENDSTOP_PHASE_CALIBRATE(self, gcmd):
|
||||||
stepper_name = self.gcode.get_str('STEPPER', params, None)
|
stepper_name = gcmd.get('STEPPER', None)
|
||||||
if stepper_name is None:
|
if stepper_name is None:
|
||||||
self.report_stats()
|
self.report_stats()
|
||||||
return
|
return
|
||||||
info = self.tracking.get(stepper_name)
|
info = self.tracking.get(stepper_name)
|
||||||
if info is None:
|
if info is None:
|
||||||
raise self.gcode.error("Stats not available for stepper %s" % (
|
raise gcmd.error("Stats not available for stepper %s"
|
||||||
stepper_name,))
|
% (stepper_name,))
|
||||||
endstop_phase = self.generate_stats(stepper_name, info)
|
endstop_phase = self.generate_stats(stepper_name, info)
|
||||||
configfile = self.printer.lookup_object('configfile')
|
configfile = self.printer.lookup_object('configfile')
|
||||||
section = 'endstop_phase %s' % stepper_name
|
section = 'endstop_phase %s' % stepper_name
|
||||||
configfile.remove_section(section)
|
configfile.remove_section(section)
|
||||||
configfile.set(section, "endstop_phase", endstop_phase)
|
configfile.set(section, "endstop_phase", endstop_phase)
|
||||||
self.gcode.respond_info(
|
gcmd.respond_info(
|
||||||
"The SAVE_CONFIG command will update the printer config\n"
|
"The SAVE_CONFIG command will update the printer config\n"
|
||||||
"file with these parameters and restart the printer.")
|
"file with these parameters and restart the printer.")
|
||||||
def generate_stats(self, stepper_name, info):
|
def generate_stats(self, stepper_name, info):
|
||||||
|
@ -189,8 +189,8 @@ class EndstopPhases:
|
||||||
if wph[j]]
|
if wph[j]]
|
||||||
best_phase = best % phases
|
best_phase = best % phases
|
||||||
lo, hi = found[0] % phases, found[-1] % phases
|
lo, hi = found[0] % phases, found[-1] % phases
|
||||||
self.gcode.respond_info("%s: endstop_phase=%d (range %d to %d)" % (
|
self.gcode.respond_info("%s: endstop_phase=%d (range %d to %d)"
|
||||||
stepper_name, best_phase, lo, hi))
|
% (stepper_name, best_phase, lo, hi))
|
||||||
return best_phase
|
return best_phase
|
||||||
def report_stats(self):
|
def report_stats(self):
|
||||||
if not self.tracking:
|
if not self.tracking:
|
||||||
|
|
Loading…
Reference in New Issue