123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790 |
-
-
-
-
- #include "gcode.h"
- GcodeSuite gcode;
-
- #include "parser.h"
- #include "queue.h"
- #include "../module/motion.h"
-
- #if ENABLED(PRINTCOUNTER)
- #include "../module/printcounter.h"
- #endif
-
- #include "../Marlin.h"
-
- uint8_t GcodeSuite::target_extruder;
- millis_t GcodeSuite::previous_move_ms;
-
- bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
-
- #if ENABLED(HOST_KEEPALIVE_FEATURE)
- GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
- uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
- #endif
-
- #if ENABLED(CNC_WORKSPACE_PLANES)
- GcodeSuite::WorkspacePlane GcodeSuite::workspace_plane = PLANE_XY;
- #endif
-
- #if ENABLED(CNC_COORDINATE_SYSTEMS)
- int8_t GcodeSuite::active_coordinate_system = -1;
- float GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
- #endif
-
-
- bool GcodeSuite::get_target_extruder_from_command() {
- if (parser.seenval('T')) {
- const int8_t e = parser.value_byte();
- if (e >= EXTRUDERS) {
- SERIAL_ECHO_START();
- SERIAL_CHAR('M');
- SERIAL_ECHO(parser.codenum);
- SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
- return true;
- }
- target_extruder = e;
- }
- else
- target_extruder = active_extruder;
-
- return false;
- }
-
-
- void GcodeSuite::get_destination_from_command() {
- LOOP_XYZE(i) {
- if (parser.seen(axis_codes[i])) {
- const float v = parser.value_axis_units((AxisEnum)i);
- destination[i] = (axis_relative_modes[i] || relative_mode)
- ? current_position[i] + v
- : (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
- }
- else
- destination[i] = current_position[i];
- }
-
- if (parser.linearval('F') > 0)
- feedrate_mm_s = MMM_TO_MMS(parser.value_feedrate());
-
- #if ENABLED(PRINTCOUNTER)
- if (!DEBUGGING(DRYRUN))
- print_job_timer.incFilamentUsed(destination[E_AXIS] - current_position[E_AXIS]);
- #endif
-
-
- #if ENABLED(MIXING_EXTRUDER) && ENABLED(DIRECT_MIXING_IN_G1)
- M165();
- #endif
- }
-
-
- void GcodeSuite::dwell(millis_t time) {
- time += millis();
- while (PENDING(millis(), time)) idle();
- }
-
-
- #if HAS_LEVELING && ENABLED(G29_RETRY_AND_RECOVER)
-
- #ifndef G29_MAX_RETRIES
- #define G29_MAX_RETRIES 0
- #endif
-
- void GcodeSuite::G29_with_retry() {
- uint8_t retries = G29_MAX_RETRIES;
- while (G29()) {
- if (retries--) {
- #ifdef G29_ACTION_ON_RECOVER
- SERIAL_ECHOLNPGM("//action:" G29_ACTION_ON_RECOVER);
- #endif
- #ifdef G29_RECOVER_COMMANDS
- process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
- #endif
- }
- else {
- #ifdef G29_FAILURE_COMMANDS
- process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
- #endif
- #ifdef G29_ACTION_ON_FAILURE
- SERIAL_ECHOLNPGM("//action:" G29_ACTION_ON_FAILURE);
- #endif
- #if ENABLED(G29_HALT_ON_FAILURE)
- kill(PSTR(MSG_ERR_PROBING_FAILED));
- #endif
- return;
- }
- }
- #ifdef G29_SUCCESS_COMMANDS
- process_subcommands_now_P(PSTR(G29_SUCCESS_COMMANDS));
- #endif
- }
-
- #endif
-
-
-
-
- #if ENABLED(M100_FREE_MEMORY_WATCHER)
- extern void M100_dump_routine(PGM_P const title, const char *start, const char *end);
- #endif
-
-
- void GcodeSuite::process_parsed_command(
- #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
- const bool no_ok
- #endif
- ) {
- KEEPALIVE_STATE(IN_HANDLER);
-
-
- switch (parser.command_letter) {
- case 'G': switch (parser.codenum) {
-
- case 0: case 1: G0_G1(
- #if IS_SCARA || defined(G0_FEEDRATE)
- parser.codenum == 0
- #endif
- );
- break;
-
- #if ENABLED(ARC_SUPPORT) && DISABLED(SCARA)
- case 2: case 3: G2_G3(parser.codenum == 2); break;
- #endif
-
- case 4: G4(); break;
-
- #if ENABLED(BEZIER_CURVE_SUPPORT)
- case 5: G5(); break;
- #endif
-
- #if ENABLED(FWRETRACT)
- case 10: G10(); break;
- case 11: G11(); break;
- #endif
-
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
- case 12: G12(); break;
- #endif
-
- #if ENABLED(CNC_WORKSPACE_PLANES)
- case 17: G17(); break;
- case 18: G18(); break;
- case 19: G19(); break;
- #endif
-
- #if ENABLED(INCH_MODE_SUPPORT)
- case 20: G20(); break;
- case 21: G21(); break;
- #endif
-
- #if ENABLED(G26_MESH_VALIDATION)
- case 26: G26(); break;
- #endif
-
- #if ENABLED(NOZZLE_PARK_FEATURE)
- case 27: G27(); break;
- #endif
-
- case 28: G28(false); break;
-
- #if HAS_LEVELING
- case 29:
- #if ENABLED(G29_RETRY_AND_RECOVER)
- G29_with_retry();
- #else
- G29();
- #endif
- break;
- #endif
-
- #if HAS_BED_PROBE
- case 30: G30(); break;
- #if ENABLED(Z_PROBE_SLED)
- case 31: G31(); break;
- case 32: G32(); break;
- #endif
- #endif
-
- #if ENABLED(DELTA_AUTO_CALIBRATION)
- case 33: G33(); break;
- #endif
-
- #if ENABLED(Z_STEPPER_AUTO_ALIGN)
- case 34: G34(); break;
- #endif
-
- #if ENABLED(G38_PROBE_TARGET)
- case 38:
- if (parser.subcode == 2 || parser.subcode == 3)
- G38(parser.subcode == 2);
- break;
- #endif
-
- #if ENABLED(GCODE_MOTION_MODES)
- case 80: G80(); break;
- #endif
-
- case 90: relative_mode = false; break;
- case 91: relative_mode = true; break;
-
- case 92: G92(); break;
-
- #if HAS_MESH
- case 42: G42(); break;
- #endif
-
- #if ENABLED(DEBUG_GCODE_PARSER)
- case 800: parser.debug(); break;
- #endif
-
- default: parser.unknown_command_error(); break;
- }
- break;
-
- case 'M': switch (parser.codenum) {
- #if HAS_RESUME_CONTINUE
- case 0:
- case 1: M0_M1(); break;
- #endif
-
- #if ENABLED(SPINDLE_LASER_ENABLE)
- case 3: M3_M4(true ); break;
- case 4: M3_M4(false); break;
- case 5: M5(); break;
- #endif
-
- #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
- case 12: M12(); break;
- #endif
-
- case 17: M17(); break;
-
- #if ENABLED(SDSUPPORT)
- case 20: M20(); break;
- case 21: M21(); break;
- case 22: M22(); break;
- case 23: M23(); break;
- case 24: M24(); break;
- case 25: M25(); break;
- case 26: M26(); break;
- case 27: M27(); break;
- case 28: M28(); break;
- case 29: M29(); break;
- case 30: M30(); break;
- case 32: M32(); break;
-
- #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
- case 33: M33(); break;
- #endif
-
- #if ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE)
- case 34: M34(); break;
- #endif
-
- case 928: M928(); break;
- #endif
-
- case 31: M31(); break;
- case 42: M42(); break;
-
- #if ENABLED(PINS_DEBUGGING)
- case 43: M43(); break;
- #endif
-
- #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
- case 48: M48(); break;
- #endif
-
- #if ENABLED(G26_MESH_VALIDATION)
- case 49: M49(); break;
- #endif
-
- #if ENABLED(ULTRA_LCD) && ENABLED(LCD_SET_PROGRESS_MANUALLY)
- case 73: M73(); break;
- #endif
-
- case 75: M75(); break;
- case 76: M76(); break;
- case 77: M77(); break;
-
- #if ENABLED(PRINTCOUNTER)
- case 78: M78(); break;
- #endif
-
- #if ENABLED(M100_FREE_MEMORY_WATCHER)
- case 100: M100(); break;
- #endif
-
- case 104: M104(); break;
- case 109: M109(); break;
- case 110: M110(); break;
- case 111: M111(); break;
-
- #if DISABLED(EMERGENCY_PARSER)
- case 108: M108(); break;
- case 112: M112(); break;
- case 410: M410(); break;
- #else
- case 108: case 112: case 410: break;
- #endif
-
- #if ENABLED(HOST_KEEPALIVE_FEATURE)
- case 113: M113(); break;
- #endif
-
- #if HAS_HEATED_BED
- case 140: M140(); break;
- case 190: M190(); break;
- #endif
-
- case 105: M105(); KEEPALIVE_STATE(NOT_BUSY); return;
-
- #if ENABLED(AUTO_REPORT_TEMPERATURES) && HAS_TEMP_SENSOR
- case 155: M155(); break;
- #endif
-
- #if FAN_COUNT > 0
- case 106: M106(); break;
- case 107: M107(); break;
- #endif
-
- #if ENABLED(PARK_HEAD_ON_PAUSE)
- case 125: M125(); break;
- #endif
-
- #if ENABLED(BARICUDA)
-
- #if HAS_HEATER_1
- case 126: M126(); break;
- case 127: M127(); break;
- #endif
-
-
- #if HAS_HEATER_2
- case 128: M128(); break;
- case 129: M129(); break;
- #endif
- #endif
-
- #if HAS_POWER_SWITCH
- case 80: M80(); break;
- #endif
- case 81: M81(); break;
-
- case 82: M82(); break;
- case 83: M83(); break;
- case 18: case 84: M18_M84(); break;
- case 85: M85(); break;
- case 92: M92(); break;
- case 114: M114(); break;
- case 115: M115(); break;
- case 117: M117(); break;
- case 118: M118(); break;
- case 119: M119(); break;
- case 120: M120(); break;
- case 121: M121(); break;
-
- #if ENABLED(ULTIPANEL)
- case 145: M145(); break;
- #endif
-
- #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
- case 149: M149(); break;
- #endif
-
- #if HAS_COLOR_LEDS
- case 150: M150(); break;
- #endif
-
- #if ENABLED(MIXING_EXTRUDER)
- case 163: M163(); break;
- case 164: M164(); break;
- #if ENABLED(DIRECT_MIXING_IN_G1)
- case 165: M165(); break;
- #endif
- #endif
-
- #if DISABLED(NO_VOLUMETRICS)
- case 200: M200(); break;
- #endif
-
- case 201: M201(); break;
-
- #if 0
- case 202: M202(); break;
- #endif
-
- case 203: M203(); break;
- case 204: M204(); break;
- case 205: M205(); break;
-
- #if HAS_M206_COMMAND
- case 206: M206(); break;
- #endif
-
- #if ENABLED(DELTA)
- case 665: M665(); break;
- #endif
-
- #if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
- case 666: M666(); break;
- #endif
-
- #if ENABLED(FWRETRACT)
- case 207: M207(); break;
- case 208: M208(); break;
- #if ENABLED(FWRETRACT_AUTORETRACT)
- case 209:
- if (MIN_AUTORETRACT <= MAX_AUTORETRACT) M209();
- break;
- #endif
- #endif
-
- case 211: M211(); break;
-
- #if EXTRUDERS > 1
- case 217: M217(); break;
- #endif
-
- #if HOTENDS > 1
- case 218: M218(); break;
- #endif
-
- case 220: M220(); break;
- case 221: M221(); break;
- case 226: M226(); break;
-
- #if HAS_SERVOS
- case 280: M280(); break;
- #if ENABLED(EDITABLE_SERVO_ANGLES)
- case 281: M281(); break;
- #endif
- #endif
-
- #if ENABLED(BABYSTEPPING)
- case 290: M290(); break;
- #endif
-
- #if HAS_BUZZER
- case 300: M300(); break;
- #endif
-
- #if ENABLED(PIDTEMP)
- case 301: M301(); break;
- #endif
-
- #if ENABLED(PIDTEMPBED)
- case 304: M304(); break;
- #endif
-
- #if defined(CHDK) || HAS_PHOTOGRAPH
- case 240: M240(); break;
- #endif
-
- #if HAS_LCD_CONTRAST
- case 250: M250(); break;
- #endif
-
- #if ENABLED(EXPERIMENTAL_I2CBUS)
- case 260: M260(); break;
- case 261: M261(); break;
- #endif
-
- #if ENABLED(PREVENT_COLD_EXTRUSION)
- case 302: M302(); break;
- #endif
-
- case 303: M303(); break;
-
- #if ENABLED(MORGAN_SCARA)
- case 360: if (M360()) return; break;
- case 361: if (M361()) return; break;
- case 362: if (M362()) return; break;
- case 363: if (M363()) return; break;
- case 364: if (M364()) return; break;
- #endif
-
- #if ENABLED(EXT_SOLENOID) || ENABLED(MANUAL_SOLENOID_CONTROL)
- case 380: M380(); break;
- case 381: M381(); break;
- #endif
-
- case 400: M400(); break;
-
- #if HAS_BED_PROBE
- case 401: M401(); break;
- case 402: M402(); break;
- #endif
-
- #if ENABLED(FILAMENT_WIDTH_SENSOR)
- case 404: M404(); break;
- case 405: M405(); break;
- case 406: M406(); break;
- case 407: M407(); break;
- #endif
-
- #if HAS_LEVELING
- case 420: M420(); break;
- #endif
-
- #if HAS_MESH
- case 421: M421(); break;
- #endif
-
- #if HAS_M206_COMMAND
- case 428: M428(); break;
- #endif
-
- case 500: M500(); break;
- case 501: M501(); break;
- case 502: M502(); break;
- #if DISABLED(DISABLE_M503)
- case 503: M503(); break;
- #endif
- #if ENABLED(EEPROM_SETTINGS)
- case 504: M504(); break;
- #endif
-
- #if ENABLED(SDSUPPORT)
- case 524: M524(); break;
- #endif
-
- #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
- case 540: M540(); break;
- #endif
-
- #if HAS_BED_PROBE
- case 851: M851(); break;
- #endif
-
- #if ENABLED(SKEW_CORRECTION_GCODE)
- case 852: M852(); break;
- #endif
-
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- case 600: M600(); break;
- case 603: M603(); break;
- #endif
-
- #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
- case 605: M605(); break;
- #endif
-
- #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
- case 701: M701(); break;
- case 702: M702(); break;
- #endif
-
- #if ENABLED(MAX7219_GCODE)
- case 7219: M7219(); break;
- #endif
-
- #if ENABLED(LIN_ADVANCE)
- case 900: M900(); break;
- #endif
-
- #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM || ENABLED(DIGIPOT_I2C) || ENABLED(DAC_STEPPER_CURRENT)
- case 907: M907(); break;
- #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
- case 908: M908(); break;
- #if ENABLED(DAC_STEPPER_CURRENT)
- case 909: M909(); break;
- case 910: M910(); break;
- #endif
- #endif
- #endif
-
- #if HAS_TRINAMIC
- #if ENABLED(TMC_DEBUG)
- case 122: M122(); break;
- #endif
- case 906: M906(); break;
- #if ENABLED(MONITOR_DRIVER_STATUS)
- case 911: M911(); break;
- case 912: M912(); break;
- #endif
- #if ENABLED(HYBRID_THRESHOLD)
- case 913: M913(); break;
- #endif
- #if USE_SENSORLESS
- case 914: M914(); break;
- #endif
- #if ENABLED(TMC_Z_CALIBRATION)
- case 915: M915(); break;
- #endif
- #endif
-
- #if HAS_MICROSTEPS
- case 350: M350(); break;
- case 351: M351(); break;
- #endif
-
- case 355: M355(); break;
-
- #if ENABLED(DEBUG_GCODE_PARSER)
- case 800: parser.debug(); break;
- #endif
-
- #if ENABLED(I2C_POSITION_ENCODERS)
- case 860: M860(); break;
- case 861: M861(); break;
- case 862: M862(); break;
- case 863: M863(); break;
- case 864: M864(); break;
- case 865: M865(); break;
- case 866: M866(); break;
- case 867: M867(); break;
- case 868: M868(); break;
- case 869: M869(); break;
- #endif
-
- #if ENABLED(Z_STEPPER_AUTO_ALIGN)
- case 422: M422(); break;
- #endif
-
- case 999: M999(); break;
-
- default: parser.unknown_command_error(); break;
- }
- break;
-
- case 'T': T(parser.codenum); break;
-
- default: parser.unknown_command_error();
- }
-
- KEEPALIVE_STATE(NOT_BUSY);
-
- #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
- if (!no_ok)
- #endif
- ok_to_send();
- }
-
-
- void GcodeSuite::process_next_command() {
- char * const current_command = command_queue[cmd_queue_index_r];
-
- if (DEBUGGING(ECHO)) {
- SERIAL_ECHO_START();
- SERIAL_ECHOLN(current_command);
- #if ENABLED(M100_FREE_MEMORY_WATCHER)
- SERIAL_ECHOPAIR("slot:", cmd_queue_index_r);
- M100_dump_routine(PSTR(" Command Queue:"), (const char*)command_queue, (const char*)(command_queue + sizeof(command_queue)));
- #endif
- }
-
-
- parser.parse(current_command);
- process_parsed_command();
- }
-
- #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
-
-
- void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
-
- char * const saved_cmd = parser.command_ptr;
-
-
- while (pgm_read_byte_near(pgcode)) {
-
- PGM_P const delim = strchr_P(pgcode, '\n');
- size_t len = delim ? delim - pgcode : strlen_P(pgcode);
- char cmd[len + 1];
- strncpy_P(cmd, pgcode, len);
- cmd[len] = '\0';
- pgcode += len;
- if (delim) pgcode++;
-
-
- parser.parse(cmd);
- process_parsed_command(true);
- }
-
-
- parser.parse(saved_cmd);
- }
- #endif
-
- #if ENABLED(HOST_KEEPALIVE_FEATURE)
-
-
-
- void GcodeSuite::host_keepalive() {
- const millis_t ms = millis();
- static millis_t next_busy_signal_ms = 0;
- if (!suspend_auto_report && host_keepalive_interval && busy_state != NOT_BUSY) {
- if (PENDING(ms, next_busy_signal_ms)) return;
- switch (busy_state) {
- case IN_HANDLER:
- case IN_PROCESS:
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPGM(MSG_BUSY_PROCESSING);
- break;
- case PAUSED_FOR_USER:
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_USER);
- break;
- case PAUSED_FOR_INPUT:
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_INPUT);
- break;
- default:
- break;
- }
- }
- next_busy_signal_ms = ms + host_keepalive_interval * 1000UL;
- }
-
- #endif
|