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

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