aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/gcode.py
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* gcode: Raise a gcode.error() from G20 commandKevin O'Connor2020-04-241-1/+1
| | | | | | | It's important to raise an error (instead of calling respond_error() ) so that a G20 will stop a virtual_sdcard print. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode_arcs: Fix Z moves and E movesKevin O'Connor2020-04-221-1/+2
| | | | | | | | Fix Z moves so that the movement is spaced out among the arc movements. Fix extrude moves when in absolute extrude mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Add a "command_error" event notifierKevin O'Connor2020-02-151-0/+1
| | | | | | | Allow other modules to be notified if there is a gcode command error detected. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Return previous handler from register_command(cmd, None)Kevin O'Connor2020-02-121-1/+2
| | | | | | | | When overriding a g-code command, allow the caller to obtain the previous command handler. Use this feature in homing_override and safe_z_home. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Fix detection of some "extended" g-code commandsKevin O'Connor2020-01-071-4/+11
| | | | | | | Fix typo that resulted in _get_extended_params() being called for all commands. Allow "extended" g-code commands to contain numbers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* extruder: Move M104/M140 commands from gcode.py to extruder.pyKevin O'Connor2019-12-161-32/+3
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* heater_bed: Move M140/M190 commands from gcode.py to heater_bed.pyKevin O'Connor2019-12-161-11/+6
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Rename bg_temp() to wait_for_temperature()Kevin O'Connor2019-12-161-2/+3
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* heater: Use printer.command_error() instead of internal heater.error()Kevin O'Connor2019-12-161-4/+1
| | | | | | | Use the more standard command_error to report invalid temperature requests. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Remove builtin T0/T1/T2/... command supportKevin O'Connor2019-12-101-26/+1
| | | | | | | | The builtin Tn command is not sufficiently flexible to control some multi-extruder printers. Remove the command and encourage users to define individual gcode_macros for each Tn instance. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* extruder: Add an ACTIVATE_EXTRUDER commandKevin O'Connor2019-12-101-0/+6
| | | | | | | Add support for an extended g-code command to change the currently active extruder. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Remove support for the M206 commandKevin O'Connor2019-12-101-9/+1
| | | | | | | | The M206 command isn't particularly standardized and isn't issued by default from 3rd party software in their standard configurations. Encourage users to use the more powerful SET_GCODE_OFFSET command. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>