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.

Marlin_main.cpp 68KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233
  1. /* -*- c++ -*- */
  2. /*
  3. Reprap firmware based on Sprinter and grbl.
  4. Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. This firmware is a mashup between Sprinter and grbl.
  18. (https://github.com/kliment/Sprinter)
  19. (https://github.com/simen/grbl/tree)
  20. It has preliminary support for Matthew Roberts advance algorithm
  21. http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
  22. */
  23. #include "Marlin.h"
  24. #include "ultralcd.h"
  25. #include "planner.h"
  26. #include "stepper.h"
  27. #include "temperature.h"
  28. #include "motion_control.h"
  29. #include "cardreader.h"
  30. #include "watchdog.h"
  31. #include "ConfigurationStore.h"
  32. #include "language.h"
  33. #include "pins_arduino.h"
  34. #if DIGIPOTSS_PIN > -1
  35. #include <SPI.h>
  36. #endif
  37. #define VERSION_STRING "1.0.0"
  38. // look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html
  39. // http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
  40. //Implemented Codes
  41. //-------------------
  42. // G0 -> G1
  43. // G1 - Coordinated Movement X Y Z E
  44. // G2 - CW ARC
  45. // G3 - CCW ARC
  46. // G4 - Dwell S<seconds> or P<milliseconds>
  47. // G10 - retract filament according to settings of M207
  48. // G11 - retract recover filament according to settings of M208
  49. // G28 - Home all Axis
  50. // G90 - Use Absolute Coordinates
  51. // G91 - Use Relative Coordinates
  52. // G92 - Set current position to cordinates given
  53. //RepRap M Codes
  54. // M0 - Unconditional stop - Wait for user to press a button on the LCD (Only if ULTRA_LCD is enabled)
  55. // M1 - Same as M0
  56. // M104 - Set extruder target temp
  57. // M105 - Read current temp
  58. // M106 - Fan on
  59. // M107 - Fan off
  60. // M109 - Wait for extruder current temp to reach target temp.
  61. // M114 - Display current position
  62. //Custom M Codes
  63. // M17 - Enable/Power all stepper motors
  64. // M18 - Disable all stepper motors; same as M84
  65. // M20 - List SD card
  66. // M21 - Init SD card
  67. // M22 - Release SD card
  68. // M23 - Select SD file (M23 filename.g)
  69. // M24 - Start/resume SD print
  70. // M25 - Pause SD print
  71. // M26 - Set SD position in bytes (M26 S12345)
  72. // M27 - Report SD print status
  73. // M28 - Start SD write (M28 filename.g)
  74. // M29 - Stop SD write
  75. // M30 - Delete file from SD (M30 filename.g)
  76. // M31 - Output time since last M109 or SD card start to serial
  77. // M42 - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used.
  78. // M80 - Turn on Power Supply
  79. // M81 - Turn off Power Supply
  80. // M82 - Set E codes absolute (default)
  81. // M83 - Set E codes relative while in Absolute Coordinates (G90) mode
  82. // M84 - Disable steppers until next move,
  83. // or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled. S0 to disable the timeout.
  84. // M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
  85. // M92 - Set axis_steps_per_unit - same syntax as G92
  86. // M114 - Output current position to serial port
  87. // M115 - Capabilities string
  88. // M117 - display message
  89. // M119 - Output Endstop status to serial port
  90. // M126 - Solenoid Air Valve Open (BariCUDA support by jmil)
  91. // M127 - Solenoid Air Valve Closed (BariCUDA vent to atmospheric pressure by jmil)
  92. // M128 - EtoP Open (BariCUDA EtoP = electricity to air pressure transducer by jmil)
  93. // M129 - EtoP Closed (BariCUDA EtoP = electricity to air pressure transducer by jmil)
  94. // M140 - Set bed target temp
  95. // M190 - Wait for bed current temp to reach target temp.
  96. // M200 - Set filament diameter
  97. // M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
  98. // M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!
  99. // M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec
  100. // M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate
  101. // M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk
  102. // M206 - set additional homeing offset
  103. // M207 - set retract length S[positive mm] F[feedrate mm/sec] Z[additional zlift/hop]
  104. // M208 - set recover=unretract length S[positive mm surplus to the M207 S*] F[feedrate mm/sec]
  105. // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction.
  106. // M218 - set hotend offset (in mm): T<extruder_number> X<offset_on_X> Y<offset_on_Y>
  107. // M220 S<factor in percent>- set speed factor override percentage
  108. // M221 S<factor in percent>- set extrude factor override percentage
  109. // M240 - Trigger a camera to take a photograph
  110. // M300 - Play beepsound S<frequency Hz> P<duration ms>
  111. // M301 - Set PID parameters P I and D
  112. // M302 - Allow cold extrudes
  113. // M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C)
  114. // M304 - Set bed PID parameters P I and D
  115. // M400 - Finish all moves
  116. // M500 - stores paramters in EEPROM
  117. // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
  118. // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
  119. // M503 - print the current settings (from memory not from eeprom)
  120. // M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  121. // M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
  122. // M907 - Set digital trimpot motor current using axis codes.
  123. // M908 - Control digital trimpot directly.
  124. // M350 - Set microstepping mode.
  125. // M351 - Toggle MS1 MS2 pins directly.
  126. // M928 - Start SD logging (M928 filename.g) - ended by M29
  127. // M999 - Restart after being stopped by error
  128. //Stepper Movement Variables
  129. //===========================================================================
  130. //=============================imported variables============================
  131. //===========================================================================
  132. //===========================================================================
  133. //=============================public variables=============================
  134. //===========================================================================
  135. #ifdef SDSUPPORT
  136. CardReader card;
  137. #endif
  138. float homing_feedrate[] = HOMING_FEEDRATE;
  139. bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
  140. int feedmultiply=100; //100->1 200->2
  141. int saved_feedmultiply;
  142. int extrudemultiply=100; //100->1 200->2
  143. float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
  144. float add_homeing[3]={0,0,0};
  145. float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
  146. float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
  147. // Extruder offset, only in XY plane
  148. #if EXTRUDERS > 1
  149. float extruder_offset[2][EXTRUDERS] = {
  150. #if defined(EXTRUDER_OFFSET_X) && defined(EXTRUDER_OFFSET_Y)
  151. EXTRUDER_OFFSET_X, EXTRUDER_OFFSET_Y
  152. #endif
  153. };
  154. #endif
  155. uint8_t active_extruder = 0;
  156. int fanSpeed=0;
  157. #ifdef BARICUDA
  158. int ValvePressure=0;
  159. int EtoPPressure=0;
  160. #endif
  161. #ifdef FWRETRACT
  162. bool autoretract_enabled=true;
  163. bool retracted=false;
  164. float retract_length=3, retract_feedrate=17*60, retract_zlift=0.8;
  165. float retract_recover_length=0, retract_recover_feedrate=8*60;
  166. #endif
  167. //===========================================================================
  168. //=============================private variables=============================
  169. //===========================================================================
  170. const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
  171. static float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
  172. static float offset[3] = {0.0, 0.0, 0.0};
  173. static bool home_all_axis = true;
  174. static float feedrate = 1500.0, next_feedrate, saved_feedrate;
  175. static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;
  176. static bool relative_mode = false; //Determines Absolute or Relative Coordinates
  177. static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
  178. static bool fromsd[BUFSIZE];
  179. static int bufindr = 0;
  180. static int bufindw = 0;
  181. static int buflen = 0;
  182. //static int i = 0;
  183. static char serial_char;
  184. static int serial_count = 0;
  185. static boolean comment_mode = false;
  186. static char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
  187. const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
  188. //static float tt = 0;
  189. //static float bt = 0;
  190. //Inactivity shutdown variables
  191. static unsigned long previous_millis_cmd = 0;
  192. static unsigned long max_inactive_time = 0;
  193. static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l;
  194. unsigned long starttime=0;
  195. unsigned long stoptime=0;
  196. static uint8_t tmp_extruder;
  197. bool Stopped=false;
  198. //===========================================================================
  199. //=============================ROUTINES=============================
  200. //===========================================================================
  201. void get_arc_coordinates();
  202. bool setTargetedHotend(int code);
  203. void serial_echopair_P(const char *s_P, float v)
  204. { serialprintPGM(s_P); SERIAL_ECHO(v); }
  205. void serial_echopair_P(const char *s_P, double v)
  206. { serialprintPGM(s_P); SERIAL_ECHO(v); }
  207. void serial_echopair_P(const char *s_P, unsigned long v)
  208. { serialprintPGM(s_P); SERIAL_ECHO(v); }
  209. extern "C"{
  210. extern unsigned int __bss_end;
  211. extern unsigned int __heap_start;
  212. extern void *__brkval;
  213. int freeMemory() {
  214. int free_memory;
  215. if((int)__brkval == 0)
  216. free_memory = ((int)&free_memory) - ((int)&__bss_end);
  217. else
  218. free_memory = ((int)&free_memory) - ((int)__brkval);
  219. return free_memory;
  220. }
  221. }
  222. //adds an command to the main command buffer
  223. //thats really done in a non-safe way.
  224. //needs overworking someday
  225. void enquecommand(const char *cmd)
  226. {
  227. if(buflen < BUFSIZE)
  228. {
  229. //this is dangerous if a mixing of serial and this happsens
  230. strcpy(&(cmdbuffer[bufindw][0]),cmd);
  231. SERIAL_ECHO_START;
  232. SERIAL_ECHOPGM("enqueing \"");
  233. SERIAL_ECHO(cmdbuffer[bufindw]);
  234. SERIAL_ECHOLNPGM("\"");
  235. bufindw= (bufindw + 1)%BUFSIZE;
  236. buflen += 1;
  237. }
  238. }
  239. void enquecommand_P(const char *cmd)
  240. {
  241. if(buflen < BUFSIZE)
  242. {
  243. //this is dangerous if a mixing of serial and this happsens
  244. strcpy_P(&(cmdbuffer[bufindw][0]),cmd);
  245. SERIAL_ECHO_START;
  246. SERIAL_ECHOPGM("enqueing \"");
  247. SERIAL_ECHO(cmdbuffer[bufindw]);
  248. SERIAL_ECHOLNPGM("\"");
  249. bufindw= (bufindw + 1)%BUFSIZE;
  250. buflen += 1;
  251. }
  252. }
  253. void setup_killpin()
  254. {
  255. #if( KILL_PIN>-1 )
  256. pinMode(KILL_PIN,INPUT);
  257. WRITE(KILL_PIN,HIGH);
  258. #endif
  259. }
  260. void setup_photpin()
  261. {
  262. #ifdef PHOTOGRAPH_PIN
  263. #if (PHOTOGRAPH_PIN > -1)
  264. SET_OUTPUT(PHOTOGRAPH_PIN);
  265. WRITE(PHOTOGRAPH_PIN, LOW);
  266. #endif
  267. #endif
  268. }
  269. void setup_powerhold()
  270. {
  271. #ifdef SUICIDE_PIN
  272. #if (SUICIDE_PIN> -1)
  273. SET_OUTPUT(SUICIDE_PIN);
  274. WRITE(SUICIDE_PIN, HIGH);
  275. #endif
  276. #endif
  277. #if (PS_ON_PIN > -1)
  278. SET_OUTPUT(PS_ON_PIN);
  279. WRITE(PS_ON_PIN, PS_ON_AWAKE);
  280. #endif
  281. }
  282. void suicide()
  283. {
  284. #ifdef SUICIDE_PIN
  285. #if (SUICIDE_PIN> -1)
  286. SET_OUTPUT(SUICIDE_PIN);
  287. WRITE(SUICIDE_PIN, LOW);
  288. #endif
  289. #endif
  290. }
  291. void setup()
  292. {
  293. setup_killpin();
  294. setup_powerhold();
  295. MYSERIAL.begin(BAUDRATE);
  296. SERIAL_PROTOCOLLNPGM("start");
  297. SERIAL_ECHO_START;
  298. // Check startup - does nothing if bootloader sets MCUSR to 0
  299. byte mcu = MCUSR;
  300. if(mcu & 1) SERIAL_ECHOLNPGM(MSG_POWERUP);
  301. if(mcu & 2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET);
  302. if(mcu & 4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET);
  303. if(mcu & 8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET);
  304. if(mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
  305. MCUSR=0;
  306. SERIAL_ECHOPGM(MSG_MARLIN);
  307. SERIAL_ECHOLNPGM(VERSION_STRING);
  308. #ifdef STRING_VERSION_CONFIG_H
  309. #ifdef STRING_CONFIG_H_AUTHOR
  310. SERIAL_ECHO_START;
  311. SERIAL_ECHOPGM(MSG_CONFIGURATION_VER);
  312. SERIAL_ECHOPGM(STRING_VERSION_CONFIG_H);
  313. SERIAL_ECHOPGM(MSG_AUTHOR);
  314. SERIAL_ECHOLNPGM(STRING_CONFIG_H_AUTHOR);
  315. SERIAL_ECHOPGM("Compiled: ");
  316. SERIAL_ECHOLNPGM(__DATE__);
  317. #endif
  318. #endif
  319. SERIAL_ECHO_START;
  320. SERIAL_ECHOPGM(MSG_FREE_MEMORY);
  321. SERIAL_ECHO(freeMemory());
  322. SERIAL_ECHOPGM(MSG_PLANNER_BUFFER_BYTES);
  323. SERIAL_ECHOLN((int)sizeof(block_t)*BLOCK_BUFFER_SIZE);
  324. for(int8_t i = 0; i < BUFSIZE; i++)
  325. {
  326. fromsd[i] = false;
  327. }
  328. // loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
  329. Config_RetrieveSettings();
  330. tp_init(); // Initialize temperature loop
  331. plan_init(); // Initialize planner;
  332. watchdog_init();
  333. st_init(); // Initialize stepper, this enables interrupts!
  334. setup_photpin();
  335. lcd_init();
  336. #ifdef CONTROLLERFAN_PIN
  337. SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan
  338. #endif
  339. #ifdef EXTRUDERFAN_PIN
  340. SET_OUTPUT(EXTRUDERFAN_PIN); //Set pin used for extruder cooling fan
  341. #endif
  342. }
  343. void loop()
  344. {
  345. if(buflen < (BUFSIZE-1))
  346. get_command();
  347. #ifdef SDSUPPORT
  348. card.checkautostart(false);
  349. #endif
  350. if(buflen)
  351. {
  352. #ifdef SDSUPPORT
  353. if(card.saving)
  354. {
  355. if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL)
  356. {
  357. card.write_command(cmdbuffer[bufindr]);
  358. if(card.logging)
  359. {
  360. process_commands();
  361. }
  362. else
  363. {
  364. SERIAL_PROTOCOLLNPGM(MSG_OK);
  365. }
  366. }
  367. else
  368. {
  369. card.closefile();
  370. SERIAL_PROTOCOLLNPGM(MSG_FILE_SAVED);
  371. }
  372. }
  373. else
  374. {
  375. process_commands();
  376. }
  377. #else
  378. process_commands();
  379. #endif //SDSUPPORT
  380. buflen = (buflen-1);
  381. bufindr = (bufindr + 1)%BUFSIZE;
  382. }
  383. //check heater every n milliseconds
  384. manage_heater();
  385. manage_inactivity();
  386. checkHitEndstops();
  387. lcd_update();
  388. }
  389. void get_command()
  390. {
  391. while( MYSERIAL.available() > 0 && buflen < BUFSIZE) {
  392. serial_char = MYSERIAL.read();
  393. if(serial_char == '\n' ||
  394. serial_char == '\r' ||
  395. (serial_char == ':' && comment_mode == false) ||
  396. serial_count >= (MAX_CMD_SIZE - 1) )
  397. {
  398. if(!serial_count) { //if empty line
  399. comment_mode = false; //for new command
  400. return;
  401. }
  402. cmdbuffer[bufindw][serial_count] = 0; //terminate string
  403. if(!comment_mode){
  404. comment_mode = false; //for new command
  405. fromsd[bufindw] = false;
  406. if(strchr(cmdbuffer[bufindw], 'N') != NULL)
  407. {
  408. strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
  409. gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
  410. if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
  411. SERIAL_ERROR_START;
  412. SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
  413. SERIAL_ERRORLN(gcode_LastN);
  414. //Serial.println(gcode_N);
  415. FlushSerialRequestResend();
  416. serial_count = 0;
  417. return;
  418. }
  419. if(strchr(cmdbuffer[bufindw], '*') != NULL)
  420. {
  421. byte checksum = 0;
  422. byte count = 0;
  423. while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
  424. strchr_pointer = strchr(cmdbuffer[bufindw], '*');
  425. if( (int)(strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) {
  426. SERIAL_ERROR_START;
  427. SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
  428. SERIAL_ERRORLN(gcode_LastN);
  429. FlushSerialRequestResend();
  430. serial_count = 0;
  431. return;
  432. }
  433. //if no errors, continue parsing
  434. }
  435. else
  436. {
  437. SERIAL_ERROR_START;
  438. SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
  439. SERIAL_ERRORLN(gcode_LastN);
  440. FlushSerialRequestResend();
  441. serial_count = 0;
  442. return;
  443. }
  444. gcode_LastN = gcode_N;
  445. //if no errors, continue parsing
  446. }
  447. else // if we don't receive 'N' but still see '*'
  448. {
  449. if((strchr(cmdbuffer[bufindw], '*') != NULL))
  450. {
  451. SERIAL_ERROR_START;
  452. SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
  453. SERIAL_ERRORLN(gcode_LastN);
  454. serial_count = 0;
  455. return;
  456. }
  457. }
  458. if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
  459. strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
  460. switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
  461. case 0:
  462. case 1:
  463. case 2:
  464. case 3:
  465. if(Stopped == false) { // If printer is stopped by an error the G[0-3] codes are ignored.
  466. #ifdef SDSUPPORT
  467. if(card.saving)
  468. break;
  469. #endif //SDSUPPORT
  470. SERIAL_PROTOCOLLNPGM(MSG_OK);
  471. }
  472. else {
  473. SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
  474. LCD_MESSAGEPGM(MSG_STOPPED);
  475. }
  476. break;
  477. default:
  478. break;
  479. }
  480. }
  481. bufindw = (bufindw + 1)%BUFSIZE;
  482. buflen += 1;
  483. }
  484. serial_count = 0; //clear buffer
  485. }
  486. else
  487. {
  488. if(serial_char == ';') comment_mode = true;
  489. if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
  490. }
  491. }
  492. #ifdef SDSUPPORT
  493. if(!card.sdprinting || serial_count!=0){
  494. return;
  495. }
  496. while( !card.eof() && buflen < BUFSIZE) {
  497. int16_t n=card.get();
  498. serial_char = (char)n;
  499. if(serial_char == '\n' ||
  500. serial_char == '\r' ||
  501. (serial_char == ':' && comment_mode == false) ||
  502. serial_count >= (MAX_CMD_SIZE - 1)||n==-1)
  503. {
  504. if(card.eof()){
  505. SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
  506. stoptime=millis();
  507. char time[30];
  508. unsigned long t=(stoptime-starttime)/1000;
  509. int hours, minutes;
  510. minutes=(t/60)%60;
  511. hours=t/60/60;
  512. sprintf_P(time, PSTR("%i hours %i minutes"),hours, minutes);
  513. SERIAL_ECHO_START;
  514. SERIAL_ECHOLN(time);
  515. lcd_setstatus(time);
  516. card.printingHasFinished();
  517. card.checkautostart(true);
  518. }
  519. if(!serial_count)
  520. {
  521. comment_mode = false; //for new command
  522. return; //if empty line
  523. }
  524. cmdbuffer[bufindw][serial_count] = 0; //terminate string
  525. // if(!comment_mode){
  526. fromsd[bufindw] = true;
  527. buflen += 1;
  528. bufindw = (bufindw + 1)%BUFSIZE;
  529. // }
  530. comment_mode = false; //for new command
  531. serial_count = 0; //clear buffer
  532. }
  533. else
  534. {
  535. if(serial_char == ';') comment_mode = true;
  536. if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
  537. }
  538. }
  539. #endif //SDSUPPORT
  540. }
  541. float code_value()
  542. {
  543. return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
  544. }
  545. long code_value_long()
  546. {
  547. return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
  548. }
  549. bool code_seen(char code)
  550. {
  551. strchr_pointer = strchr(cmdbuffer[bufindr], code);
  552. return (strchr_pointer != NULL); //Return True if a character was found
  553. }
  554. #define DEFINE_PGM_READ_ANY(type, reader) \
  555. static inline type pgm_read_any(const type *p) \
  556. { return pgm_read_##reader##_near(p); }
  557. DEFINE_PGM_READ_ANY(float, float);
  558. DEFINE_PGM_READ_ANY(signed char, byte);
  559. #define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
  560. static const PROGMEM type array##_P[3] = \
  561. { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \
  562. static inline type array(int axis) \
  563. { return pgm_read_any(&array##_P[axis]); }
  564. XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS);
  565. XYZ_CONSTS_FROM_CONFIG(float, base_max_pos, MAX_POS);
  566. XYZ_CONSTS_FROM_CONFIG(float, base_home_pos, HOME_POS);
  567. XYZ_CONSTS_FROM_CONFIG(float, max_length, MAX_LENGTH);
  568. XYZ_CONSTS_FROM_CONFIG(float, home_retract_mm, HOME_RETRACT_MM);
  569. XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
  570. static void axis_is_at_home(int axis) {
  571. current_position[axis] = base_home_pos(axis) + add_homeing[axis];
  572. min_pos[axis] = base_min_pos(axis) + add_homeing[axis];
  573. max_pos[axis] = base_max_pos(axis) + add_homeing[axis];
  574. }
  575. static void homeaxis(int axis) {
  576. #define HOMEAXIS_DO(LETTER) \
  577. ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
  578. if (axis==X_AXIS ? HOMEAXIS_DO(X) :
  579. axis==Y_AXIS ? HOMEAXIS_DO(Y) :
  580. axis==Z_AXIS ? HOMEAXIS_DO(Z) :
  581. 0) {
  582. current_position[axis] = 0;
  583. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  584. destination[axis] = 1.5 * max_length(axis) * home_dir(axis);
  585. feedrate = homing_feedrate[axis];
  586. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
  587. st_synchronize();
  588. current_position[axis] = 0;
  589. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  590. destination[axis] = -home_retract_mm(axis) * home_dir(axis);
  591. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
  592. st_synchronize();
  593. destination[axis] = 2*home_retract_mm(axis) * home_dir(axis);
  594. feedrate = homing_feedrate[axis]/2 ;
  595. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
  596. st_synchronize();
  597. axis_is_at_home(axis);
  598. destination[axis] = current_position[axis];
  599. feedrate = 0.0;
  600. endstops_hit_on_purpose();
  601. }
  602. }
  603. #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
  604. void process_commands()
  605. {
  606. unsigned long codenum; //throw away variable
  607. char *starpos = NULL;
  608. if(code_seen('G'))
  609. {
  610. switch((int)code_value())
  611. {
  612. case 0: // G0 -> G1
  613. case 1: // G1
  614. if(Stopped == false) {
  615. get_coordinates(); // For X Y Z E F
  616. prepare_move();
  617. //ClearToSend();
  618. return;
  619. }
  620. //break;
  621. case 2: // G2 - CW ARC
  622. if(Stopped == false) {
  623. get_arc_coordinates();
  624. prepare_arc_move(true);
  625. return;
  626. }
  627. case 3: // G3 - CCW ARC
  628. if(Stopped == false) {
  629. get_arc_coordinates();
  630. prepare_arc_move(false);
  631. return;
  632. }
  633. case 4: // G4 dwell
  634. LCD_MESSAGEPGM(MSG_DWELL);
  635. codenum = 0;
  636. if(code_seen('P')) codenum = code_value(); // milliseconds to wait
  637. if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
  638. st_synchronize();
  639. codenum += millis(); // keep track of when we started waiting
  640. previous_millis_cmd = millis();
  641. while(millis() < codenum ){
  642. manage_heater();
  643. manage_inactivity();
  644. lcd_update();
  645. }
  646. break;
  647. #ifdef FWRETRACT
  648. case 10: // G10 retract
  649. if(!retracted)
  650. {
  651. destination[X_AXIS]=current_position[X_AXIS];
  652. destination[Y_AXIS]=current_position[Y_AXIS];
  653. destination[Z_AXIS]=current_position[Z_AXIS];
  654. current_position[Z_AXIS]+=-retract_zlift;
  655. destination[E_AXIS]=current_position[E_AXIS]-retract_length;
  656. feedrate=retract_feedrate;
  657. retracted=true;
  658. prepare_move();
  659. }
  660. break;
  661. case 11: // G10 retract_recover
  662. if(!retracted)
  663. {
  664. destination[X_AXIS]=current_position[X_AXIS];
  665. destination[Y_AXIS]=current_position[Y_AXIS];
  666. destination[Z_AXIS]=current_position[Z_AXIS];
  667. current_position[Z_AXIS]+=retract_zlift;
  668. current_position[E_AXIS]+=-retract_recover_length;
  669. feedrate=retract_recover_feedrate;
  670. retracted=false;
  671. prepare_move();
  672. }
  673. break;
  674. #endif //FWRETRACT
  675. case 28: //G28 Home all Axis one at a time
  676. saved_feedrate = feedrate;
  677. saved_feedmultiply = feedmultiply;
  678. feedmultiply = 100;
  679. previous_millis_cmd = millis();
  680. enable_endstops(true);
  681. for(int8_t i=0; i < NUM_AXIS; i++) {
  682. destination[i] = current_position[i];
  683. }
  684. feedrate = 0.0;
  685. home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
  686. #if Z_HOME_DIR > 0 // If homing away from BED do Z first
  687. if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
  688. HOMEAXIS(Z);
  689. }
  690. #endif
  691. #ifdef QUICK_HOME
  692. if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS])) ) //first diagonal move
  693. {
  694. current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;
  695. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  696. destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;
  697. feedrate = homing_feedrate[X_AXIS];
  698. if(homing_feedrate[Y_AXIS]<feedrate)
  699. feedrate =homing_feedrate[Y_AXIS];
  700. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
  701. st_synchronize();
  702. axis_is_at_home(X_AXIS);
  703. axis_is_at_home(Y_AXIS);
  704. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  705. destination[X_AXIS] = current_position[X_AXIS];
  706. destination[Y_AXIS] = current_position[Y_AXIS];
  707. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
  708. feedrate = 0.0;
  709. st_synchronize();
  710. endstops_hit_on_purpose();
  711. }
  712. #endif
  713. if((home_all_axis) || (code_seen(axis_codes[X_AXIS])))
  714. {
  715. HOMEAXIS(X);
  716. }
  717. if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) {
  718. HOMEAXIS(Y);
  719. }
  720. #if Z_HOME_DIR < 0 // If homing towards BED do Z last
  721. if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
  722. HOMEAXIS(Z);
  723. }
  724. #endif
  725. if(code_seen(axis_codes[X_AXIS]))
  726. {
  727. if(code_value_long() != 0) {
  728. current_position[X_AXIS]=code_value()+add_homeing[0];
  729. }
  730. }
  731. if(code_seen(axis_codes[Y_AXIS])) {
  732. if(code_value_long() != 0) {
  733. current_position[Y_AXIS]=code_value()+add_homeing[1];
  734. }
  735. }
  736. if(code_seen(axis_codes[Z_AXIS])) {
  737. if(code_value_long() != 0) {
  738. current_position[Z_AXIS]=code_value()+add_homeing[2];
  739. }
  740. }
  741. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  742. #ifdef ENDSTOPS_ONLY_FOR_HOMING
  743. enable_endstops(false);
  744. #endif
  745. feedrate = saved_feedrate;
  746. feedmultiply = saved_feedmultiply;
  747. previous_millis_cmd = millis();
  748. endstops_hit_on_purpose();
  749. break;
  750. case 90: // G90
  751. relative_mode = false;
  752. break;
  753. case 91: // G91
  754. relative_mode = true;
  755. break;
  756. case 92: // G92
  757. if(!code_seen(axis_codes[E_AXIS]))
  758. st_synchronize();
  759. for(int8_t i=0; i < NUM_AXIS; i++) {
  760. if(code_seen(axis_codes[i])) {
  761. if(i == E_AXIS) {
  762. current_position[i] = code_value();
  763. plan_set_e_position(current_position[E_AXIS]);
  764. }
  765. else {
  766. current_position[i] = code_value()+add_homeing[i];
  767. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  768. }
  769. }
  770. }
  771. break;
  772. }
  773. }
  774. else if(code_seen('M'))
  775. {
  776. switch( (int)code_value() )
  777. {
  778. #ifdef ULTIPANEL
  779. case 0: // M0 - Unconditional stop - Wait for user button press on LCD
  780. case 1: // M1 - Conditional stop - Wait for user button press on LCD
  781. {
  782. LCD_MESSAGEPGM(MSG_USERWAIT);
  783. codenum = 0;
  784. if(code_seen('P')) codenum = code_value(); // milliseconds to wait
  785. if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
  786. st_synchronize();
  787. previous_millis_cmd = millis();
  788. if (codenum > 0){
  789. codenum += millis(); // keep track of when we started waiting
  790. while(millis() < codenum && !LCD_CLICKED){
  791. manage_heater();
  792. manage_inactivity();
  793. lcd_update();
  794. }
  795. }else{
  796. while(!LCD_CLICKED){
  797. manage_heater();
  798. manage_inactivity();
  799. lcd_update();
  800. }
  801. }
  802. LCD_MESSAGEPGM(MSG_RESUMING);
  803. }
  804. break;
  805. #endif
  806. case 17:
  807. LCD_MESSAGEPGM(MSG_NO_MOVE);
  808. enable_x();
  809. enable_y();
  810. enable_z();
  811. enable_e0();
  812. enable_e1();
  813. enable_e2();
  814. break;
  815. #ifdef SDSUPPORT
  816. case 20: // M20 - list SD card
  817. SERIAL_PROTOCOLLNPGM(MSG_BEGIN_FILE_LIST);
  818. card.ls();
  819. SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST);
  820. break;
  821. case 21: // M21 - init SD card
  822. card.initsd();
  823. break;
  824. case 22: //M22 - release SD card
  825. card.release();
  826. break;
  827. case 23: //M23 - Select file
  828. starpos = (strchr(strchr_pointer + 4,'*'));
  829. if(starpos!=NULL)
  830. *(starpos-1)='\0';
  831. card.openFile(strchr_pointer + 4,true);
  832. break;
  833. case 24: //M24 - Start SD print
  834. card.startFileprint();
  835. starttime=millis();
  836. break;
  837. case 25: //M25 - Pause SD print
  838. card.pauseSDPrint();
  839. break;
  840. case 26: //M26 - Set SD index
  841. if(card.cardOK && code_seen('S')) {
  842. card.setIndex(code_value_long());
  843. }
  844. break;
  845. case 27: //M27 - Get SD status
  846. card.getStatus();
  847. break;
  848. case 28: //M28 - Start SD write
  849. starpos = (strchr(strchr_pointer + 4,'*'));
  850. if(starpos != NULL){
  851. char* npos = strchr(cmdbuffer[bufindr], 'N');
  852. strchr_pointer = strchr(npos,' ') + 1;
  853. *(starpos-1) = '\0';
  854. }
  855. card.openFile(strchr_pointer+4,false);
  856. break;
  857. case 29: //M29 - Stop SD write
  858. //processed in write to file routine above
  859. //card,saving = false;
  860. break;
  861. case 30: //M30 <filename> Delete File
  862. if (card.cardOK){
  863. card.closefile();
  864. starpos = (strchr(strchr_pointer + 4,'*'));
  865. if(starpos != NULL){
  866. char* npos = strchr(cmdbuffer[bufindr], 'N');
  867. strchr_pointer = strchr(npos,' ') + 1;
  868. *(starpos-1) = '\0';
  869. }
  870. card.removeFile(strchr_pointer + 4);
  871. }
  872. break;
  873. case 928: //M928 - Start SD write
  874. starpos = (strchr(strchr_pointer + 5,'*'));
  875. if(starpos != NULL){
  876. char* npos = strchr(cmdbuffer[bufindr], 'N');
  877. strchr_pointer = strchr(npos,' ') + 1;
  878. *(starpos-1) = '\0';
  879. }
  880. card.openLogFile(strchr_pointer+5);
  881. break;
  882. #endif //SDSUPPORT
  883. case 31: //M31 take time since the start of the SD print or an M109 command
  884. {
  885. stoptime=millis();
  886. char time[30];
  887. unsigned long t=(stoptime-starttime)/1000;
  888. int sec,min;
  889. min=t/60;
  890. sec=t%60;
  891. sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
  892. SERIAL_ECHO_START;
  893. SERIAL_ECHOLN(time);
  894. lcd_setstatus(time);
  895. autotempShutdown();
  896. }
  897. break;
  898. case 42: //M42 -Change pin status via gcode
  899. if (code_seen('S'))
  900. {
  901. int pin_status = code_value();
  902. int pin_number = LED_PIN;
  903. if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
  904. pin_number = code_value();
  905. for(int8_t i = 0; i < (int8_t)sizeof(sensitive_pins); i++)
  906. {
  907. if (sensitive_pins[i] == pin_number)
  908. {
  909. pin_number = -1;
  910. break;
  911. }
  912. }
  913. if (pin_number > -1)
  914. {
  915. pinMode(pin_number, OUTPUT);
  916. digitalWrite(pin_number, pin_status);
  917. analogWrite(pin_number, pin_status);
  918. }
  919. }
  920. break;
  921. case 104: // M104
  922. if(setTargetedHotend(104)){
  923. break;
  924. }
  925. if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
  926. setWatch();
  927. break;
  928. case 140: // M140 set bed temp
  929. if (code_seen('S')) setTargetBed(code_value());
  930. break;
  931. case 105 : // M105
  932. if(setTargetedHotend(105)){
  933. break;
  934. }
  935. #if (TEMP_0_PIN > -1)
  936. SERIAL_PROTOCOLPGM("ok T:");
  937. SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1);
  938. SERIAL_PROTOCOLPGM(" /");
  939. SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1);
  940. #if TEMP_BED_PIN > -1
  941. SERIAL_PROTOCOLPGM(" B:");
  942. SERIAL_PROTOCOL_F(degBed(),1);
  943. SERIAL_PROTOCOLPGM(" /");
  944. SERIAL_PROTOCOL_F(degTargetBed(),1);
  945. #endif //TEMP_BED_PIN
  946. #else
  947. SERIAL_ERROR_START;
  948. SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
  949. #endif
  950. SERIAL_PROTOCOLPGM(" @:");
  951. SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));
  952. SERIAL_PROTOCOLPGM(" B@:");
  953. SERIAL_PROTOCOL(getHeaterPower(-1));
  954. SERIAL_PROTOCOLLN("");
  955. return;
  956. break;
  957. case 109:
  958. {// M109 - Wait for extruder heater to reach target.
  959. if(setTargetedHotend(109)){
  960. break;
  961. }
  962. LCD_MESSAGEPGM(MSG_HEATING);
  963. #ifdef AUTOTEMP
  964. autotemp_enabled=false;
  965. #endif
  966. if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
  967. #ifdef AUTOTEMP
  968. if (code_seen('S')) autotemp_min=code_value();
  969. if (code_seen('B')) autotemp_max=code_value();
  970. if (code_seen('F'))
  971. {
  972. autotemp_factor=code_value();
  973. autotemp_enabled=true;
  974. }
  975. #endif
  976. setWatch();
  977. codenum = millis();
  978. /* See if we are heating up or cooling down */
  979. bool target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling
  980. #ifdef TEMP_RESIDENCY_TIME
  981. long residencyStart;
  982. residencyStart = -1;
  983. /* continue to loop until we have reached the target temp
  984. _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
  985. while((residencyStart == -1) ||
  986. (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL))) ) {
  987. #else
  988. while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
  989. #endif //TEMP_RESIDENCY_TIME
  990. if( (millis() - codenum) > 1000UL )
  991. { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
  992. SERIAL_PROTOCOLPGM("T:");
  993. SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1);
  994. SERIAL_PROTOCOLPGM(" E:");
  995. SERIAL_PROTOCOL((int)tmp_extruder);
  996. #ifdef TEMP_RESIDENCY_TIME
  997. SERIAL_PROTOCOLPGM(" W:");
  998. if(residencyStart > -1)
  999. {
  1000. codenum = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residencyStart)) / 1000UL;
  1001. SERIAL_PROTOCOLLN( codenum );
  1002. }
  1003. else
  1004. {
  1005. SERIAL_PROTOCOLLN( "?" );
  1006. }
  1007. #else
  1008. SERIAL_PROTOCOLLN("");
  1009. #endif
  1010. codenum = millis();
  1011. }
  1012. manage_heater();
  1013. manage_inactivity();
  1014. lcd_update();
  1015. #ifdef TEMP_RESIDENCY_TIME
  1016. /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
  1017. or when current temp falls outside the hysteresis after target temp was reached */
  1018. if ((residencyStart == -1 && target_direction && (degHotend(tmp_extruder) >= (degTargetHotend(tmp_extruder)-TEMP_WINDOW))) ||
  1019. (residencyStart == -1 && !target_direction && (degHotend(tmp_extruder) <= (degTargetHotend(tmp_extruder)+TEMP_WINDOW))) ||
  1020. (residencyStart > -1 && labs(degHotend(tmp_extruder) - degTargetHotend(tmp_extruder)) > TEMP_HYSTERESIS) )
  1021. {
  1022. residencyStart = millis();
  1023. }
  1024. #endif //TEMP_RESIDENCY_TIME
  1025. }
  1026. LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
  1027. starttime=millis();
  1028. previous_millis_cmd = millis();
  1029. }
  1030. break;
  1031. case 190: // M190 - Wait for bed heater to reach target.
  1032. #if TEMP_BED_PIN > -1
  1033. LCD_MESSAGEPGM(MSG_BED_HEATING);
  1034. if (code_seen('S')) setTargetBed(code_value());
  1035. codenum = millis();
  1036. while(isHeatingBed())
  1037. {
  1038. if(( millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
  1039. {
  1040. float tt=degHotend(active_extruder);
  1041. SERIAL_PROTOCOLPGM("T:");
  1042. SERIAL_PROTOCOL(tt);
  1043. SERIAL_PROTOCOLPGM(" E:");
  1044. SERIAL_PROTOCOL((int)active_extruder);
  1045. SERIAL_PROTOCOLPGM(" B:");
  1046. SERIAL_PROTOCOL_F(degBed(),1);
  1047. SERIAL_PROTOCOLLN("");
  1048. codenum = millis();
  1049. }
  1050. manage_heater();
  1051. manage_inactivity();
  1052. lcd_update();
  1053. }
  1054. LCD_MESSAGEPGM(MSG_BED_DONE);
  1055. previous_millis_cmd = millis();
  1056. #endif
  1057. break;
  1058. #if FAN_PIN > -1
  1059. case 106: //M106 Fan On
  1060. if (code_seen('S')){
  1061. fanSpeed=constrain(code_value(),0,255);
  1062. }
  1063. else {
  1064. fanSpeed=255;
  1065. }
  1066. break;
  1067. case 107: //M107 Fan Off
  1068. fanSpeed = 0;
  1069. break;
  1070. #endif //FAN_PIN
  1071. #ifdef BARICUDA
  1072. // PWM for HEATER_1_PIN
  1073. #if HEATER_1_PIN > -1
  1074. case 126: //M126 valve open
  1075. if (code_seen('S')){
  1076. ValvePressure=constrain(code_value(),0,255);
  1077. }
  1078. else {
  1079. ValvePressure=255;
  1080. }
  1081. break;
  1082. case 127: //M127 valve closed
  1083. ValvePressure = 0;
  1084. break;
  1085. #endif //HEATER_1_PIN
  1086. // PWM for HEATER_2_PIN
  1087. #if HEATER_2_PIN > -1
  1088. case 128: //M128 valve open
  1089. if (code_seen('S')){
  1090. EtoPPressure=constrain(code_value(),0,255);
  1091. }
  1092. else {
  1093. EtoPPressure=255;
  1094. }
  1095. break;
  1096. case 129: //M129 valve closed
  1097. EtoPPressure = 0;
  1098. break;
  1099. #endif //HEATER_2_PIN
  1100. #endif
  1101. #if (PS_ON_PIN > -1)
  1102. case 80: // M80 - ATX Power On
  1103. SET_OUTPUT(PS_ON_PIN); //GND
  1104. WRITE(PS_ON_PIN, PS_ON_AWAKE);
  1105. break;
  1106. #endif
  1107. case 81: // M81 - ATX Power Off
  1108. #if defined SUICIDE_PIN && SUICIDE_PIN > -1
  1109. st_synchronize();
  1110. suicide();
  1111. #elif (PS_ON_PIN > -1)
  1112. SET_OUTPUT(PS_ON_PIN);
  1113. WRITE(PS_ON_PIN, PS_ON_ASLEEP);
  1114. #endif
  1115. break;
  1116. case 82:
  1117. axis_relative_modes[3] = false;
  1118. break;
  1119. case 83:
  1120. axis_relative_modes[3] = true;
  1121. break;
  1122. case 18: //compatibility
  1123. case 84: // M84
  1124. if(code_seen('S')){
  1125. stepper_inactive_time = code_value() * 1000;
  1126. }
  1127. else
  1128. {
  1129. bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3])));
  1130. if(all_axis)
  1131. {
  1132. st_synchronize();
  1133. disable_e0();
  1134. disable_e1();
  1135. disable_e2();
  1136. finishAndDisableSteppers();
  1137. }
  1138. else
  1139. {
  1140. st_synchronize();
  1141. if(code_seen('X')) disable_x();
  1142. if(code_seen('Y')) disable_y();
  1143. if(code_seen('Z')) disable_z();
  1144. #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
  1145. if(code_seen('E')) {
  1146. disable_e0();
  1147. disable_e1();
  1148. disable_e2();
  1149. }
  1150. #endif
  1151. }
  1152. }
  1153. break;
  1154. case 85: // M85
  1155. code_seen('S');
  1156. max_inactive_time = code_value() * 1000;
  1157. break;
  1158. case 92: // M92
  1159. for(int8_t i=0; i < NUM_AXIS; i++)
  1160. {
  1161. if(code_seen(axis_codes[i]))
  1162. {
  1163. if(i == 3) { // E
  1164. float value = code_value();
  1165. if(value < 20.0) {
  1166. float factor = axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab.
  1167. max_e_jerk *= factor;
  1168. max_feedrate[i] *= factor;
  1169. axis_steps_per_sqr_second[i] *= factor;
  1170. }
  1171. axis_steps_per_unit[i] = value;
  1172. }
  1173. else {
  1174. axis_steps_per_unit[i] = code_value();
  1175. }
  1176. }
  1177. }
  1178. break;
  1179. case 115: // M115
  1180. SERIAL_PROTOCOLPGM(MSG_M115_REPORT);
  1181. break;
  1182. case 117: // M117 display message
  1183. starpos = (strchr(strchr_pointer + 5,'*'));
  1184. if(starpos!=NULL)
  1185. *(starpos-1)='\0';
  1186. lcd_setstatus(strchr_pointer + 5);
  1187. break;
  1188. case 114: // M114
  1189. SERIAL_PROTOCOLPGM("X:");
  1190. SERIAL_PROTOCOL(current_position[X_AXIS]);
  1191. SERIAL_PROTOCOLPGM("Y:");
  1192. SERIAL_PROTOCOL(current_position[Y_AXIS]);
  1193. SERIAL_PROTOCOLPGM("Z:");
  1194. SERIAL_PROTOCOL(current_position[Z_AXIS]);
  1195. SERIAL_PROTOCOLPGM("E:");
  1196. SERIAL_PROTOCOL(current_position[E_AXIS]);
  1197. SERIAL_PROTOCOLPGM(MSG_COUNT_X);
  1198. SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]);
  1199. SERIAL_PROTOCOLPGM("Y:");
  1200. SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]);
  1201. SERIAL_PROTOCOLPGM("Z:");
  1202. SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);
  1203. SERIAL_PROTOCOLLN("");
  1204. break;
  1205. case 120: // M120
  1206. enable_endstops(false) ;
  1207. break;
  1208. case 121: // M121
  1209. enable_endstops(true) ;
  1210. break;
  1211. case 119: // M119
  1212. SERIAL_PROTOCOLLN(MSG_M119_REPORT);
  1213. #if (X_MIN_PIN > -1)
  1214. SERIAL_PROTOCOLPGM(MSG_X_MIN);
  1215. SERIAL_PROTOCOLLN(((READ(X_MIN_PIN)^X_ENDSTOPS_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
  1216. #endif
  1217. #if (X_MAX_PIN > -1)
  1218. SERIAL_PROTOCOLPGM(MSG_X_MAX);
  1219. SERIAL_PROTOCOLLN(((READ(X_MAX_PIN)^X_ENDSTOPS_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
  1220. #endif
  1221. #if (Y_MIN_PIN > -1)
  1222. SERIAL_PROTOCOLPGM(MSG_Y_MIN);
  1223. SERIAL_PROTOCOLLN(((READ(Y_MIN_PIN)^Y_ENDSTOPS_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
  1224. #endif
  1225. #if (Y_MAX_PIN > -1)
  1226. SERIAL_PROTOCOLPGM(MSG_Y_MAX);
  1227. SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_ENDSTOPS_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
  1228. #endif
  1229. #if (Z_MIN_PIN > -1)
  1230. SERIAL_PROTOCOLPGM(MSG_Z_MIN);
  1231. SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_ENDSTOPS_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
  1232. #endif
  1233. #if (Z_MAX_PIN > -1)
  1234. SERIAL_PROTOCOLPGM(MSG_Z_MAX);
  1235. SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_ENDSTOPS_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
  1236. #endif
  1237. break;
  1238. //TODO: update for all axis, use for loop
  1239. case 201: // M201
  1240. for(int8_t i=0; i < NUM_AXIS; i++)
  1241. {
  1242. if(code_seen(axis_codes[i]))
  1243. {
  1244. max_acceleration_units_per_sq_second[i] = code_value();
  1245. }
  1246. }
  1247. // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
  1248. reset_acceleration_rates();
  1249. break;
  1250. #if 0 // Not used for Sprinter/grbl gen6
  1251. case 202: // M202
  1252. for(int8_t i=0; i < NUM_AXIS; i++) {
  1253. if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
  1254. }
  1255. break;
  1256. #endif
  1257. case 203: // M203 max feedrate mm/sec
  1258. for(int8_t i=0; i < NUM_AXIS; i++) {
  1259. if(code_seen(axis_codes[i])) max_feedrate[i] = code_value();
  1260. }
  1261. break;
  1262. case 204: // M204 acclereration S normal moves T filmanent only moves
  1263. {
  1264. if(code_seen('S')) acceleration = code_value() ;
  1265. if(code_seen('T')) retract_acceleration = code_value() ;
  1266. }
  1267. break;
  1268. case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
  1269. {
  1270. if(code_seen('S')) minimumfeedrate = code_value();
  1271. if(code_seen('T')) mintravelfeedrate = code_value();
  1272. if(code_seen('B')) minsegmenttime = code_value() ;
  1273. if(code_seen('X')) max_xy_jerk = code_value() ;
  1274. if(code_seen('Z')) max_z_jerk = code_value() ;
  1275. if(code_seen('E')) max_e_jerk = code_value() ;
  1276. }
  1277. break;
  1278. case 206: // M206 additional homeing offset
  1279. for(int8_t i=0; i < 3; i++)
  1280. {
  1281. if(code_seen(axis_codes[i])) add_homeing[i] = code_value();
  1282. }
  1283. break;
  1284. #ifdef FWRETRACT
  1285. case 207: //M207 - set retract length S[positive mm] F[feedrate mm/sec] Z[additional zlift/hop]
  1286. {
  1287. if(code_seen('S'))
  1288. {
  1289. retract_length = code_value() ;
  1290. }
  1291. if(code_seen('F'))
  1292. {
  1293. retract_feedrate = code_value() ;
  1294. }
  1295. if(code_seen('Z'))
  1296. {
  1297. retract_zlift = code_value() ;
  1298. }
  1299. }break;
  1300. case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/sec]
  1301. {
  1302. if(code_seen('S'))
  1303. {
  1304. retract_recover_length = code_value() ;
  1305. }
  1306. if(code_seen('F'))
  1307. {
  1308. retract_recover_feedrate = code_value() ;
  1309. }
  1310. }break;
  1311. case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction.
  1312. {
  1313. if(code_seen('S'))
  1314. {
  1315. int t= code_value() ;
  1316. switch(t)
  1317. {
  1318. case 0: autoretract_enabled=false;retracted=false;break;
  1319. case 1: autoretract_enabled=true;retracted=false;break;
  1320. default:
  1321. SERIAL_ECHO_START;
  1322. SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND);
  1323. SERIAL_ECHO(cmdbuffer[bufindr]);
  1324. SERIAL_ECHOLNPGM("\"");
  1325. }
  1326. }
  1327. }break;
  1328. #endif // FWRETRACT
  1329. #if EXTRUDERS > 1
  1330. case 218: // M218 - set hotend offset (in mm), T<extruder_number> X<offset_on_X> Y<offset_on_Y>
  1331. {
  1332. if(setTargetedHotend(218)){
  1333. break;
  1334. }
  1335. if(code_seen('X'))
  1336. {
  1337. extruder_offset[X_AXIS][tmp_extruder] = code_value();
  1338. }
  1339. if(code_seen('Y'))
  1340. {
  1341. extruder_offset[Y_AXIS][tmp_extruder] = code_value();
  1342. }
  1343. SERIAL_ECHO_START;
  1344. SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
  1345. for(tmp_extruder = 0; tmp_extruder < EXTRUDERS; tmp_extruder++)
  1346. {
  1347. SERIAL_ECHO(" ");
  1348. SERIAL_ECHO(extruder_offset[X_AXIS][tmp_extruder]);
  1349. SERIAL_ECHO(",");
  1350. SERIAL_ECHO(extruder_offset[Y_AXIS][tmp_extruder]);
  1351. }
  1352. SERIAL_ECHOLN("");
  1353. }break;
  1354. #endif
  1355. case 220: // M220 S<factor in percent>- set speed factor override percentage
  1356. {
  1357. if(code_seen('S'))
  1358. {
  1359. feedmultiply = code_value() ;
  1360. }
  1361. }
  1362. break;
  1363. case 221: // M221 S<factor in percent>- set extrude factor override percentage
  1364. {
  1365. if(code_seen('S'))
  1366. {
  1367. extrudemultiply = code_value() ;
  1368. }
  1369. }
  1370. break;
  1371. #if defined(LARGE_FLASH) && LARGE_FLASH == true && defined(BEEPER) && BEEPER > -1
  1372. case 300: // M300
  1373. {
  1374. int beepS = 1;
  1375. int beepP = 1000;
  1376. if(code_seen('S')) beepS = code_value();
  1377. if(code_seen('P')) beepP = code_value();
  1378. tone(BEEPER, beepS);
  1379. delay(beepP);
  1380. noTone(BEEPER);
  1381. }
  1382. break;
  1383. #endif // M300
  1384. #ifdef PIDTEMP
  1385. case 301: // M301
  1386. {
  1387. if(code_seen('P')) Kp = code_value();
  1388. if(code_seen('I')) Ki = scalePID_i(code_value());
  1389. if(code_seen('D')) Kd = scalePID_d(code_value());
  1390. #ifdef PID_ADD_EXTRUSION_RATE
  1391. if(code_seen('C')) Kc = code_value();
  1392. #endif
  1393. updatePID();
  1394. SERIAL_PROTOCOL(MSG_OK);
  1395. SERIAL_PROTOCOL(" p:");
  1396. SERIAL_PROTOCOL(Kp);
  1397. SERIAL_PROTOCOL(" i:");
  1398. SERIAL_PROTOCOL(unscalePID_i(Ki));
  1399. SERIAL_PROTOCOL(" d:");
  1400. SERIAL_PROTOCOL(unscalePID_d(Kd));
  1401. #ifdef PID_ADD_EXTRUSION_RATE
  1402. SERIAL_PROTOCOL(" c:");
  1403. //Kc does not have scaling applied above, or in resetting defaults
  1404. SERIAL_PROTOCOL(Kc);
  1405. #endif
  1406. SERIAL_PROTOCOLLN("");
  1407. }
  1408. break;
  1409. #endif //PIDTEMP
  1410. #ifdef PIDTEMPBED
  1411. case 304: // M304
  1412. {
  1413. if(code_seen('P')) bedKp = code_value();
  1414. if(code_seen('I')) bedKi = scalePID_i(code_value());
  1415. if(code_seen('D')) bedKd = scalePID_d(code_value());
  1416. updatePID();
  1417. SERIAL_PROTOCOL(MSG_OK);
  1418. SERIAL_PROTOCOL(" p:");
  1419. SERIAL_PROTOCOL(bedKp);
  1420. SERIAL_PROTOCOL(" i:");
  1421. SERIAL_PROTOCOL(unscalePID_i(bedKi));
  1422. SERIAL_PROTOCOL(" d:");
  1423. SERIAL_PROTOCOL(unscalePID_d(bedKd));
  1424. SERIAL_PROTOCOLLN("");
  1425. }
  1426. break;
  1427. #endif //PIDTEMP
  1428. case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/
  1429. {
  1430. #ifdef PHOTOGRAPH_PIN
  1431. #if (PHOTOGRAPH_PIN > -1)
  1432. const uint8_t NUM_PULSES=16;
  1433. const float PULSE_LENGTH=0.01524;
  1434. for(int i=0; i < NUM_PULSES; i++) {
  1435. WRITE(PHOTOGRAPH_PIN, HIGH);
  1436. _delay_ms(PULSE_LENGTH);
  1437. WRITE(PHOTOGRAPH_PIN, LOW);
  1438. _delay_ms(PULSE_LENGTH);
  1439. }
  1440. delay(7.33);
  1441. for(int i=0; i < NUM_PULSES; i++) {
  1442. WRITE(PHOTOGRAPH_PIN, HIGH);
  1443. _delay_ms(PULSE_LENGTH);
  1444. WRITE(PHOTOGRAPH_PIN, LOW);
  1445. _delay_ms(PULSE_LENGTH);
  1446. }
  1447. #endif
  1448. #endif
  1449. }
  1450. break;
  1451. case 302: // allow cold extrudes
  1452. {
  1453. allow_cold_extrudes(true);
  1454. }
  1455. break;
  1456. case 303: // M303 PID autotune
  1457. {
  1458. float temp = 150.0;
  1459. int e=0;
  1460. int c=5;
  1461. if (code_seen('E')) e=code_value();
  1462. if (e<0)
  1463. temp=70;
  1464. if (code_seen('S')) temp=code_value();
  1465. if (code_seen('C')) c=code_value();
  1466. PID_autotune(temp, e, c);
  1467. }
  1468. break;
  1469. case 400: // M400 finish all moves
  1470. {
  1471. st_synchronize();
  1472. }
  1473. break;
  1474. case 500: // M500 Store settings in EEPROM
  1475. {
  1476. Config_StoreSettings();
  1477. }
  1478. break;
  1479. case 501: // M501 Read settings from EEPROM
  1480. {
  1481. Config_RetrieveSettings();
  1482. }
  1483. break;
  1484. case 502: // M502 Revert to default settings
  1485. {
  1486. Config_ResetDefault();
  1487. }
  1488. break;
  1489. case 503: // M503 print settings currently in memory
  1490. {
  1491. Config_PrintSettings();
  1492. }
  1493. break;
  1494. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  1495. case 540:
  1496. {
  1497. if(code_seen('S')) abort_on_endstop_hit = code_value() > 0;
  1498. }
  1499. break;
  1500. #endif
  1501. #ifdef FILAMENTCHANGEENABLE
  1502. case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
  1503. {
  1504. float target[4];
  1505. float lastpos[4];
  1506. target[X_AXIS]=current_position[X_AXIS];
  1507. target[Y_AXIS]=current_position[Y_AXIS];
  1508. target[Z_AXIS]=current_position[Z_AXIS];
  1509. target[E_AXIS]=current_position[E_AXIS];
  1510. lastpos[X_AXIS]=current_position[X_AXIS];
  1511. lastpos[Y_AXIS]=current_position[Y_AXIS];
  1512. lastpos[Z_AXIS]=current_position[Z_AXIS];
  1513. lastpos[E_AXIS]=current_position[E_AXIS];
  1514. //retract by E
  1515. if(code_seen('E'))
  1516. {
  1517. target[E_AXIS]+= code_value();
  1518. }
  1519. else
  1520. {
  1521. #ifdef FILAMENTCHANGE_FIRSTRETRACT
  1522. target[E_AXIS]+= FILAMENTCHANGE_FIRSTRETRACT ;
  1523. #endif
  1524. }
  1525. plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder);
  1526. //lift Z
  1527. if(code_seen('Z'))
  1528. {
  1529. target[Z_AXIS]+= code_value();
  1530. }
  1531. else
  1532. {
  1533. #ifdef FILAMENTCHANGE_ZADD
  1534. target[Z_AXIS]+= FILAMENTCHANGE_ZADD ;
  1535. #endif
  1536. }
  1537. plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder);
  1538. //move xy
  1539. if(code_seen('X'))
  1540. {
  1541. target[X_AXIS]+= code_value();
  1542. }
  1543. else
  1544. {
  1545. #ifdef FILAMENTCHANGE_XPOS
  1546. target[X_AXIS]= FILAMENTCHANGE_XPOS ;
  1547. #endif
  1548. }
  1549. if(code_seen('Y'))
  1550. {
  1551. target[Y_AXIS]= code_value();
  1552. }
  1553. else
  1554. {
  1555. #ifdef FILAMENTCHANGE_YPOS
  1556. target[Y_AXIS]= FILAMENTCHANGE_YPOS ;
  1557. #endif
  1558. }
  1559. plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder);
  1560. if(code_seen('L'))
  1561. {
  1562. target[E_AXIS]+= code_value();
  1563. }
  1564. else
  1565. {
  1566. #ifdef FILAMENTCHANGE_FINALRETRACT
  1567. target[E_AXIS]+= FILAMENTCHANGE_FINALRETRACT ;
  1568. #endif
  1569. }
  1570. plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder);
  1571. //finish moves
  1572. st_synchronize();
  1573. //disable extruder steppers so filament can be removed
  1574. disable_e0();
  1575. disable_e1();
  1576. disable_e2();
  1577. delay(100);
  1578. LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
  1579. uint8_t cnt=0;
  1580. while(!LCD_CLICKED){
  1581. cnt++;
  1582. manage_heater();
  1583. manage_inactivity();
  1584. lcd_update();
  1585. #if BEEPER > -1
  1586. if(cnt==0)
  1587. {
  1588. SET_OUTPUT(BEEPER);
  1589. WRITE(BEEPER,HIGH);
  1590. delay(3);
  1591. WRITE(BEEPER,LOW);
  1592. delay(3);
  1593. }
  1594. #endif
  1595. }
  1596. //return to normal
  1597. if(code_seen('L'))
  1598. {
  1599. target[E_AXIS]+= -code_value();
  1600. }
  1601. else
  1602. {
  1603. #ifdef FILAMENTCHANGE_FINALRETRACT
  1604. target[E_AXIS]+=(-1)*FILAMENTCHANGE_FINALRETRACT ;
  1605. #endif
  1606. }
  1607. current_position[E_AXIS]=target[E_AXIS]; //the long retract of L is compensated by manual filament feeding
  1608. plan_set_e_position(current_position[E_AXIS]);
  1609. plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); //should do nothing
  1610. plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); //move xy back
  1611. plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); //move z back
  1612. plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], feedrate/60, active_extruder); //final untretract
  1613. }
  1614. break;
  1615. #endif //FILAMENTCHANGEENABLE
  1616. case 907: // M907 Set digital trimpot motor current using axis codes.
  1617. {
  1618. #if DIGIPOTSS_PIN > -1
  1619. for(int i=0;i<NUM_AXIS;i++) if(code_seen(axis_codes[i])) digipot_current(i,code_value());
  1620. if(code_seen('B')) digipot_current(4,code_value());
  1621. if(code_seen('S')) for(int i=0;i<=4;i++) digipot_current(i,code_value());
  1622. #endif
  1623. }
  1624. break;
  1625. case 908: // M908 Control digital trimpot directly.
  1626. {
  1627. #if DIGIPOTSS_PIN > -1
  1628. uint8_t channel,current;
  1629. if(code_seen('P')) channel=code_value();
  1630. if(code_seen('S')) current=code_value();
  1631. digitalPotWrite(channel, current);
  1632. #endif
  1633. }
  1634. break;
  1635. case 350: // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
  1636. {
  1637. #if X_MS1_PIN > -1
  1638. if(code_seen('S')) for(int i=0;i<=4;i++) microstep_mode(i,code_value());
  1639. for(int i=0;i<NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_mode(i,(uint8_t)code_value());
  1640. if(code_seen('B')) microstep_mode(4,code_value());
  1641. microstep_readings();
  1642. #endif
  1643. }
  1644. break;
  1645. case 351: // M351 Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low.
  1646. {
  1647. #if X_MS1_PIN > -1
  1648. if(code_seen('S')) switch((int)code_value())
  1649. {
  1650. case 1:
  1651. for(int i=0;i<NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_ms(i,code_value(),-1);
  1652. if(code_seen('B')) microstep_ms(4,code_value(),-1);
  1653. break;
  1654. case 2:
  1655. for(int i=0;i<NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_ms(i,-1,code_value());
  1656. if(code_seen('B')) microstep_ms(4,-1,code_value());
  1657. break;
  1658. }
  1659. microstep_readings();
  1660. #endif
  1661. }
  1662. break;
  1663. case 999: // M999: Restart after being stopped
  1664. Stopped = false;
  1665. lcd_reset_alert_level();
  1666. gcode_LastN = Stopped_gcode_LastN;
  1667. FlushSerialRequestResend();
  1668. break;
  1669. }
  1670. }
  1671. else if(code_seen('T'))
  1672. {
  1673. tmp_extruder = code_value();
  1674. if(tmp_extruder >= EXTRUDERS) {
  1675. SERIAL_ECHO_START;
  1676. SERIAL_ECHO("T");
  1677. SERIAL_ECHO(tmp_extruder);
  1678. SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
  1679. }
  1680. else {
  1681. boolean make_move = false;
  1682. if(code_seen('F')) {
  1683. make_move = true;
  1684. next_feedrate = code_value();
  1685. if(next_feedrate > 0.0) {
  1686. feedrate = next_feedrate;
  1687. }
  1688. }
  1689. #if EXTRUDERS > 1
  1690. if(tmp_extruder != active_extruder) {
  1691. // Save current position to return to after applying extruder offset
  1692. memcpy(destination, current_position, sizeof(destination));
  1693. // Offset extruder (only by XY)
  1694. int i;
  1695. for(i = 0; i < 2; i++) {
  1696. current_position[i] = current_position[i] -
  1697. extruder_offset[i][active_extruder] +
  1698. extruder_offset[i][tmp_extruder];
  1699. }
  1700. // Set the new active extruder and position
  1701. active_extruder = tmp_extruder;
  1702. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1703. // Move to the old position if 'F' was in the parameters
  1704. if(make_move && Stopped == false) {
  1705. prepare_move();
  1706. }
  1707. }
  1708. #endif
  1709. SERIAL_ECHO_START;
  1710. SERIAL_ECHO(MSG_ACTIVE_EXTRUDER);
  1711. SERIAL_PROTOCOLLN((int)active_extruder);
  1712. }
  1713. }
  1714. else
  1715. {
  1716. SERIAL_ECHO_START;
  1717. SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND);
  1718. SERIAL_ECHO(cmdbuffer[bufindr]);
  1719. SERIAL_ECHOLNPGM("\"");
  1720. }
  1721. ClearToSend();
  1722. }
  1723. void FlushSerialRequestResend()
  1724. {
  1725. //char cmdbuffer[bufindr][100]="Resend:";
  1726. MYSERIAL.flush();
  1727. SERIAL_PROTOCOLPGM(MSG_RESEND);
  1728. SERIAL_PROTOCOLLN(gcode_LastN + 1);
  1729. ClearToSend();
  1730. }
  1731. void ClearToSend()
  1732. {
  1733. previous_millis_cmd = millis();
  1734. #ifdef SDSUPPORT
  1735. if(fromsd[bufindr])
  1736. return;
  1737. #endif //SDSUPPORT
  1738. SERIAL_PROTOCOLLNPGM(MSG_OK);
  1739. }
  1740. void get_coordinates()
  1741. {
  1742. bool seen[4]={false,false,false,false};
  1743. for(int8_t i=0; i < NUM_AXIS; i++) {
  1744. if(code_seen(axis_codes[i]))
  1745. {
  1746. destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
  1747. seen[i]=true;
  1748. }
  1749. else destination[i] = current_position[i]; //Are these else lines really needed?
  1750. }
  1751. if(code_seen('F')) {
  1752. next_feedrate = code_value();
  1753. if(next_feedrate > 0.0) feedrate = next_feedrate;
  1754. }
  1755. #ifdef FWRETRACT
  1756. if(autoretract_enabled)
  1757. if( !(seen[X_AXIS] || seen[Y_AXIS] || seen[Z_AXIS]) && seen[E_AXIS])
  1758. {
  1759. float echange=destination[E_AXIS]-current_position[E_AXIS];
  1760. if(echange<-MIN_RETRACT) //retract
  1761. {
  1762. if(!retracted)
  1763. {
  1764. destination[Z_AXIS]+=retract_zlift; //not sure why chaninging current_position negatively does not work.
  1765. //if slicer retracted by echange=-1mm and you want to retract 3mm, corrrectede=-2mm additionally
  1766. float correctede=-echange-retract_length;
  1767. //to generate the additional steps, not the destination is changed, but inversely the current position
  1768. current_position[E_AXIS]+=-correctede;
  1769. feedrate=retract_feedrate;
  1770. retracted=true;
  1771. }
  1772. }
  1773. else
  1774. if(echange>MIN_RETRACT) //retract_recover
  1775. {
  1776. if(retracted)
  1777. {
  1778. //current_position[Z_AXIS]+=-retract_zlift;
  1779. //if slicer retracted_recovered by echange=+1mm and you want to retract_recover 3mm, corrrectede=2mm additionally
  1780. float correctede=-echange+1*retract_length+retract_recover_length; //total unretract=retract_length+retract_recover_length[surplus]
  1781. current_position[E_AXIS]+=correctede; //to generate the additional steps, not the destination is changed, but inversely the current position
  1782. feedrate=retract_recover_feedrate;
  1783. retracted=false;
  1784. }
  1785. }
  1786. }
  1787. #endif //FWRETRACT
  1788. }
  1789. void get_arc_coordinates()
  1790. {
  1791. #ifdef SF_ARC_FIX
  1792. bool relative_mode_backup = relative_mode;
  1793. relative_mode = true;
  1794. #endif
  1795. get_coordinates();
  1796. #ifdef SF_ARC_FIX
  1797. relative_mode=relative_mode_backup;
  1798. #endif
  1799. if(code_seen('I')) {
  1800. offset[0] = code_value();
  1801. }
  1802. else {
  1803. offset[0] = 0.0;
  1804. }
  1805. if(code_seen('J')) {
  1806. offset[1] = code_value();
  1807. }
  1808. else {
  1809. offset[1] = 0.0;
  1810. }
  1811. }
  1812. void clamp_to_software_endstops(float target[3])
  1813. {
  1814. if (min_software_endstops) {
  1815. if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS];
  1816. if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS];
  1817. if (target[Z_AXIS] < min_pos[Z_AXIS]) target[Z_AXIS] = min_pos[Z_AXIS];
  1818. }
  1819. if (max_software_endstops) {
  1820. if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS];
  1821. if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS];
  1822. if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS];
  1823. }
  1824. }
  1825. void prepare_move()
  1826. {
  1827. clamp_to_software_endstops(destination);
  1828. previous_millis_cmd = millis();
  1829. // Do not use feedmultiply for E or Z only moves
  1830. if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
  1831. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
  1832. }
  1833. else {
  1834. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
  1835. }
  1836. for(int8_t i=0; i < NUM_AXIS; i++) {
  1837. current_position[i] = destination[i];
  1838. }
  1839. }
  1840. void prepare_arc_move(char isclockwise) {
  1841. float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
  1842. // Trace the arc
  1843. mc_arc(current_position, destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60/100.0, r, isclockwise, active_extruder);
  1844. // As far as the parser is concerned, the position is now == target. In reality the
  1845. // motion control system might still be processing the action and the real tool position
  1846. // in any intermediate location.
  1847. for(int8_t i=0; i < NUM_AXIS; i++) {
  1848. current_position[i] = destination[i];
  1849. }
  1850. previous_millis_cmd = millis();
  1851. }
  1852. #ifdef CONTROLLERFAN_PIN
  1853. unsigned long lastMotor = 0; //Save the time for when a motor was turned on last
  1854. unsigned long lastMotorCheck = 0;
  1855. void controllerFan()
  1856. {
  1857. if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms
  1858. {
  1859. lastMotorCheck = millis();
  1860. if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN)
  1861. #if EXTRUDERS > 2
  1862. || !READ(E2_ENABLE_PIN)
  1863. #endif
  1864. #if EXTRUDER > 1
  1865. || !READ(E1_ENABLE_PIN)
  1866. #endif
  1867. || !READ(E0_ENABLE_PIN)) //If any of the drivers are enabled...
  1868. {
  1869. lastMotor = millis(); //... set time to NOW so the fan will turn on
  1870. }
  1871. if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC...
  1872. {
  1873. WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off
  1874. }
  1875. else
  1876. {
  1877. WRITE(CONTROLLERFAN_PIN, HIGH); //... turn the fan on
  1878. }
  1879. }
  1880. }
  1881. #endif
  1882. #ifdef EXTRUDERFAN_PIN
  1883. unsigned long lastExtruderCheck = 0;
  1884. void extruderFan()
  1885. {
  1886. if ((millis() - lastExtruderCheck) >= 2500) //Not a time critical function, so we only check every 2500ms
  1887. {
  1888. lastExtruderCheck = millis();
  1889. if (degHotend(active_extruder) < EXTRUDERFAN_DEC)
  1890. {
  1891. WRITE(EXTRUDERFAN_PIN, LOW); //... turn the fan off
  1892. }
  1893. else
  1894. {
  1895. WRITE(EXTRUDERFAN_PIN, HIGH); //... turn the fan on
  1896. }
  1897. }
  1898. }
  1899. #endif
  1900. void manage_inactivity()
  1901. {
  1902. if( (millis() - previous_millis_cmd) > max_inactive_time )
  1903. if(max_inactive_time)
  1904. kill();
  1905. if(stepper_inactive_time) {
  1906. if( (millis() - previous_millis_cmd) > stepper_inactive_time )
  1907. {
  1908. if(blocks_queued() == false) {
  1909. disable_x();
  1910. disable_y();
  1911. disable_z();
  1912. disable_e0();
  1913. disable_e1();
  1914. disable_e2();
  1915. }
  1916. }
  1917. }
  1918. #if( KILL_PIN>-1 )
  1919. if( 0 == READ(KILL_PIN) )
  1920. kill();
  1921. #endif
  1922. #ifdef CONTROLLERFAN_PIN
  1923. controllerFan(); //Check if fan should be turned on to cool stepper drivers down
  1924. #endif
  1925. #ifdef EXTRUDER_RUNOUT_PREVENT
  1926. if( (millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 )
  1927. if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
  1928. {
  1929. bool oldstatus=READ(E0_ENABLE_PIN);
  1930. enable_e0();
  1931. float oldepos=current_position[E_AXIS];
  1932. float oldedes=destination[E_AXIS];
  1933. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS],
  1934. current_position[E_AXIS]+EXTRUDER_RUNOUT_EXTRUDE*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS],
  1935. EXTRUDER_RUNOUT_SPEED/60.*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS], active_extruder);
  1936. current_position[E_AXIS]=oldepos;
  1937. destination[E_AXIS]=oldedes;
  1938. plan_set_e_position(oldepos);
  1939. previous_millis_cmd=millis();
  1940. st_synchronize();
  1941. WRITE(E0_ENABLE_PIN,oldstatus);
  1942. }
  1943. #endif
  1944. check_axes_activity();
  1945. }
  1946. void kill()
  1947. {
  1948. cli(); // Stop interrupts
  1949. disable_heater();
  1950. disable_x();
  1951. disable_y();
  1952. disable_z();
  1953. disable_e0();
  1954. disable_e1();
  1955. disable_e2();
  1956. if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
  1957. SERIAL_ERROR_START;
  1958. SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
  1959. LCD_ALERTMESSAGEPGM(MSG_KILLED);
  1960. suicide();
  1961. while(1) { /* Intentionally left empty */ } // Wait for reset
  1962. }
  1963. void Stop()
  1964. {
  1965. disable_heater();
  1966. if(Stopped == false) {
  1967. Stopped = true;
  1968. Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart
  1969. SERIAL_ERROR_START;
  1970. SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
  1971. LCD_MESSAGEPGM(MSG_STOPPED);
  1972. }
  1973. }
  1974. bool IsStopped() { return Stopped; };
  1975. #ifdef FAST_PWM_FAN
  1976. void setPwmFrequency(uint8_t pin, int val)
  1977. {
  1978. val &= 0x07;
  1979. switch(digitalPinToTimer(pin))
  1980. {
  1981. #if defined(TCCR0A)
  1982. case TIMER0A:
  1983. case TIMER0B:
  1984. // TCCR0B &= ~(_BV(CS00) | _BV(CS01) | _BV(CS02));
  1985. // TCCR0B |= val;
  1986. break;
  1987. #endif
  1988. #if defined(TCCR1A)
  1989. case TIMER1A:
  1990. case TIMER1B:
  1991. // TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
  1992. // TCCR1B |= val;
  1993. break;
  1994. #endif
  1995. #if defined(TCCR2)
  1996. case TIMER2:
  1997. case TIMER2:
  1998. TCCR2 &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
  1999. TCCR2 |= val;
  2000. break;
  2001. #endif
  2002. #if defined(TCCR2A)
  2003. case TIMER2A:
  2004. case TIMER2B:
  2005. TCCR2B &= ~(_BV(CS20) | _BV(CS21) | _BV(CS22));
  2006. TCCR2B |= val;
  2007. break;
  2008. #endif
  2009. #if defined(TCCR3A)
  2010. case TIMER3A:
  2011. case TIMER3B:
  2012. case TIMER3C:
  2013. TCCR3B &= ~(_BV(CS30) | _BV(CS31) | _BV(CS32));
  2014. TCCR3B |= val;
  2015. break;
  2016. #endif
  2017. #if defined(TCCR4A)
  2018. case TIMER4A:
  2019. case TIMER4B:
  2020. case TIMER4C:
  2021. TCCR4B &= ~(_BV(CS40) | _BV(CS41) | _BV(CS42));
  2022. TCCR4B |= val;
  2023. break;
  2024. #endif
  2025. #if defined(TCCR5A)
  2026. case TIMER5A:
  2027. case TIMER5B:
  2028. case TIMER5C:
  2029. TCCR5B &= ~(_BV(CS50) | _BV(CS51) | _BV(CS52));
  2030. TCCR5B |= val;
  2031. break;
  2032. #endif
  2033. }
  2034. }
  2035. #endif //FAST_PWM_FAN
  2036. bool setTargetedHotend(int code){
  2037. tmp_extruder = active_extruder;
  2038. if(code_seen('T')) {
  2039. tmp_extruder = code_value();
  2040. if(tmp_extruder >= EXTRUDERS) {
  2041. SERIAL_ECHO_START;
  2042. switch(code){
  2043. case 104:
  2044. SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER);
  2045. break;
  2046. case 105:
  2047. SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER);
  2048. break;
  2049. case 109:
  2050. SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER);
  2051. break;
  2052. case 218:
  2053. SERIAL_ECHO(MSG_M218_INVALID_EXTRUDER);
  2054. break;
  2055. }
  2056. SERIAL_ECHOLN(tmp_extruder);
  2057. return true;
  2058. }
  2059. }
  2060. return false;
  2061. }