gcode: Send proactive state messages

Send a g-code info message on printer state changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-12 18:46:25 -04:00
parent 91691afdcf
commit 094b9de69e
3 changed files with 13 additions and 6 deletions

View File

@ -147,7 +147,7 @@ In addition to common g-code commands, Klipper supports a few extended
commands - "status" and "restart" are examples of these commands. Use
the "help" command to get a list of other extended commands.
After Klipper reports that the "printer is ready" go on to the
After Klipper reports that the printer is ready go on to the
[config check document](Config_checks.md) to perform some basic checks
on the pin definitions in the config file.

View File

@ -106,8 +106,11 @@ class GCodeParser:
self.dump_debug()
if self.is_fileinput:
self.printer.request_exit('error_exit')
self._respond_state("Shutdown")
return
if state != 'ready':
if state == 'disconnect':
self._respond_state("Disconnect")
return
self.is_printer_ready = True
self.gcode_handlers = self.ready_gcode_handlers
@ -125,6 +128,7 @@ class GCodeParser:
self.fan = self.printer.lookup_object('fan', None)
if self.is_fileinput and self.fd_handle is None:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
self._respond_state("Ready")
def reset_last_position(self):
self.last_position = self.position_with_transform()
def dump_debug(self):
@ -287,6 +291,8 @@ class GCodeParser:
self.respond('!! %s' % (lines[0].strip(),))
if self.is_fileinput:
self.printer.request_exit('error_exit')
def _respond_state(self, state):
self.respond_info("Klipper state: %s" % (state,))
# Parameter parsing helpers
class sentinel: pass
def get_str(self, name, params, default=sentinel, parser=str,
@ -671,10 +677,11 @@ class GCodeParser:
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_state("Ready")
return
msg = self.printer.get_state_message()
self._respond_state("Not ready")
self.respond_error(msg)
cmd_HELP_when_not_ready = True
def cmd_HELP(self, params):

View File

@ -139,7 +139,7 @@ class Printer:
self.state_message = message_startup
self.is_shutdown = False
self.run_result = None
self.state_cb = []
self.state_cb = [gc.printer_state]
def get_start_args(self):
return self.start_args
def get_reactor(self):