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:
Kevin O'Connor
2025-09-18 12:31:30 -04:00
parent aea8d8e0a1
commit 2290d87f5d

View File

@@ -1,15 +1,26 @@
# 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.
import os, re, logging, collections, shlex
import os, re, logging, collections, shlex, operator
class CommandError(Exception):
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:
error = CommandError
def __init__(self, gcode, command, commandline, params, need_ack):