mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-12-17 13:49:59 +01:00
gcode: Replace Coord named tuple with custom tuple class
Replace the existing Coord() class with one that supports more than 4 coordinates. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -1,15 +1,26 @@
|
|||||||
# Parse gcode commands
|
# Parse gcode commands
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016-2024 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2016-2025 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import os, re, logging, collections, shlex
|
import os, re, logging, collections, shlex, operator
|
||||||
|
|
||||||
class CommandError(Exception):
|
class CommandError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
Coord = collections.namedtuple('Coord', ('x', 'y', 'z', 'e'))
|
# Custom "tuple" class for coordinates - add easy access to x, y, z components
|
||||||
|
class Coord(tuple):
|
||||||
|
__slots__ = ()
|
||||||
|
def __new__(cls, x, y, z, e, *args):
|
||||||
|
return tuple.__new__(cls, (x, y, z, e) + args)
|
||||||
|
def __getnewargs__(self):
|
||||||
|
return tuple(self)
|
||||||
|
x = property(operator.itemgetter(0))
|
||||||
|
y = property(operator.itemgetter(1))
|
||||||
|
z = property(operator.itemgetter(2))
|
||||||
|
e = property(operator.itemgetter(3))
|
||||||
|
|
||||||
|
# Class for handling gcode command parameters (gcmd)
|
||||||
class GCodeCommand:
|
class GCodeCommand:
|
||||||
error = CommandError
|
error = CommandError
|
||||||
def __init__(self, gcode, command, commandline, params, need_ack):
|
def __init__(self, gcode, command, commandline, params, need_ack):
|
||||||
|
|||||||
Reference in New Issue
Block a user