gcode: Add action_x() callables to get_status()

Add action_respond_info(), action_respond_error(), and
action_emergency_stop() callables to the get_status() return
dictionary.  This allows gcode macros to directly invoke these
actions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-05-28 11:07:11 -04:00 committed by KevinOConnor
parent ac8f6dfe20
commit 4ccc218b06
1 changed files with 13 additions and 1 deletions

View File

@ -103,6 +103,15 @@ class GCodeParser:
self.position_with_transform = transform.get_position self.position_with_transform = transform.get_position
def stats(self, eventtime): def stats(self, eventtime):
return False, "gcodein=%d" % (self.bytes_read,) return False, "gcodein=%d" % (self.bytes_read,)
def _action_emergency_stop(self, msg="action_emergency_stop"):
self.printer.invoke_shutdown("Shutdown due to %s" % (msg,))
return ""
def _action_respond_info(self, msg):
self.respond_info(msg)
return ""
def _action_respond_error(self, msg):
self.respond_error(msg)
return ""
def _get_gcode_position(self): def _get_gcode_position(self):
p = [lp - bp for lp, bp in zip(self.last_position, self.base_position)] p = [lp - bp for lp, bp in zip(self.last_position, self.base_position)]
p[3] /= self.extrude_factor p[3] /= self.extrude_factor
@ -134,7 +143,10 @@ class GCodeParser:
'base_epos': self.base_position[3], 'base_epos': self.base_position[3],
'homing_xpos': self.homing_position[0], 'homing_xpos': self.homing_position[0],
'homing_ypos': self.homing_position[1], 'homing_ypos': self.homing_position[1],
'homing_zpos': self.homing_position[2] 'homing_zpos': self.homing_position[2],
'action_respond_info': self._action_respond_info,
'action_respond_error': self._action_respond_error,
'action_emergency_stop': self._action_emergency_stop,
} }
def _handle_shutdown(self): def _handle_shutdown(self):
if not self.is_printer_ready: if not self.is_printer_ready: