gcode: Add a "STATUS" command
Add a status command that will report the current printer status. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
4f087c331c
commit
219796ef4e
|
@ -45,7 +45,8 @@ class GCodeParser:
|
||||||
def build_handlers(self):
|
def build_handlers(self):
|
||||||
handlers = ['G1', 'G4', 'G20', 'G21', 'G28', 'G90', 'G91', 'G92',
|
handlers = ['G1', 'G4', 'G20', 'G21', 'G28', 'G90', 'G91', 'G92',
|
||||||
'M18', 'M82', 'M83', 'M105', 'M110', 'M112', 'M114', 'M206',
|
'M18', 'M82', 'M83', 'M105', 'M110', 'M112', 'M114', 'M206',
|
||||||
'HELP', 'QUERY_ENDSTOPS', 'RESTART', 'CLEAR_SHUTDOWN']
|
'HELP', 'QUERY_ENDSTOPS', 'RESTART', 'CLEAR_SHUTDOWN',
|
||||||
|
'STATUS']
|
||||||
if self.heater_nozzle is not None:
|
if self.heater_nozzle is not None:
|
||||||
handlers.extend(['M104', 'M109', 'PID_TUNE'])
|
handlers.extend(['M104', 'M109', 'PID_TUNE'])
|
||||||
if self.heater_bed is not None:
|
if self.heater_bed is not None:
|
||||||
|
@ -150,10 +151,13 @@ class GCodeParser:
|
||||||
if self.is_fileinput:
|
if self.is_fileinput:
|
||||||
return
|
return
|
||||||
os.write(self.fd, msg+"\n")
|
os.write(self.fd, msg+"\n")
|
||||||
|
def respond_info(self, msg):
|
||||||
|
lines = [l.strip() for l in msg.strip().split('\n')]
|
||||||
|
self.respond("// " + "\n// ".join(lines))
|
||||||
def respond_error(self, msg):
|
def respond_error(self, msg):
|
||||||
lines = msg.strip().split('\n')
|
lines = msg.strip().split('\n')
|
||||||
for line in lines[:-1]:
|
if len(lines) > 1:
|
||||||
self.respond('// %s' % (line.strip(),))
|
self.respond_info("\n".join(lines[:-1]))
|
||||||
self.respond('!! %s' % (lines[-1].strip(),))
|
self.respond('!! %s' % (lines[-1].strip(),))
|
||||||
# Temperature wrappers
|
# Temperature wrappers
|
||||||
def get_temp(self):
|
def get_temp(self):
|
||||||
|
@ -342,7 +346,7 @@ class GCodeParser:
|
||||||
heater.start_auto_tune(temp)
|
heater.start_auto_tune(temp)
|
||||||
self.bg_temp(heater)
|
self.bg_temp(heater)
|
||||||
cmd_CLEAR_SHUTDOWN_when_not_ready = True
|
cmd_CLEAR_SHUTDOWN_when_not_ready = True
|
||||||
cmd_CLEAR_SHUTDOWN_help = "Clear firmware shutdown and restart"
|
cmd_CLEAR_SHUTDOWN_help = "Clear a firmware shutdown and restart"
|
||||||
def cmd_CLEAR_SHUTDOWN(self, params):
|
def cmd_CLEAR_SHUTDOWN(self, params):
|
||||||
if self.toolhead is None:
|
if self.toolhead is None:
|
||||||
self.cmd_default(params)
|
self.cmd_default(params)
|
||||||
|
@ -353,11 +357,22 @@ class GCodeParser:
|
||||||
cmd_RESTART_help = "Reload config file and restart host software"
|
cmd_RESTART_help = "Reload config file and restart host software"
|
||||||
def cmd_RESTART(self, params):
|
def cmd_RESTART(self, params):
|
||||||
self.printer.request_restart()
|
self.printer.request_restart()
|
||||||
|
cmd_STATUS_when_not_ready = True
|
||||||
|
cmd_STATUS_help = "Report the printer status"
|
||||||
|
def cmd_STATUS(self, params):
|
||||||
|
msg = self.printer.get_state_message()
|
||||||
|
if self.is_printer_ready:
|
||||||
|
self.respond_info(msg)
|
||||||
|
else:
|
||||||
|
self.respond_error(msg)
|
||||||
cmd_HELP_when_not_ready = True
|
cmd_HELP_when_not_ready = True
|
||||||
def cmd_HELP(self, params):
|
def cmd_HELP(self, params):
|
||||||
cmdhelp = ["// Available extended commands:"]
|
cmdhelp = []
|
||||||
|
if not self.is_printer_ready:
|
||||||
|
cmdhelp.append("Printer is not ready - not all commands available.")
|
||||||
|
cmdhelp.append("Available extended commands:")
|
||||||
for cmd in self.gcode_handlers:
|
for cmd in self.gcode_handlers:
|
||||||
desc = getattr(self, 'cmd_'+cmd+'_help', None)
|
desc = getattr(self, 'cmd_'+cmd+'_help', None)
|
||||||
if desc is not None:
|
if desc is not None:
|
||||||
cmdhelp.append("%-10s: %s" % (cmd, desc))
|
cmdhelp.append("%-10s: %s" % (cmd, desc))
|
||||||
self.respond("\n// ".join(cmdhelp))
|
self.respond_info("\n".join(cmdhelp))
|
||||||
|
|
|
@ -153,7 +153,7 @@ class Printer:
|
||||||
self.build_config()
|
self.build_config()
|
||||||
self.validate_config()
|
self.validate_config()
|
||||||
self.gcode.set_printer_ready(True)
|
self.gcode.set_printer_ready(True)
|
||||||
self.state_message = "Running"
|
self.state_message = "Printer is ready"
|
||||||
except ConfigParser.Error, e:
|
except ConfigParser.Error, e:
|
||||||
logging.exception("Config error")
|
logging.exception("Config error")
|
||||||
self.state_message = "%s%s" % (str(e), message_restart)
|
self.state_message = "%s%s" % (str(e), message_restart)
|
||||||
|
|
Loading…
Reference in New Issue