mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-12-26 17:48:32 -07: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:
parent
b6c1b5a6dd
commit
01b3a6a8e4
1 changed files with 14 additions and 3 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue