respond: Use new GCodeCommand wrappers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-04-24 19:37:10 -04:00
parent 5a0b9d1ce8
commit 433c8c937a
1 changed files with 12 additions and 12 deletions

View File

@ -17,11 +17,11 @@ class HostResponder:
self.default_prefix = config.getchoice('default_type', respond_types, self.default_prefix = config.getchoice('default_type', respond_types,
'echo') 'echo')
self.default_prefix = config.get('default_prefix', self.default_prefix) self.default_prefix = config.get('default_prefix', self.default_prefix)
self.gcode = self.printer.lookup_object('gcode') gcode = self.printer.lookup_object('gcode')
self.gcode.register_command('M118', self.cmd_M118, True) gcode.register_command('M118', self.cmd_M118, True)
self.gcode.register_command('RESPOND', self.cmd_RESPOND, True) gcode.register_command('RESPOND', self.cmd_RESPOND, True)
def cmd_M118(self, params): def cmd_M118(self, gcmd):
msg = params['#original'] msg = gcmd.get_commandline()
umsg = msg.upper() umsg = msg.upper()
if not umsg.startswith('M118'): if not umsg.startswith('M118'):
# Parse out additional info if M118 recd during a print # Parse out additional info if M118 recd during a print
@ -32,21 +32,21 @@ class HostResponder:
msg = msg[5:] msg = msg[5:]
else: else:
msg = '' msg = ''
self.gcode.respond_raw("%s %s" % (self.default_prefix, msg)) gcmd.respond_raw("%s %s" % (self.default_prefix, msg))
def cmd_RESPOND(self, params): def cmd_RESPOND(self, gcmd):
respond_type = self.gcode.get_str('TYPE', params, None) respond_type = gcmd.get('TYPE', None)
prefix = self.default_prefix prefix = self.default_prefix
if(respond_type != None): if(respond_type != None):
respond_type = respond_type.lower() respond_type = respond_type.lower()
if(respond_type in respond_types): if(respond_type in respond_types):
prefix = respond_types[respond_type] prefix = respond_types[respond_type]
else: else:
raise self.gcode.error( raise gcmd.error(
"RESPOND TYPE '%s' is invalid. Must be one" "RESPOND TYPE '%s' is invalid. Must be one"
" of 'echo', 'command', or 'error'" % (respond_type,)) " of 'echo', 'command', or 'error'" % (respond_type,))
prefix = self.gcode.get_str('PREFIX', params, prefix) prefix = gcmd.get('PREFIX', prefix)
msg = self.gcode.get_str('MSG', params, '') msg = gcmd.get('MSG', '')
self.gcode.respond_raw("%s %s" %(prefix, msg)) gcmd.respond_raw("%s %s" % (prefix, msg))
def load_config(config): def load_config(config):
return HostResponder(config) return HostResponder(config)