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 49KB

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