gcode_macro: 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:26:43 -04:00
parent fb16e8810b
commit a13e681b2e
1 changed files with 5 additions and 7 deletions

View File

@ -138,20 +138,18 @@ class GCodeMacro:
def get_status(self, eventtime): def get_status(self, eventtime):
return dict(self.variables) return dict(self.variables)
cmd_SET_GCODE_VARIABLE_help = "Set the value of a G-Code macro variable" cmd_SET_GCODE_VARIABLE_help = "Set the value of a G-Code macro variable"
def cmd_SET_GCODE_VARIABLE(self, params): def cmd_SET_GCODE_VARIABLE(self, gcmd):
variable = self.gcode.get_str('VARIABLE', params) variable = gcmd.get('VARIABLE')
value = self.gcode.get_str('VALUE', params) value = gcmd.get('VALUE')
if variable not in self.variables: if variable not in self.variables:
if variable in self.kwparams: if variable in self.kwparams:
self.kwparams[variable] = value self.kwparams[variable] = value
return return
raise self.gcode.error("Unknown gcode_macro variable '%s'" % ( raise gcmd.error("Unknown gcode_macro variable '%s'" % (variable,))
variable,))
try: try:
literal = ast.literal_eval(value) literal = ast.literal_eval(value)
except ValueError as e: except ValueError as e:
raise self.gcode.error("Unable to parse '%s' as a literal" % ( raise gcmd.error("Unable to parse '%s' as a literal" % (value,))
value,))
self.variables[variable] = literal self.variables[variable] = literal
cmd_desc = "G-Code macro" cmd_desc = "G-Code macro"
def cmd(self, gcmd): def cmd(self, gcmd):