gcode: Move definition of CommandError and Coord from homing.py to gcode.py

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-01-08 12:07:45 -05:00
parent c8434ec54b
commit ea85d419de
6 changed files with 24 additions and 28 deletions

View File

@ -1,6 +1,6 @@
# G-Code G1 movement commands (and associated coordinate manipulation)
#
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
@ -34,6 +34,7 @@ class GCodeMove:
gcode.register_command('G0', self.cmd_G1)
gcode.register_command('M114', self.cmd_M114, True)
gcode.register_command('GET_POSITION', self.cmd_GET_POSITION, True)
self.Coord = gcode.Coord
# G-Code coordinate manipulation
self.absolute_coord = self.absolute_extrude = True
self.base_position = [0.0, 0.0, 0.0, 0.0]
@ -94,9 +95,9 @@ class GCodeMove:
'extrude_factor': self.extrude_factor,
'absolute_coordinates': self.absolute_coord,
'absolute_extrude': self.absolute_extrude,
'homing_origin': homing.Coord(*self.homing_position),
'position': homing.Coord(*self.last_position),
'gcode_position': homing.Coord(*move_position),
'homing_origin': self.Coord(*self.homing_position),
'position': self.Coord(*self.last_position),
'gcode_position': self.Coord(*move_position),
}
def reset_last_position(self):
if self.is_printer_ready:

View File

@ -1,13 +1,17 @@
# Parse gcode commands
#
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os, re, logging, collections, shlex
import homing
class CommandError(Exception):
pass
Coord = collections.namedtuple('Coord', ('x', 'y', 'z', 'e'))
class GCodeCommand:
error = homing.CommandError
error = CommandError
def __init__(self, gcode, command, commandline, params, need_ack):
self._command = command
self._commandline = commandline
@ -68,7 +72,8 @@ class GCodeCommand:
# Parse and dispatch G-Code commands
class GCodeDispatch:
error = homing.CommandError
error = CommandError
Coord = Coord
def __init__(self, printer):
self.printer = printer
self.is_fileinput = not not printer.get_start_args().get("debuginput")

View File

@ -1,6 +1,6 @@
# Code for state tracking during homing operations
#
# Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, math, collections
@ -157,8 +157,3 @@ def multi_complete(printer, completions):
return completions[0]
cb = (lambda e: all([c.wait() for c in completions]))
return printer.get_reactor().register_callback(cb)
class CommandError(Exception):
pass
Coord = collections.namedtuple('Coord', ('x', 'y', 'z', 'e'))

View File

@ -5,7 +5,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import sys, os, gc, optparse, logging, time, collections, importlib
import util, reactor, queuelogger, msgproto, homing
import util, reactor, queuelogger, msgproto
import gcode, configfile, pins, mcu, toolhead, webhooks
message_ready = "Printer is ready"
@ -47,7 +47,7 @@ Printer is shutdown
class Printer:
config_error = configfile.error
command_error = homing.CommandError
command_error = gcode.CommandError
def __init__(self, main_reactor, bglogger, start_args):
self.bglogger = bglogger
self.start_args = start_args

View File

@ -1,10 +1,10 @@
# Code for coordinating events on the printer toolhead
#
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, importlib
import mcu, homing, chelper, kinematics.extruder
import mcu, chelper, kinematics.extruder
# Common suffixes: _d is distance (in mm), _v is velocity (in
# mm/second), _v2 is velocity squared (mm^2/s^2), _t is time (in
@ -196,7 +196,6 @@ class DripModeEndSignal(Exception):
# Main code to track events (and their timing) on the printer toolhead
class ToolHead:
Coord = homing.Coord
def __init__(self, config):
self.printer = config.get_printer()
self.reactor = self.printer.get_reactor()
@ -251,6 +250,8 @@ class ToolHead:
self.trapq_free_moves = ffi_lib.trapq_free_moves
self.step_generators = []
# Create kinematics class
gcode = self.printer.lookup_object('gcode')
self.Coord = gcode.Coord
self.extruder = kinematics.extruder.DummyExtruder(self.printer)
kin_name = config.get('kinematics')
try:
@ -265,7 +266,6 @@ class ToolHead:
logging.exception(msg)
raise config.error(msg)
# Register commands
gcode = self.printer.lookup_object('gcode')
gcode.register_command('G4', self.cmd_G4)
gcode.register_command('M400', self.cmd_M400)
gcode.register_command('SET_VELOCITY_LIMIT',

View File

@ -3,13 +3,8 @@
# Copyright (C) 2020 Eric Callahan <arksine.code@gmail.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license
import logging
import socket
import os
import sys
import errno
import json
import homing
import logging, socket, os, sys, errno, json
import gcode
# Json decodes strings as unicode types in Python 2.x. This doesn't
# play well with some parts of Klipper (particuarly displays), so we
@ -27,7 +22,7 @@ def byteify(data, ignore_dicts=False):
for k, v in data.items()}
return data
class WebRequestError(homing.CommandError):
class WebRequestError(gcode.CommandError):
def __init__(self, message,):
Exception.__init__(self, message)