diff --git a/klippy/extras/display/display.py b/klippy/extras/display/display.py index e83ed1a4..ce34a6bb 100644 --- a/klippy/extras/display/display.py +++ b/klippy/extras/display/display.py @@ -24,17 +24,20 @@ class PrinterLCD: # menu self.menu = menu.MenuManager(config, self.lcd_chip) # printer objects - self.gcode = self.toolhead = self.sdcard = None + self.toolhead = self.sdcard = None self.fan = self.extruder0 = self.extruder1 = self.heater_bed = None self.printer.register_event_handler("klippy:ready", self.handle_ready) # screen updating self.screen_update_timer = self.reactor.register_timer( self.screen_update_event) + # Register commands + self.gcode = self.printer.lookup_object('gcode') + self.gcode.register_command('M73', self.cmd_M73) + self.gcode.register_command('M117', self.cmd_M117) # Initialization def handle_ready(self): self.lcd_chip.init() # Load printer objects - self.gcode = self.printer.lookup_object('gcode') self.toolhead = self.printer.lookup_object('toolhead') self.sdcard = self.printer.lookup_object('virtual_sdcard', None) self.fan = self.printer.lookup_object('fan', None) @@ -45,8 +48,6 @@ class PrinterLCD: self.progress = None self.msg_time = None self.message = None - self.gcode.register_command('M73', self.cmd_M73) - self.gcode.register_command('M117', self.cmd_M117) # Start screen update timer self.reactor.update_timer(self.screen_update_timer, self.reactor.NOW) # Get menu instance diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py index 3818df7e..e34dbf74 100644 --- a/klippy/extras/gcode_macro.py +++ b/klippy/extras/gcode_macro.py @@ -13,11 +13,7 @@ class GCodeMacro: self.script = config.get('gcode') printer = config.get_printer() self.gcode = printer.lookup_object('gcode') - try: - self.gcode.register_command( - self.alias, self.cmd, desc=self.cmd_desc) - except self.gcode.error as e: - raise config.error(str(e)) + self.gcode.register_command(self.alias, self.cmd, desc=self.cmd_desc) self.in_script = False self.kwparams = { o[len(DEFAULT_PREFIX):].upper(): config.get(o) for o in config.get_prefix_options(DEFAULT_PREFIX) } diff --git a/klippy/extras/manual_probe.py b/klippy/extras/manual_probe.py index a1fc63cf..b816d6c8 100644 --- a/klippy/extras/manual_probe.py +++ b/klippy/extras/manual_probe.py @@ -58,7 +58,7 @@ class ManualProbeHelper: try: self.gcode.register_command('ACCEPT', self.cmd_ACCEPT, desc=self.cmd_ACCEPT_help) - except self.gcode.error as e: + except self.printer.config_error as e: self.gcode.respond_error( "Already in a manual Z probe. Use ABORT to abort it.") self.finalize_callback(None) diff --git a/klippy/extras/tsl1401cl_filament_width_sensor.py b/klippy/extras/tsl1401cl_filament_width_sensor.py index 06530bf8..fa1ac26d 100644 --- a/klippy/extras/tsl1401cl_filament_width_sensor.py +++ b/klippy/extras/tsl1401cl_filament_width_sensor.py @@ -24,7 +24,7 @@ class FilamentWidthSensor: self.filament_array = [] self.lastFilamentWidthReading = 0 # printer objects - self.gcode = self.toolhead = self.ppins = self.mcu_adc = None + self.toolhead = self.ppins = self.mcu_adc = None self.printer.register_event_handler("klippy:ready", self.handle_ready) # Start adc self.ppins = self.printer.lookup_object('pins') @@ -34,17 +34,18 @@ class FilamentWidthSensor: # extrude factor updating self.extrude_factor_update_timer = self.reactor.register_timer( self.extrude_factor_update_event) - - # Initialization - def handle_ready(self): - # Load printer objects + # Register commands self.gcode = self.printer.lookup_object('gcode') - self.toolhead = self.printer.lookup_object('toolhead') self.gcode.register_command('QUERY_FILAMENT_WIDTH', self.cmd_M407) self.gcode.register_command('RESET_FILAMENT_WIDTH_SENSOR', self.cmd_ClearFilamentArray) self.gcode.register_command('DISABLE_FILAMENT_WIDTH_SENSOR', self.cmd_M406) self.gcode.register_command('ENABLE_FILAMENT_WIDTH_SENSOR', self.cmd_M405) + # Initialization + def handle_ready(self): + # Load printer objects + self.toolhead = self.printer.lookup_object('toolhead') + # Start extrude factor update timer self.reactor.update_timer(self.extrude_factor_update_timer, self.reactor.NOW) diff --git a/klippy/gcode.py b/klippy/gcode.py index 0506e715..cc419b4b 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -67,7 +67,8 @@ class GCodeParser: del self.base_gcode_handlers[cmd] return if cmd in self.ready_gcode_handlers: - raise error("gcode command %s already registered" % (cmd,)) + raise self.printer.config_error( + "gcode command %s already registered" % (cmd,)) if not (len(cmd) >= 2 and not cmd[0].isupper() and cmd[1].isdigit()): origfunc = func func = lambda params: origfunc(self.get_extended_params(params)) @@ -83,11 +84,13 @@ class GCodeParser: self.mux_commands[cmd] = prev = (key, {}) prev_key, prev_values = prev if prev_key != key: - raise error("mux command %s %s %s may have only one key (%s)" % ( - cmd, key, value, prev_key)) + raise self.printer.config_error( + "mux command %s %s %s may have only one key (%s)" % ( + cmd, key, value, prev_key)) if value in prev_values: - raise error("mux command %s %s %s already registered (%s)" % ( - cmd, key, value, prev_values)) + raise self.printer.config_error( + "mux command %s %s %s already registered (%s)" % ( + cmd, key, value, prev_values)) prev_values[value] = func def set_move_transform(self, transform): if self.move_transform is not None: @@ -328,16 +331,16 @@ class GCodeParser: raise error("Error on '%s': unable to parse %s" % ( params['#original'], params[name])) if minval is not None and value < minval: - raise self.error("Error on '%s': %s must have minimum of %s" % ( + raise error("Error on '%s': %s must have minimum of %s" % ( params['#original'], name, minval)) if maxval is not None and value > maxval: - raise self.error("Error on '%s': %s must have maximum of %s" % ( + raise error("Error on '%s': %s must have maximum of %s" % ( params['#original'], name, maxval)) if above is not None and value <= above: - raise self.error("Error on '%s': %s must be above %s" % ( + raise error("Error on '%s': %s must be above %s" % ( params['#original'], name, above)) if below is not None and value >= below: - raise self.error("Error on '%s': %s must be below %s" % ( + raise error("Error on '%s': %s must be below %s" % ( params['#original'], name, below)) return value def get_int(self, name, params, default=sentinel, minval=None, maxval=None):