My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gcode.cpp 47KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * gcode.cpp - Temporary container for all gcode handlers
  24. * Most will migrate to classes, by feature.
  25. */
  26. #include "gcode.h"
  27. GcodeSuite gcode;
  28. #if ENABLED(WIFI_CUSTOM_COMMAND)
  29. extern bool wifi_custom_command(char * const command_ptr);
  30. #endif
  31. #include "parser.h"
  32. #include "queue.h"
  33. #include "../module/motion.h"
  34. #if ENABLED(PRINTCOUNTER)
  35. #include "../module/printcounter.h"
  36. #endif
  37. #if ENABLED(HOST_ACTION_COMMANDS)
  38. #include "../feature/host_actions.h"
  39. #endif
  40. #if ENABLED(POWER_LOSS_RECOVERY)
  41. #include "../sd/cardreader.h"
  42. #include "../feature/powerloss.h"
  43. #endif
  44. #if ENABLED(CANCEL_OBJECTS)
  45. #include "../feature/cancel_object.h"
  46. #endif
  47. #if ENABLED(LASER_MOVE_POWER)
  48. #include "../feature/spindle_laser.h"
  49. #endif
  50. #if ENABLED(FLOWMETER_SAFETY)
  51. #include "../feature/cooler.h"
  52. #endif
  53. #if ENABLED(PASSWORD_FEATURE)
  54. #include "../feature/password/password.h"
  55. #endif
  56. #include "../MarlinCore.h" // for idle, kill
  57. // Inactivity shutdown
  58. millis_t GcodeSuite::previous_move_ms = 0,
  59. GcodeSuite::max_inactive_time = 0,
  60. GcodeSuite::stepper_inactive_time = SEC_TO_MS(DEFAULT_STEPPER_DEACTIVE_TIME);
  61. // Relative motion mode for each logical axis
  62. static constexpr xyze_bool_t ar_init = AXIS_RELATIVE_MODES;
  63. axis_bits_t GcodeSuite::axis_relative = 0 LOGICAL_AXIS_GANG(
  64. | (ar_init.e << REL_E),
  65. | (ar_init.x << REL_X),
  66. | (ar_init.y << REL_Y),
  67. | (ar_init.z << REL_Z),
  68. | (ar_init.i << REL_I),
  69. | (ar_init.j << REL_J),
  70. | (ar_init.k << REL_K)
  71. );
  72. #if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
  73. bool GcodeSuite::autoreport_paused; // = false
  74. #endif
  75. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  76. GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
  77. uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
  78. #endif
  79. #if ENABLED(CNC_WORKSPACE_PLANES)
  80. GcodeSuite::WorkspacePlane GcodeSuite::workspace_plane = PLANE_XY;
  81. #endif
  82. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  83. int8_t GcodeSuite::active_coordinate_system = -1; // machine space
  84. xyz_pos_t GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS];
  85. #endif
  86. void GcodeSuite::report_echo_start(const bool forReplay) { if (!forReplay) SERIAL_ECHO_START(); }
  87. void GcodeSuite::report_heading(const bool forReplay, FSTR_P const fstr, const bool eol/*=true*/) {
  88. if (forReplay) return;
  89. if (fstr) {
  90. SERIAL_ECHO_START();
  91. SERIAL_ECHOPGM("; ");
  92. SERIAL_ECHOF(fstr);
  93. }
  94. if (eol) { SERIAL_CHAR(':'); SERIAL_EOL(); }
  95. }
  96. void GcodeSuite::say_units() {
  97. SERIAL_ECHOLNPGM_P(
  98. TERN_(INCH_MODE_SUPPORT, parser.linear_unit_factor != 1.0 ? PSTR(" (in)") :)
  99. PSTR(" (mm)")
  100. );
  101. }
  102. /**
  103. * Get the target extruder from the T parameter or the active_extruder
  104. * Return -1 if the T parameter is out of range
  105. */
  106. int8_t GcodeSuite::get_target_extruder_from_command() {
  107. if (parser.seenval('T')) {
  108. const int8_t e = parser.value_byte();
  109. if (e < EXTRUDERS) return e;
  110. SERIAL_ECHO_START();
  111. SERIAL_CHAR('M'); SERIAL_ECHO(parser.codenum);
  112. SERIAL_ECHOLNPGM(" " STR_INVALID_EXTRUDER " ", e);
  113. return -1;
  114. }
  115. return active_extruder;
  116. }
  117. /**
  118. * Get the target E stepper from the 'T' parameter.
  119. * If there is no 'T' parameter then dval will be substituted.
  120. * Returns -1 if the resulting E stepper index is out of range.
  121. */
  122. int8_t GcodeSuite::get_target_e_stepper_from_command(const int8_t dval/*=-1*/) {
  123. const int8_t e = parser.intval('T', dval);
  124. if (WITHIN(e, 0, E_STEPPERS - 1)) return e;
  125. SERIAL_ECHO_START();
  126. SERIAL_CHAR('M'); SERIAL_ECHO(parser.codenum);
  127. if (e == -1)
  128. SERIAL_ECHOLNPGM(" " STR_E_STEPPER_NOT_SPECIFIED);
  129. else
  130. SERIAL_ECHOLNPGM(" " STR_INVALID_E_STEPPER " ", e);
  131. return -1;
  132. }
  133. /**
  134. * Set XYZIJKE destination and feedrate from the current GCode command
  135. *
  136. * - Set destination from included axis codes
  137. * - Set to current for missing axis codes
  138. * - Set the feedrate, if included
  139. */
  140. void GcodeSuite::get_destination_from_command() {
  141. xyze_bool_t seen{false};
  142. #if ENABLED(CANCEL_OBJECTS)
  143. const bool &skip_move = cancelable.skipping;
  144. #else
  145. constexpr bool skip_move = false;
  146. #endif
  147. // Get new XYZ position, whether absolute or relative
  148. LOOP_LINEAR_AXES(i) {
  149. if ( (seen[i] = parser.seenval(AXIS_CHAR(i))) ) {
  150. const float v = parser.value_axis_units((AxisEnum)i);
  151. if (skip_move)
  152. destination[i] = current_position[i];
  153. else
  154. destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : LOGICAL_TO_NATIVE(v, i);
  155. }
  156. else
  157. destination[i] = current_position[i];
  158. }
  159. #if HAS_EXTRUDERS
  160. // Get new E position, whether absolute or relative
  161. if ( (seen.e = parser.seenval('E')) ) {
  162. const float v = parser.value_axis_units(E_AXIS);
  163. destination.e = axis_is_relative(E_AXIS) ? current_position.e + v : v;
  164. }
  165. else
  166. destination.e = current_position.e;
  167. #endif
  168. #if ENABLED(POWER_LOSS_RECOVERY) && !PIN_EXISTS(POWER_LOSS)
  169. // Only update power loss recovery on moves with E
  170. if (recovery.enabled && IS_SD_PRINTING() && seen.e && (seen.x || seen.y))
  171. recovery.save();
  172. #endif
  173. if (parser.floatval('F') > 0)
  174. feedrate_mm_s = parser.value_feedrate();
  175. #if ENABLED(PRINTCOUNTER)
  176. if (!DEBUGGING(DRYRUN) && !skip_move)
  177. print_job_timer.incFilamentUsed(destination.e - current_position.e);
  178. #endif
  179. // Get ABCDHI mixing factors
  180. #if BOTH(MIXING_EXTRUDER, DIRECT_MIXING_IN_G1)
  181. M165();
  182. #endif
  183. #if ENABLED(LASER_MOVE_POWER)
  184. // Set the laser power in the planner to configure this move
  185. if (parser.seen('S')) {
  186. const float spwr = parser.value_float();
  187. cutter.inline_power(TERN(SPINDLE_LASER_USE_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0));
  188. }
  189. else if (ENABLED(LASER_MOVE_G0_OFF) && parser.codenum == 0) // G0
  190. cutter.set_inline_enabled(false);
  191. #endif
  192. }
  193. /**
  194. * Dwell waits immediately. It does not synchronize. Use M400 instead of G4
  195. */
  196. void GcodeSuite::dwell(millis_t time) {
  197. time += millis();
  198. while (PENDING(millis(), time)) idle();
  199. }
  200. /**
  201. * When G29_RETRY_AND_RECOVER is enabled, call G29() in
  202. * a loop with recovery and retry handling.
  203. */
  204. #if ENABLED(G29_RETRY_AND_RECOVER)
  205. void GcodeSuite::event_probe_recover() {
  206. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_INFO, F("G29 Retrying"), FPSTR(DISMISS_STR)));
  207. #ifdef ACTION_ON_G29_RECOVER
  208. hostui.g29_recover();
  209. #endif
  210. #ifdef G29_RECOVER_COMMANDS
  211. process_subcommands_now(F(G29_RECOVER_COMMANDS));
  212. #endif
  213. }
  214. #if ENABLED(G29_HALT_ON_FAILURE)
  215. #include "../lcd/marlinui.h"
  216. #endif
  217. void GcodeSuite::event_probe_failure() {
  218. #ifdef ACTION_ON_G29_FAILURE
  219. hostui.g29_failure();
  220. #endif
  221. #ifdef G29_FAILURE_COMMANDS
  222. process_subcommands_now(F(G29_FAILURE_COMMANDS));
  223. #endif
  224. #if ENABLED(G29_HALT_ON_FAILURE)
  225. #ifdef ACTION_ON_CANCEL
  226. hostui.cancel();
  227. #endif
  228. kill(GET_TEXT_F(MSG_LCD_PROBING_FAILED));
  229. #endif
  230. }
  231. #ifndef G29_MAX_RETRIES
  232. #define G29_MAX_RETRIES 0
  233. #endif
  234. void GcodeSuite::G29_with_retry() {
  235. uint8_t retries = G29_MAX_RETRIES;
  236. while (G29()) { // G29 should return true for failed probes ONLY
  237. if (retries) {
  238. event_probe_recover();
  239. --retries;
  240. }
  241. else {
  242. event_probe_failure();
  243. return;
  244. }
  245. }
  246. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_end());
  247. #ifdef G29_SUCCESS_COMMANDS
  248. process_subcommands_now(F(G29_SUCCESS_COMMANDS));
  249. #endif
  250. }
  251. #endif // G29_RETRY_AND_RECOVER
  252. /**
  253. * Process the parsed command and dispatch it to its handler
  254. */
  255. void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
  256. KEEPALIVE_STATE(IN_HANDLER);
  257. /**
  258. * Block all Gcodes except M511 Unlock Printer, if printer is locked
  259. * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu
  260. */
  261. #if ENABLED(PASSWORD_FEATURE)
  262. if (password.is_locked && !parser.is_command('M', 511)) {
  263. SERIAL_ECHO_MSG(STR_PRINTER_LOCKED);
  264. if (!no_ok) queue.ok_to_send();
  265. return;
  266. }
  267. #endif
  268. #if ENABLED(FLOWMETER_SAFETY)
  269. if (cooler.flowfault) {
  270. SERIAL_ECHO_MSG(STR_FLOWMETER_FAULT);
  271. return;
  272. }
  273. #endif
  274. // Handle a known command or reply "unknown command"
  275. switch (parser.command_letter) {
  276. case 'G': switch (parser.codenum) {
  277. case 0: case 1: // G0: Fast Move, G1: Linear Move
  278. G0_G1(TERN_(HAS_FAST_MOVES, parser.codenum == 0)); break;
  279. #if ENABLED(ARC_SUPPORT) && DISABLED(SCARA)
  280. case 2: case 3: G2_G3(parser.codenum == 2); break; // G2: CW ARC, G3: CCW ARC
  281. #endif
  282. case 4: G4(); break; // G4: Dwell
  283. #if ENABLED(BEZIER_CURVE_SUPPORT)
  284. case 5: G5(); break; // G5: Cubic B_spline
  285. #endif
  286. #if ENABLED(DIRECT_STEPPING)
  287. case 6: G6(); break; // G6: Direct Stepper Move
  288. #endif
  289. #if ENABLED(FWRETRACT)
  290. case 10: G10(); break; // G10: Retract / Swap Retract
  291. case 11: G11(); break; // G11: Recover / Swap Recover
  292. #endif
  293. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  294. case 12: G12(); break; // G12: Nozzle Clean
  295. #endif
  296. #if ENABLED(CNC_WORKSPACE_PLANES)
  297. case 17: G17(); break; // G17: Select Plane XY
  298. case 18: G18(); break; // G18: Select Plane ZX
  299. case 19: G19(); break; // G19: Select Plane YZ
  300. #endif
  301. #if ENABLED(INCH_MODE_SUPPORT)
  302. case 20: G20(); break; // G20: Inch Mode
  303. case 21: G21(); break; // G21: MM Mode
  304. #else
  305. case 21: NOOP; break; // No error on unknown G21
  306. #endif
  307. #if ENABLED(G26_MESH_VALIDATION)
  308. case 26: G26(); break; // G26: Mesh Validation Pattern generation
  309. #endif
  310. #if ENABLED(NOZZLE_PARK_FEATURE)
  311. case 27: G27(); break; // G27: Nozzle Park
  312. #endif
  313. case 28: G28(); break; // G28: Home one or more axes
  314. #if HAS_LEVELING
  315. case 29: // G29: Bed leveling calibration
  316. TERN(G29_RETRY_AND_RECOVER, G29_with_retry, G29)();
  317. break;
  318. #endif
  319. #if HAS_BED_PROBE
  320. case 30: G30(); break; // G30: Single Z probe
  321. #if ENABLED(Z_PROBE_SLED)
  322. case 31: G31(); break; // G31: dock the sled
  323. case 32: G32(); break; // G32: undock the sled
  324. #endif
  325. #endif
  326. #if ENABLED(DELTA_AUTO_CALIBRATION)
  327. case 33: G33(); break; // G33: Delta Auto-Calibration
  328. #endif
  329. #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  330. case 34: G34(); break; // G34: Z Stepper automatic alignment using probe
  331. #endif
  332. #if ENABLED(ASSISTED_TRAMMING)
  333. case 35: G35(); break; // G35: Read four bed corners to help adjust bed screws
  334. #endif
  335. #if ENABLED(G38_PROBE_TARGET)
  336. case 38: // G38.2, G38.3: Probe towards target
  337. if (WITHIN(parser.subcode, 2, TERN(G38_PROBE_AWAY, 5, 3)))
  338. G38(parser.subcode); // G38.4, G38.5: Probe away from target
  339. break;
  340. #endif
  341. #if HAS_MESH
  342. case 42: G42(); break; // G42: Coordinated move to a mesh point
  343. #endif
  344. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  345. case 53: G53(); break; // G53: (prefix) Apply native workspace
  346. case 54: G54(); break; // G54: Switch to Workspace 1
  347. case 55: G55(); break; // G55: Switch to Workspace 2
  348. case 56: G56(); break; // G56: Switch to Workspace 3
  349. case 57: G57(); break; // G57: Switch to Workspace 4
  350. case 58: G58(); break; // G58: Switch to Workspace 5
  351. case 59: G59(); break; // G59.0 - G59.3: Switch to Workspace 6-9
  352. #endif
  353. #if SAVED_POSITIONS
  354. case 60: G60(); break; // G60: save current position
  355. case 61: G61(); break; // G61: Apply/restore saved coordinates.
  356. #endif
  357. #if BOTH(PTC_PROBE, PTC_BED)
  358. case 76: G76(); break; // G76: Calibrate first layer compensation values
  359. #endif
  360. #if ENABLED(GCODE_MOTION_MODES)
  361. case 80: G80(); break; // G80: Reset the current motion mode
  362. #endif
  363. case 90: set_relative_mode(false); break; // G90: Absolute Mode
  364. case 91: set_relative_mode(true); break; // G91: Relative Mode
  365. case 92: G92(); break; // G92: Set current axis position(s)
  366. #if ENABLED(CALIBRATION_GCODE)
  367. case 425: G425(); break; // G425: Perform calibration with calibration cube
  368. #endif
  369. #if ENABLED(DEBUG_GCODE_PARSER)
  370. case 800: parser.debug(); break; // G800: GCode Parser Test for G
  371. #endif
  372. default: parser.unknown_command_warning(); break;
  373. }
  374. break;
  375. case 'M': switch (parser.codenum) {
  376. #if HAS_RESUME_CONTINUE
  377. case 0: // M0: Unconditional stop - Wait for user button press on LCD
  378. case 1: M0_M1(); break; // M1: Conditional stop - Wait for user button press on LCD
  379. #endif
  380. #if HAS_CUTTER
  381. case 3: M3_M4(false); break; // M3: Turn ON Laser | Spindle (clockwise), set Power | Speed
  382. case 4: M3_M4(true ); break; // M4: Turn ON Laser | Spindle (counter-clockwise), set Power | Speed
  383. case 5: M5(); break; // M5: Turn OFF Laser | Spindle
  384. #endif
  385. #if ENABLED(COOLANT_MIST)
  386. case 7: M7(); break; // M7: Coolant Mist ON
  387. #endif
  388. #if EITHER(AIR_ASSIST, COOLANT_FLOOD)
  389. case 8: M8(); break; // M8: Air Assist / Coolant Flood ON
  390. #endif
  391. #if EITHER(AIR_ASSIST, COOLANT_CONTROL)
  392. case 9: M9(); break; // M9: Air Assist / Coolant OFF
  393. #endif
  394. #if ENABLED(AIR_EVACUATION)
  395. case 10: M10(); break; // M10: Vacuum or Blower motor ON
  396. case 11: M11(); break; // M11: Vacuum or Blower motor OFF
  397. #endif
  398. #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
  399. case 12: M12(); break; // M12: Synchronize and optionally force a CLC set
  400. #endif
  401. #if ENABLED(EXPECTED_PRINTER_CHECK)
  402. case 16: M16(); break; // M16: Expected printer check
  403. #endif
  404. case 17: M17(); break; // M17: Enable all stepper motors
  405. #if ENABLED(SDSUPPORT)
  406. case 20: M20(); break; // M20: List SD card
  407. case 21: M21(); break; // M21: Init SD card
  408. case 22: M22(); break; // M22: Release SD card
  409. case 23: M23(); break; // M23: Select file
  410. case 24: M24(); break; // M24: Start SD print
  411. case 25: M25(); break; // M25: Pause SD print
  412. case 26: M26(); break; // M26: Set SD index
  413. case 27: M27(); break; // M27: Get SD status
  414. case 28: M28(); break; // M28: Start SD write
  415. case 29: M29(); break; // M29: Stop SD write
  416. case 30: M30(); break; // M30 <filename> Delete File
  417. #if HAS_MEDIA_SUBCALLS
  418. case 32: M32(); break; // M32: Select file and start SD print
  419. #endif
  420. #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
  421. case 33: M33(); break; // M33: Get the long full path to a file or folder
  422. #endif
  423. #if BOTH(SDCARD_SORT_ALPHA, SDSORT_GCODE)
  424. case 34: M34(); break; // M34: Set SD card sorting options
  425. #endif
  426. case 928: M928(); break; // M928: Start SD write
  427. #endif // SDSUPPORT
  428. case 31: M31(); break; // M31: Report time since the start of SD print or last M109
  429. #if ENABLED(DIRECT_PIN_CONTROL)
  430. case 42: M42(); break; // M42: Change pin state
  431. #endif
  432. #if ENABLED(PINS_DEBUGGING)
  433. case 43: M43(); break; // M43: Read pin state
  434. #endif
  435. #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
  436. case 48: M48(); break; // M48: Z probe repeatability test
  437. #endif
  438. #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
  439. case 73: M73(); break; // M73: Set progress percentage (for display on LCD)
  440. #endif
  441. case 75: M75(); break; // M75: Start print timer
  442. case 76: M76(); break; // M76: Pause print timer
  443. case 77: M77(); break; // M77: Stop print timer
  444. #if ENABLED(PRINTCOUNTER)
  445. case 78: M78(); break; // M78: Show print statistics
  446. #endif
  447. #if ENABLED(M100_FREE_MEMORY_WATCHER)
  448. case 100: M100(); break; // M100: Free Memory Report
  449. #endif
  450. #if HAS_EXTRUDERS
  451. case 104: M104(); break; // M104: Set hot end temperature
  452. case 109: M109(); break; // M109: Wait for hotend temperature to reach target
  453. #endif
  454. case 105: M105(); return; // M105: Report Temperatures (and say "ok")
  455. #if HAS_FAN
  456. case 106: M106(); break; // M106: Fan On
  457. case 107: M107(); break; // M107: Fan Off
  458. #endif
  459. case 110: M110(); break; // M110: Set Current Line Number
  460. case 111: M111(); break; // M111: Set debug level
  461. #if DISABLED(EMERGENCY_PARSER)
  462. case 108: M108(); break; // M108: Cancel Waiting
  463. case 112: M112(); break; // M112: Full Shutdown
  464. case 410: M410(); break; // M410: Quickstop - Abort all the planned moves.
  465. TERN_(HOST_PROMPT_SUPPORT, case 876:) // M876: Handle Host prompt responses
  466. #else
  467. case 108: case 112: case 410:
  468. TERN_(HOST_PROMPT_SUPPORT, case 876:)
  469. break;
  470. #endif
  471. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  472. case 113: M113(); break; // M113: Set Host Keepalive interval
  473. #endif
  474. #if HAS_HEATED_BED
  475. case 140: M140(); break; // M140: Set bed temperature
  476. case 190: M190(); break; // M190: Wait for bed temperature to reach target
  477. #endif
  478. #if HAS_HEATED_CHAMBER
  479. case 141: M141(); break; // M141: Set chamber temperature
  480. case 191: M191(); break; // M191: Wait for chamber temperature to reach target
  481. #endif
  482. #if HAS_TEMP_PROBE
  483. case 192: M192(); break; // M192: Wait for probe temp
  484. #endif
  485. #if HAS_COOLER
  486. case 143: M143(); break; // M143: Set cooler temperature
  487. case 193: M193(); break; // M193: Wait for cooler temperature to reach target
  488. #endif
  489. #if ENABLED(AUTO_REPORT_POSITION)
  490. case 154: M154(); break; // M154: Set position auto-report interval
  491. #endif
  492. #if BOTH(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR)
  493. case 155: M155(); break; // M155: Set temperature auto-report interval
  494. #endif
  495. #if ENABLED(PARK_HEAD_ON_PAUSE)
  496. case 125: M125(); break; // M125: Store current position and move to filament change position
  497. #endif
  498. #if ENABLED(BARICUDA)
  499. // PWM for HEATER_1_PIN
  500. #if HAS_HEATER_1
  501. case 126: M126(); break; // M126: valve open
  502. case 127: M127(); break; // M127: valve closed
  503. #endif
  504. // PWM for HEATER_2_PIN
  505. #if HAS_HEATER_2
  506. case 128: M128(); break; // M128: valve open
  507. case 129: M129(); break; // M129: valve closed
  508. #endif
  509. #endif // BARICUDA
  510. #if ENABLED(PSU_CONTROL)
  511. case 80: M80(); break; // M80: Turn on Power Supply
  512. #endif
  513. case 81: M81(); break; // M81: Turn off Power, including Power Supply, if possible
  514. #if HAS_EXTRUDERS
  515. case 82: M82(); break; // M82: Set E axis normal mode (same as other axes)
  516. case 83: M83(); break; // M83: Set E axis relative mode
  517. #endif
  518. case 18: case 84: M18_M84(); break; // M18/M84: Disable Steppers / Set Timeout
  519. case 85: M85(); break; // M85: Set inactivity stepper shutdown timeout
  520. case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes
  521. case 114: M114(); break; // M114: Report current position
  522. case 115: M115(); break; // M115: Report capabilities
  523. case 117: TERN_(HAS_STATUS_MESSAGE, M117()); break; // M117: Set LCD message text, if possible
  524. case 118: M118(); break; // M118: Display a message in the host console
  525. case 119: M119(); break; // M119: Report endstop states
  526. case 120: M120(); break; // M120: Enable endstops
  527. case 121: M121(); break; // M121: Disable endstops
  528. #if HAS_PREHEAT
  529. case 145: M145(); break; // M145: Set material heatup parameters
  530. #endif
  531. #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
  532. case 149: M149(); break; // M149: Set temperature units
  533. #endif
  534. #if HAS_COLOR_LEDS
  535. case 150: M150(); break; // M150: Set Status LED Color
  536. #endif
  537. #if ENABLED(MIXING_EXTRUDER)
  538. case 163: M163(); break; // M163: Set a component weight for mixing extruder
  539. case 164: M164(); break; // M164: Save current mix as a virtual extruder
  540. #if ENABLED(DIRECT_MIXING_IN_G1)
  541. case 165: M165(); break; // M165: Set multiple mix weights
  542. #endif
  543. #if ENABLED(GRADIENT_MIX)
  544. case 166: M166(); break; // M166: Set Gradient Mix
  545. #endif
  546. #endif
  547. #if DISABLED(NO_VOLUMETRICS)
  548. case 200: M200(); break; // M200: Set filament diameter, E to cubic units
  549. #endif
  550. case 201: M201(); break; // M201: Set max acceleration for print moves (units/s^2)
  551. #if 0
  552. case 202: M202(); break; // M202: Not used for Sprinter/grbl gen6
  553. #endif
  554. case 203: M203(); break; // M203: Set max feedrate (units/sec)
  555. case 204: M204(); break; // M204: Set acceleration
  556. case 205: M205(); break; // M205: Set advanced settings
  557. #if HAS_M206_COMMAND
  558. case 206: M206(); break; // M206: Set home offsets
  559. #endif
  560. #if ENABLED(FWRETRACT)
  561. case 207: M207(); break; // M207: Set Retract Length, Feedrate, and Z lift
  562. case 208: M208(); break; // M208: Set Recover (unretract) Additional Length and Feedrate
  563. #if ENABLED(FWRETRACT_AUTORETRACT)
  564. case 209:
  565. if (MIN_AUTORETRACT <= MAX_AUTORETRACT) M209(); // M209: Turn Automatic Retract Detection on/off
  566. break;
  567. #endif
  568. #endif
  569. #if HAS_SOFTWARE_ENDSTOPS
  570. case 211: M211(); break; // M211: Enable, Disable, and/or Report software endstops
  571. #endif
  572. #if HAS_MULTI_EXTRUDER
  573. case 217: M217(); break; // M217: Set filament swap parameters
  574. #endif
  575. #if HAS_HOTEND_OFFSET
  576. case 218: M218(); break; // M218: Set a tool offset
  577. #endif
  578. case 220: M220(); break; // M220: Set Feedrate Percentage: S<percent> ("FR" on your LCD)
  579. #if HAS_EXTRUDERS
  580. case 221: M221(); break; // M221: Set Flow Percentage
  581. #endif
  582. #if ENABLED(DIRECT_PIN_CONTROL)
  583. case 226: M226(); break; // M226: Wait until a pin reaches a state
  584. #endif
  585. #if HAS_SERVOS
  586. case 280: M280(); break; // M280: Set servo position absolute
  587. #if ENABLED(EDITABLE_SERVO_ANGLES)
  588. case 281: M281(); break; // M281: Set servo angles
  589. #endif
  590. #if ENABLED(SERVO_DETACH_GCODE)
  591. case 282: M282(); break; // M282: Detach servo
  592. #endif
  593. #endif
  594. #if ENABLED(BABYSTEPPING)
  595. case 290: M290(); break; // M290: Babystepping
  596. #endif
  597. #if HAS_BUZZER
  598. case 300: M300(); break; // M300: Play beep tone
  599. #endif
  600. #if ENABLED(PIDTEMP)
  601. case 301: M301(); break; // M301: Set hotend PID parameters
  602. #endif
  603. #if ENABLED(PIDTEMPBED)
  604. case 304: M304(); break; // M304: Set bed PID parameters
  605. #endif
  606. #if ENABLED(PIDTEMPCHAMBER)
  607. case 309: M309(); break; // M309: Set chamber PID parameters
  608. #endif
  609. #if ENABLED(PHOTO_GCODE)
  610. case 240: M240(); break; // M240: Trigger a camera
  611. #endif
  612. #if HAS_LCD_CONTRAST
  613. case 250: M250(); break; // M250: Set LCD contrast
  614. #endif
  615. #if HAS_LCD_BRIGHTNESS
  616. case 256: M256(); break; // M256: Set LCD brightness
  617. #endif
  618. #if ENABLED(EXPERIMENTAL_I2CBUS)
  619. case 260: M260(); break; // M260: Send data to an i2c slave
  620. case 261: M261(); break; // M261: Request data from an i2c slave
  621. #endif
  622. #if ENABLED(PREVENT_COLD_EXTRUSION)
  623. case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
  624. #endif
  625. #if HAS_PID_HEATING
  626. case 303: M303(); break; // M303: PID autotune
  627. #endif
  628. #if HAS_USER_THERMISTORS
  629. case 305: M305(); break; // M305: Set user thermistor parameters
  630. #endif
  631. #if ENABLED(REPETIER_GCODE_M360)
  632. case 360: M360(); break; // M360: Firmware settings
  633. #endif
  634. #if ENABLED(MORGAN_SCARA)
  635. case 360: if (M360()) return; break; // M360: SCARA Theta pos1
  636. case 361: if (M361()) return; break; // M361: SCARA Theta pos2
  637. case 362: if (M362()) return; break; // M362: SCARA Psi pos1
  638. case 363: if (M363()) return; break; // M363: SCARA Psi pos2
  639. case 364: if (M364()) return; break; // M364: SCARA Psi pos3 (90 deg to Theta)
  640. #endif
  641. #if EITHER(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL)
  642. case 380: M380(); break; // M380: Activate solenoid on active (or specified) extruder
  643. case 381: M381(); break; // M381: Disable all solenoids or, if MANUAL_SOLENOID_CONTROL, active (or specified) solenoid
  644. #endif
  645. case 400: M400(); break; // M400: Finish all moves
  646. #if HAS_BED_PROBE
  647. case 401: M401(); break; // M401: Deploy probe
  648. case 402: M402(); break; // M402: Stow probe
  649. #endif
  650. #if HAS_PRUSA_MMU2
  651. case 403: M403(); break;
  652. #endif
  653. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  654. case 404: M404(); break; // M404: Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
  655. case 405: M405(); break; // M405: Turn on filament sensor for control
  656. case 406: M406(); break; // M406: Turn off filament sensor for control
  657. case 407: M407(); break; // M407: Display measured filament diameter
  658. #endif
  659. #if HAS_FILAMENT_SENSOR
  660. case 412: M412(); break; // M412: Enable/Disable filament runout detection
  661. #endif
  662. #if HAS_MULTI_LANGUAGE
  663. case 414: M414(); break; // M414: Select multi language menu
  664. #endif
  665. #if HAS_LEVELING
  666. case 420: M420(); break; // M420: Enable/Disable Bed Leveling
  667. #endif
  668. #if HAS_MESH
  669. case 421: M421(); break; // M421: Set a Mesh Bed Leveling Z coordinate
  670. #endif
  671. #if ENABLED(BACKLASH_GCODE)
  672. case 425: M425(); break; // M425: Tune backlash compensation
  673. #endif
  674. #if HAS_M206_COMMAND
  675. case 428: M428(); break; // M428: Apply current_position to home_offset
  676. #endif
  677. #if HAS_POWER_MONITOR
  678. case 430: M430(); break; // M430: Read the system current (A), voltage (V), and power (W)
  679. #endif
  680. #if ENABLED(CANCEL_OBJECTS)
  681. case 486: M486(); break; // M486: Identify and cancel objects
  682. #endif
  683. case 500: M500(); break; // M500: Store settings in EEPROM
  684. case 501: M501(); break; // M501: Read settings from EEPROM
  685. case 502: M502(); break; // M502: Revert to default settings
  686. #if DISABLED(DISABLE_M503)
  687. case 503: M503(); break; // M503: print settings currently in memory
  688. #endif
  689. #if ENABLED(EEPROM_SETTINGS)
  690. case 504: M504(); break; // M504: Validate EEPROM contents
  691. #endif
  692. #if ENABLED(PASSWORD_FEATURE)
  693. case 510: M510(); break; // M510: Lock Printer
  694. #if ENABLED(PASSWORD_UNLOCK_GCODE)
  695. case 511: M511(); break; // M511: Unlock Printer
  696. #endif
  697. #if ENABLED(PASSWORD_CHANGE_GCODE)
  698. case 512: M512(); break; // M512: Set/Change/Remove Password
  699. #endif
  700. #endif
  701. #if ENABLED(SDSUPPORT)
  702. case 524: M524(); break; // M524: Abort the current SD print job
  703. #endif
  704. #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT)
  705. case 540: M540(); break; // M540: Set abort on endstop hit for SD printing
  706. #endif
  707. #if HAS_ETHERNET
  708. case 552: M552(); break; // M552: Set IP address
  709. case 553: M553(); break; // M553: Set gateway
  710. case 554: M554(); break; // M554: Set netmask
  711. #endif
  712. #if ENABLED(BAUD_RATE_GCODE)
  713. case 575: M575(); break; // M575: Set serial baudrate
  714. #endif
  715. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  716. case 600: M600(); break; // M600: Pause for Filament Change
  717. case 603: M603(); break; // M603: Configure Filament Change
  718. #endif
  719. #if HAS_DUPLICATION_MODE
  720. case 605: M605(); break; // M605: Set Dual X Carriage movement mode
  721. #endif
  722. #if IS_KINEMATIC
  723. case 665: M665(); break; // M665: Set Delta/SCARA parameters
  724. #endif
  725. #if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
  726. case 666: M666(); break; // M666: Set delta or multiple endstop adjustment
  727. #endif
  728. #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
  729. case 672: M672(); break; // M672: Set/clear Duet Smart Effector sensitivity
  730. #endif
  731. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  732. case 701: M701(); break; // M701: Load Filament
  733. case 702: M702(); break; // M702: Unload Filament
  734. #endif
  735. #if ENABLED(CONTROLLER_FAN_EDITABLE)
  736. case 710: M710(); break; // M710: Set Controller Fan settings
  737. #endif
  738. #if ENABLED(GCODE_MACROS)
  739. case 810: case 811: case 812: case 813: case 814:
  740. case 815: case 816: case 817: case 818: case 819:
  741. M810_819(); break; // M810-M819: Define/execute G-code macro
  742. #endif
  743. #if HAS_BED_PROBE
  744. case 851: M851(); break; // M851: Set Z Probe Z Offset
  745. #endif
  746. #if ENABLED(SKEW_CORRECTION_GCODE)
  747. case 852: M852(); break; // M852: Set Skew factors
  748. #endif
  749. #if HAS_PTC
  750. case 871: M871(); break; // M871: Print/reset/clear first layer temperature offset values
  751. #endif
  752. #if ENABLED(LIN_ADVANCE)
  753. case 900: M900(); break; // M900: Set advance K factor.
  754. #endif
  755. #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC)
  756. case 907: M907(); break; // M907: Set digital trimpot motor current using axis codes.
  757. #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC)
  758. case 908: M908(); break; // M908: Control digital trimpot directly.
  759. #if HAS_MOTOR_CURRENT_DAC
  760. case 909: M909(); break; // M909: Print digipot/DAC current value
  761. case 910: M910(); break; // M910: Commit digipot/DAC value to external EEPROM
  762. #endif
  763. #endif
  764. #endif
  765. #if HAS_TRINAMIC_CONFIG
  766. case 122: M122(); break; // M122: Report driver configuration and status
  767. case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E
  768. #if HAS_STEALTHCHOP
  769. case 569: M569(); break; // M569: Enable stealthChop on an axis.
  770. #endif
  771. #if ENABLED(MONITOR_DRIVER_STATUS)
  772. case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
  773. case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags
  774. #endif
  775. #if ENABLED(HYBRID_THRESHOLD)
  776. case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed.
  777. #endif
  778. #if USE_SENSORLESS
  779. case 914: M914(); break; // M914: Set StallGuard sensitivity.
  780. #endif
  781. #endif
  782. #if HAS_L64XX
  783. case 122: M122(); break; // M122: Report status
  784. case 906: M906(); break; // M906: Set or get motor drive level
  785. case 916: M916(); break; // M916: L6470 tuning: Increase drive level until thermal warning
  786. case 917: M917(); break; // M917: L6470 tuning: Find minimum current thresholds
  787. case 918: M918(); break; // M918: L6470 tuning: Increase speed until max or error
  788. #endif
  789. #if HAS_MICROSTEPS
  790. case 350: M350(); break; // M350: Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
  791. case 351: M351(); break; // M351: Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low.
  792. #endif
  793. #if ENABLED(CASE_LIGHT_ENABLE)
  794. case 355: M355(); break; // M355: Set case light brightness
  795. #endif
  796. #if ENABLED(DEBUG_GCODE_PARSER)
  797. case 800: parser.debug(); break; // M800: GCode Parser Test for M
  798. #endif
  799. #if ENABLED(GCODE_REPEAT_MARKERS)
  800. case 808: M808(); break; // M808: Set / Goto repeat markers
  801. #endif
  802. #if ENABLED(I2C_POSITION_ENCODERS)
  803. case 860: M860(); break; // M860: Report encoder module position
  804. case 861: M861(); break; // M861: Report encoder module status
  805. case 862: M862(); break; // M862: Perform axis test
  806. case 863: M863(); break; // M863: Calibrate steps/mm
  807. case 864: M864(); break; // M864: Change module address
  808. case 865: M865(); break; // M865: Check module firmware version
  809. case 866: M866(); break; // M866: Report axis error count
  810. case 867: M867(); break; // M867: Toggle error correction
  811. case 868: M868(); break; // M868: Set error correction threshold
  812. case 869: M869(); break; // M869: Report axis error
  813. #endif
  814. #if ENABLED(MAGNETIC_PARKING_EXTRUDER)
  815. case 951: M951(); break; // M951: Set Magnetic Parking Extruder parameters
  816. #endif
  817. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  818. case 422: M422(); break; // M422: Set Z Stepper automatic alignment position using probe
  819. #endif
  820. #if ALL(HAS_SPI_FLASH, SDSUPPORT, MARLIN_DEV_MODE)
  821. case 993: M993(); break; // M993: Backup SPI Flash to SD
  822. case 994: M994(); break; // M994: Load a Backup from SD to SPI Flash
  823. #endif
  824. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  825. case 995: M995(); break; // M995: Touch screen calibration for TFT display
  826. #endif
  827. #if ENABLED(PLATFORM_M997_SUPPORT)
  828. case 997: M997(); break; // M997: Perform in-application firmware update
  829. #endif
  830. case 999: M999(); break; // M999: Restart after being Stopped
  831. #if ENABLED(POWER_LOSS_RECOVERY)
  832. case 413: M413(); break; // M413: Enable/disable/query Power-Loss Recovery
  833. case 1000: M1000(); break; // M1000: [INTERNAL] Resume from power-loss
  834. #endif
  835. #if ENABLED(SDSUPPORT)
  836. case 1001: M1001(); break; // M1001: [INTERNAL] Handle SD completion
  837. #endif
  838. #if ENABLED(DGUS_LCD_UI_MKS)
  839. case 1002: M1002(); break; // M1002: [INTERNAL] Tool-change and Relative E Move
  840. #endif
  841. #if ENABLED(UBL_MESH_WIZARD)
  842. case 1004: M1004(); break; // M1004: UBL Mesh Wizard
  843. #endif
  844. #if ENABLED(MAX7219_GCODE)
  845. case 7219: M7219(); break; // M7219: Set LEDs, columns, and rows
  846. #endif
  847. default: parser.unknown_command_warning(); break;
  848. }
  849. break;
  850. case 'T': T(parser.codenum); break; // Tn: Tool Change
  851. #if ENABLED(MARLIN_DEV_MODE)
  852. case 'D': D(parser.codenum); break; // Dn: Debug codes
  853. #endif
  854. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  855. case 'S': case 'P': case 'R': break; // Invalid S, P, R commands already filtered
  856. #endif
  857. default:
  858. #if ENABLED(WIFI_CUSTOM_COMMAND)
  859. if (wifi_custom_command(parser.command_ptr)) break;
  860. #endif
  861. parser.unknown_command_warning();
  862. }
  863. if (!no_ok) queue.ok_to_send();
  864. SERIAL_OUT(msgDone); // Call the msgDone serial hook to signal command processing done
  865. }
  866. #if ENABLED(M100_FREE_MEMORY_DUMPER)
  867. void M100_dump_routine(FSTR_P const title, const char * const start, const uintptr_t size);
  868. #endif
  869. /**
  870. * Process a single command and dispatch it to its handler
  871. * This is called from the main loop()
  872. */
  873. void GcodeSuite::process_next_command() {
  874. GCodeQueue::CommandLine &command = queue.ring_buffer.peek_next_command();
  875. PORT_REDIRECT(SERIAL_PORTMASK(command.port));
  876. TERN_(POWER_LOSS_RECOVERY, recovery.queue_index_r = queue.ring_buffer.index_r);
  877. if (DEBUGGING(ECHO)) {
  878. SERIAL_ECHO_START();
  879. SERIAL_ECHOLN(command.buffer);
  880. #if ENABLED(M100_FREE_MEMORY_DUMPER)
  881. SERIAL_ECHOPGM("slot:", queue.ring_buffer.index_r);
  882. M100_dump_routine(F(" Command Queue:"), (const char*)&queue.ring_buffer, sizeof(queue.ring_buffer));
  883. #endif
  884. }
  885. // Parse the next command in the queue
  886. parser.parse(command.buffer);
  887. process_parsed_command();
  888. }
  889. #pragma GCC diagnostic push
  890. #if GCC_VERSION >= 80000
  891. #pragma GCC diagnostic ignored "-Wstringop-truncation"
  892. #endif
  893. /**
  894. * Run a series of commands, bypassing the command queue to allow
  895. * G-code "macros" to be called from within other G-code handlers.
  896. */
  897. void GcodeSuite::process_subcommands_now(FSTR_P fgcode) {
  898. PGM_P pgcode = FTOP(fgcode);
  899. char * const saved_cmd = parser.command_ptr; // Save the parser state
  900. for (;;) {
  901. PGM_P const delim = strchr_P(pgcode, '\n'); // Get address of next newline
  902. const size_t len = delim ? delim - pgcode : strlen_P(pgcode); // Get the command length
  903. char cmd[len + 1]; // Allocate a stack buffer
  904. strncpy_P(cmd, pgcode, len); // Copy the command to the stack
  905. cmd[len] = '\0'; // End with a nul
  906. parser.parse(cmd); // Parse the command
  907. process_parsed_command(true); // Process it (no "ok")
  908. if (!delim) break; // Last command?
  909. pgcode = delim + 1; // Get the next command
  910. }
  911. parser.parse(saved_cmd); // Restore the parser state
  912. }
  913. #pragma GCC diagnostic pop
  914. void GcodeSuite::process_subcommands_now(char * gcode) {
  915. char * const saved_cmd = parser.command_ptr; // Save the parser state
  916. for (;;) {
  917. char * const delim = strchr(gcode, '\n'); // Get address of next newline
  918. if (delim) *delim = '\0'; // Replace with nul
  919. parser.parse(gcode); // Parse the current command
  920. process_parsed_command(true); // Process it (no "ok")
  921. if (!delim) break; // Last command?
  922. *delim = '\n'; // Put back the newline
  923. gcode = delim + 1; // Get the next command
  924. }
  925. parser.parse(saved_cmd); // Restore the parser state
  926. }
  927. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  928. /**
  929. * Output a "busy" message at regular intervals
  930. * while the machine is not accepting commands.
  931. */
  932. void GcodeSuite::host_keepalive() {
  933. const millis_t ms = millis();
  934. static millis_t next_busy_signal_ms = 0;
  935. if (!autoreport_paused && host_keepalive_interval && busy_state != NOT_BUSY) {
  936. if (PENDING(ms, next_busy_signal_ms)) return;
  937. PORT_REDIRECT(SerialMask::All);
  938. switch (busy_state) {
  939. case IN_HANDLER:
  940. case IN_PROCESS:
  941. SERIAL_ECHO_MSG(STR_BUSY_PROCESSING);
  942. TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_position_moving());
  943. break;
  944. case PAUSED_FOR_USER:
  945. SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_USER);
  946. TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD));
  947. break;
  948. case PAUSED_FOR_INPUT:
  949. SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_INPUT);
  950. TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD));
  951. break;
  952. default:
  953. break;
  954. }
  955. }
  956. next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval);
  957. }
  958. #endif // HOST_KEEPALIVE_FEATURE