gcode: Raise a config error on invalid register_command()
Raise a printer.config_error() on an invalid register_command() call. This error is easier to handle for the vast majority of callers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
276d5a1436
commit
b260eb9168
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,10 +84,12 @@ 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)" % (
|
||||
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)" % (
|
||||
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):
|
||||
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue