aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/gcode.py
Commit message (Collapse)AuthorAgeFilesLines
* gcode: Improve checksum detection in get_raw_command_parameters()Kevin O'Connor2024-12-011-1/+1
| | | | | | | Only consider a trailing '*' to indicate a checksum if the remainder of the string is a number. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Some optimizations to get_raw_command_parameters()Kevin O'Connor2024-12-011-10/+10
| | | | | | Add some minor optimizations to the get_raw_command_parameters() code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Use the same M117/M118 fixup for M23Kevin O'Connor2024-12-011-2/+2
| | | | | | | | The M23 command has similar requirements for extracting the full parameter string that M117/M118 have. Use the same code for those fixups. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Fixup M117/M118 command identification in cmd_default()Kevin O'Connor2024-12-011-7/+9
| | | | | | | | Alter gcmd._command in cmd_default if the special M117/M118 handling is detected. This avoids having to recheck for this condition in get_raw_command_parameters(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Improve handling of extended g-code commands with '*;#' charactersKevin O'Connor2024-12-011-15/+11
| | | | | | | | | | | | The g-code command parser did not allow three characters to be passed as parameters to commands (asterisk, semicolon, pound sign). Rework the parsing code to better leverage the python shlex package so that these characters can be supported. In particular, this should allow better support for printing g-code files that have unusual characters in the filename. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Don't silently discard characters inside a command nameKevin O'Connor2024-12-011-7/+5
| | | | | | | | | | | Don't silently drop leading numbers and unusual characters at the start of a command - for example, don't interpret '99M88' as 'M88'. Don't silently drop spaces in a command - for example, don't interpret "M 101" as the command "M101". Doing so will cause other parts of the code (such as get_raw_command_parameters() ) to not work properly. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Validate extended g-code command namesKevin O'Connor2024-12-011-0/+4
| | | | | | | Extended g-code command names may only contain A-Z, 0-9, and underscore, and the first two characters may not be digits. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Minor change to suppress python warning on '\s'Kevin O'Connor2024-07-111-1/+1
| | | | | | Reported by @matdibu. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: expose status with available commandsPedro Lamas2023-12-111-0/+13
| | | | Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
* gcode: Handle M117 and M118 commands that start with a special characterKevin O'Connor2022-01-181-11/+10
| | | | | | | | | | | Commit 7ef7bf60 broke the special handling for M117 commands that start with a number or special character. Fix that support and extend to M118 as well. Also improve handling of commands not separated by a space (eg, "M117HELLO"). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Allow rename_existing also for register_mux_command (#4843)Alex Zellner2021-11-221-3/+4
| | | Signed-off-by: Alex Zellner <alexander.zellner@googlemail.com>
* gcode_macro: Add "rawparams" pseudo-variablePedro Lamas2021-11-191-0/+16
| | | | Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
* gcode: Fix Python3 syntax errorKevin O'Connor2021-10-311-2/+2
| | | | | | | Fix error introduced in d6c3aaad. Also, go back to only accepting ascii characters on input. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Use regular str() types for g-code commands on Python2Kevin O'Connor2021-10-311-3/+3
| | | | | | | | | Avoid using unicode() types on Python2 as it can lead to subtle errors. Also, accept utf8 on gcode input (instead of just ascii). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Convert to Python3 string encodingKevin O'Connor2021-10-011-2/+2
| | | | | | | | | | | The error checking is not complete in this change - the code should handle the case where an input string is not valid utf8. The code will continue to run on Python2 after this change, however the execution time on Python2 is measurably slower after making this change. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Update gcode descriptions (#4335)Stefan Dej2021-06-021-0/+1
| | | | | | | | | | Add help description to HELP Add help description to RESPOND Add help description to MEASURE_AXES_NOISE, TEST_RESONANCES and SHAPER_CALIBRATE Add help description to PAUSE, RESUME, CLEAR_PAUSE and CANCEL_PRINT Add help description to GET_POSITION Add help description to SET_RETRACTION and GET_RETRACTION Signed-off-by: Stefan Dej <meteyou@gmail.com>
* gcode: Generate M115 output even if command not sent from gcode pseudo-terminalKevin O'Connor2021-04-281-1/+4
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Move definition of CommandError and Coord from homing.py to gcode.pyKevin O'Connor2021-01-081-4/+9
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Don't log debugging output for unknown commands if command is blankKevin O'Connor2020-09-171-1/+3
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Fix out-of-order cmd_M112 referenceKevin O'Connor2020-08-231-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode_move: Move GCodeMove class from gcode.py to new extras moduleKevin O'Connor2020-08-201-272/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Split G0/G1 command handling to new gcode_move classKevin O'Connor2020-08-201-151/+165
| | | | | | | | Split up the main GCodeParser class into GCodeDispatch and GCodeMove classes. The GCodeMove class is now available using the "gcode_move" printer object name. This split simplifies the gcode.py code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* toolhead: Move G4 and M400 commands from gcode.py to toolhead.pyKevin O'Connor2020-08-201-8/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Convert get_status() last_xpos to use a namedtupleKevin O'Connor2020-08-201-4/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Remove unneeded base_xpos variables from get_status()Kevin O'Connor2020-08-201-4/+0
| | | | | | Convert the only user of base_zpos to use gcode_position. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Convert get_status() homing_xpos to use a namedtupleKevin O'Connor2020-08-201-3/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Remove unused move_xpos get_status() variablesKevin O'Connor2020-08-201-4/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Remove "action_" commands from get_status() callsKevin O'Connor2020-08-201-12/+0
| | | | | | | | | | | | Rename printer.gcode.action_emergency_stop() to action_emergency_stop(), printer.gcode.action_respond_info() to action_respond_info(), and printer.gcode.action_respond_error() to action_raise_error() in command templates. This simplifies the get_status() interface, as returning callable functions from that interface was confusing. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* toolhead: Add a manual_move() helper functionKevin O'Connor2020-08-201-0/+2
| | | | | | | | Add a helper function for submitting relative movements. This function will also automatically ensure gcode.reset_last_position() is called. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Automatically call reset_last_position() on a toolhead set_position()Kevin O'Connor2020-08-201-1/+2
| | | | | | | | Generate a "toolhead:set_position" event on a call to toolhead.set_position() and use that event to automatically call gcode.reset_last_position(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* webhooks: Require a subscription to receive gcode outputKevin O'Connor2020-08-161-19/+2
| | | | | | | | | | | Add a new "gcode/subscribe_output" webhook endpoint to subscribe to gcode output. Only client connections that subscribe to the gcode output will receive that output. This also moves all the gcode webhooks from gcode.py to webhooks.py and arranges for gcode.py to be initialized prior to webhooks.py. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* webhooks: Remove "method" parameter from webhook requestsKevin O'Connor2020-08-161-14/+5
| | | | | | | Don't require or use the "method" parameter of requests. This simplifies the interface. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Fix error causing _dump_debug() to failKevin O'Connor2020-08-081-7/+8
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Separate IO handling to its own classKevin O'Connor2020-08-061-111/+127
| | | | | | | Move the pseudo-tty IO handling from the main gcode class to a new gcode_io class. This simplifies the main gcode class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Introduce add_early_printer_objects()Kevin O'Connor2020-08-061-0/+3
| | | | | | | Create the initial gcode class via new module level add_early_printer_objects() function. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Pass the pseudo-tty fd via the start_args systemKevin O'Connor2020-08-061-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Allow handlers to be registered for all gcode outputKevin O'Connor2020-08-061-0/+5
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Only write to the gcode pseudo-tty if it appears to be activeKevin O'Connor2020-08-061-8/+11
| | | | | | | | If there isn't a reader of the output pipe it can lead to the generation of a large number of errors. Only attempt to write if it appears the pipe is active. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Report the final print_time in debuginput modeKevin O'Connor2020-07-301-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: return message category in get_state_message()Arksine2020-06-241-2/+2
| | | | Signed-off-by: Eric Callahan <arksine.code@gmail.com>
* gcode: add webhooks supportArksine2020-06-241-0/+27
| | | | | | Register "gcode/script", "gcode/help", "gcode/restart", and "gcode/firmware_restart" endpoints. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
* gcode: Make it clear that gcode.get_status() can be called without eventtimeKevin O'Connor2020-05-261-1/+1
| | | | | | | Make it clear that gcode.get_status() to be called without an eventtime by defaulting eventtime=None. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Move "ok" tracking to GCodeCommand classKevin O'Connor2020-05-051-27/+17
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Remove parsing helpers from main gcode classKevin O'Connor2020-05-051-16/+0
| | | | | | | | Remove the parsing helpers from the main gcode class now that all callers have been converted to use the parsing helpers in the GCodeCommand class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Use new GCodeCommand wrappers in command handlersKevin O'Connor2020-05-051-82/+80
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Create new wrapper class for gcode command parametersKevin O'Connor2020-05-051-50/+89
| | | | | | | | Instead of passing a dictionary to the command handlers, create a wrapper class and pass that class to the command handlers. This can simplify the command handler code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Only call position_with_transform() when printer is readyKevin O'Connor2020-05-021-1/+2
| | | | | Signed-off-by: Eric Callahan <arksine.code@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* heater: Move M105 command handling from gcode.py to heater.pyKevin O'Connor2020-04-251-39/+15
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Rename respond() to respond_raw()Kevin O'Connor2020-04-241-6/+6
| | | | | | | | | | | Rename the method to make it more clear that it is a low-level call that should be rarely used. Also, change gcode_button.py, hall_filament_width_sensor.py, and tsl1401cl_filament_width_sensor.py to use respond_info() instead of respond_raw(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Don't export respond_error()Kevin O'Connor2020-04-241-6/+6
| | | | | | | Don't export the respond_error() method as callers should raise a gcode.error() instead. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>