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.pde 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*
  2. Reprap firmware based on Sprinter and grbl.
  3. Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /*
  16. This firmware is a mashup between Sprinter and grbl.
  17. (https://github.com/kliment/Sprinter)
  18. (https://github.com/simen/grbl/tree)
  19. It has preliminary support for Matthew Roberts advance algorithm
  20. http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
  21. */
  22. #include <math.h>
  23. #include <EEPROM.h>
  24. #include "EEPROMwrite.h"
  25. #include "fastio.h"
  26. #include "Configuration.h"
  27. #include "pins.h"
  28. #include "Marlin.h"
  29. #include "ultralcd.h"
  30. #include "planner.h"
  31. #include "stepper.h"
  32. #include "temperature.h"
  33. #include "motion_control.h"
  34. #include "cardreader.h"
  35. #include "watchdog.h"
  36. #include <stdio.h>
  37. #define VERSION_STRING "1.0.0 Beta 1"
  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. // G28 - Home all Axis
  48. // G90 - Use Absolute Coordinates
  49. // G91 - Use Relative Coordinates
  50. // G92 - Set current position to cordinates given
  51. //RepRap M Codes
  52. // M104 - Set extruder target temp
  53. // M105 - Read current temp
  54. // M106 - Fan on
  55. // M107 - Fan off
  56. // M109 - Wait for extruder current temp to reach target temp.
  57. // M114 - Display current position
  58. //Custom M Codes
  59. // M17 - Enable/Power all stepper motors
  60. // M18 - Disable all stepper motors; same as M84
  61. // M20 - List SD card
  62. // M21 - Init SD card
  63. // M22 - Release SD card
  64. // M23 - Select SD file (M23 filename.g)
  65. // M24 - Start/resume SD print
  66. // M25 - Pause SD print
  67. // M26 - Set SD position in bytes (M26 S12345)
  68. // M27 - Report SD print status
  69. // M28 - Start SD write (M28 filename.g)
  70. // M29 - Stop SD write
  71. // M30 - Output time since last M109 or SD card start to serial
  72. // M42 - Change pin status via gcode
  73. // M80 - Turn on Power Supply
  74. // M81 - Turn off Power Supply
  75. // M82 - Set E codes absolute (default)
  76. // M83 - Set E codes relative while in Absolute Coordinates (G90) mode
  77. // M84 - Disable steppers until next move,
  78. // or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled. S0 to disable the timeout.
  79. // M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
  80. // M92 - Set axis_steps_per_unit - same syntax as G92
  81. // M114 - Output current position to serial port
  82. // M115 - Capabilities string
  83. // M117 - display message
  84. // M119 - Output Endstop status to serial port
  85. // M140 - Set bed target temp
  86. // M190 - Wait for bed current temp to reach target temp.
  87. // M200 - Set filament diameter
  88. // M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
  89. // M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!
  90. // M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec
  91. // 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
  92. // M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
  93. // M206 - set additional homeing offset
  94. // M220 - set speed factor override percentage S:factor in percent
  95. // M301 - Set PID parameters P I and D
  96. // M400 - Finish all moves
  97. // M500 - stores paramters in EEPROM
  98. // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
  99. // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
  100. //Stepper Movement Variables
  101. //===========================================================================
  102. //=============================imported variables============================
  103. //===========================================================================
  104. extern float HeaterPower;
  105. //===========================================================================
  106. //=============================public variables=============================
  107. //===========================================================================
  108. #ifdef SDSUPPORT
  109. CardReader card;
  110. #endif
  111. float homing_feedrate[] = HOMING_FEEDRATE;
  112. bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
  113. volatile int feedmultiply=100; //100->1 200->2
  114. int saved_feedmultiply;
  115. volatile bool feedmultiplychanged=false;
  116. float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
  117. float add_homeing[3]={0,0,0};
  118. //===========================================================================
  119. //=============================private variables=============================
  120. //===========================================================================
  121. const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
  122. static float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
  123. static float offset[3] = {0.0, 0.0, 0.0};
  124. static bool home_all_axis = true;
  125. static float feedrate = 1500.0, next_feedrate, saved_feedrate;
  126. static long gcode_N, gcode_LastN;
  127. static bool relative_mode = false; //Determines Absolute or Relative Coordinates
  128. static bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
  129. static uint8_t fanpwm=0;
  130. static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
  131. static bool fromsd[BUFSIZE];
  132. static int bufindr = 0;
  133. static int bufindw = 0;
  134. static int buflen = 0;
  135. static int i = 0;
  136. static char serial_char;
  137. static int serial_count = 0;
  138. static boolean comment_mode = false;
  139. static char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
  140. const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
  141. static float tt = 0, bt = 0;
  142. //Inactivity shutdown variables
  143. static unsigned long previous_millis_cmd = 0;
  144. static unsigned long max_inactive_time = 0;
  145. static unsigned long stepper_inactive_time = 0;
  146. static unsigned long starttime=0;
  147. static unsigned long stoptime=0;
  148. static uint8_t tmp_extruder;
  149. //===========================================================================
  150. //=============================ROUTINES=============================
  151. //===========================================================================
  152. void get_arc_coordinates();
  153. extern "C"{
  154. extern unsigned int __bss_end;
  155. extern unsigned int __heap_start;
  156. extern void *__brkval;
  157. int freeMemory() {
  158. int free_memory;
  159. if((int)__brkval == 0)
  160. free_memory = ((int)&free_memory) - ((int)&__bss_end);
  161. else
  162. free_memory = ((int)&free_memory) - ((int)__brkval);
  163. return free_memory;
  164. }
  165. }
  166. //adds an command to the main command buffer
  167. //thats really done in a non-safe way.
  168. //needs overworking someday
  169. void enquecommand(const char *cmd)
  170. {
  171. if(buflen < BUFSIZE)
  172. {
  173. //this is dangerous if a mixing of serial and this happsens
  174. strcpy(&(cmdbuffer[bufindw][0]),cmd);
  175. SERIAL_ECHO_START;
  176. SERIAL_ECHOPGM("enqueing \"");
  177. SERIAL_ECHO(cmdbuffer[bufindw]);
  178. SERIAL_ECHOLNPGM("\"");
  179. bufindw= (bufindw + 1)%BUFSIZE;
  180. buflen += 1;
  181. }
  182. }
  183. void setup()
  184. {
  185. MSerial.begin(BAUDRATE);
  186. SERIAL_ECHO_START;
  187. SERIAL_ECHOLNPGM(VERSION_STRING);
  188. SERIAL_PROTOCOLLNPGM("start");
  189. SERIAL_ECHO_START;
  190. SERIAL_ECHOPGM("Free Memory:");
  191. SERIAL_ECHOLN(freeMemory());
  192. for(int8_t i = 0; i < BUFSIZE; i++)
  193. {
  194. fromsd[i] = false;
  195. }
  196. RetrieveSettings(); // loads data from EEPROM if available
  197. for(int8_t i=0; i < NUM_AXIS; i++)
  198. {
  199. axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
  200. }
  201. tp_init(); // Initialize temperature loop
  202. plan_init(); // Initialize planner;
  203. st_init(); // Initialize stepper;
  204. wd_init();
  205. }
  206. void loop()
  207. {
  208. if(buflen<3)
  209. get_command();
  210. #ifdef SDSUPPORT
  211. card.checkautostart(false);
  212. #endif
  213. if(buflen)
  214. {
  215. #ifdef SDSUPPORT
  216. if(card.saving)
  217. {
  218. if(strstr(cmdbuffer[bufindr],"M29") == NULL)
  219. {
  220. card.write_command(cmdbuffer[bufindr]);
  221. SERIAL_PROTOCOLLNPGM("ok");
  222. }
  223. else
  224. {
  225. card.closefile();
  226. SERIAL_PROTOCOLLNPGM("Done saving file.");
  227. }
  228. }
  229. else
  230. {
  231. process_commands();
  232. }
  233. #else
  234. process_commands();
  235. #endif //SDSUPPORT
  236. buflen = (buflen-1);
  237. bufindr = (bufindr + 1)%BUFSIZE;
  238. }
  239. //check heater every n milliseconds
  240. manage_heater();
  241. manage_inactivity(1);
  242. checkHitEndstops();
  243. LCD_STATUS;
  244. }
  245. FORCE_INLINE void get_command()
  246. {
  247. while( MSerial.available() > 0 && buflen < BUFSIZE) {
  248. serial_char = MSerial.read();
  249. if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) )
  250. {
  251. if(!serial_count) return; //if empty line
  252. cmdbuffer[bufindw][serial_count] = 0; //terminate string
  253. if(!comment_mode){
  254. fromsd[bufindw] = false;
  255. if(strstr(cmdbuffer[bufindw], "N") != NULL)
  256. {
  257. strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
  258. gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
  259. if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) {
  260. SERIAL_ERROR_START;
  261. SERIAL_ERRORPGM("Line Number is not Last Line Number+1, Last Line:");
  262. SERIAL_ERRORLN(gcode_LastN);
  263. //Serial.println(gcode_N);
  264. FlushSerialRequestResend();
  265. serial_count = 0;
  266. return;
  267. }
  268. if(strstr(cmdbuffer[bufindw], "*") != NULL)
  269. {
  270. byte checksum = 0;
  271. byte count = 0;
  272. while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
  273. strchr_pointer = strchr(cmdbuffer[bufindw], '*');
  274. if( (int)(strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) {
  275. SERIAL_ERROR_START;
  276. SERIAL_ERRORPGM("checksum mismatch, Last Line:");
  277. SERIAL_ERRORLN(gcode_LastN);
  278. FlushSerialRequestResend();
  279. serial_count = 0;
  280. return;
  281. }
  282. //if no errors, continue parsing
  283. }
  284. else
  285. {
  286. SERIAL_ERROR_START;
  287. SERIAL_ERRORPGM("No Checksum with line number, Last Line:");
  288. SERIAL_ERRORLN(gcode_LastN);
  289. FlushSerialRequestResend();
  290. serial_count = 0;
  291. return;
  292. }
  293. gcode_LastN = gcode_N;
  294. //if no errors, continue parsing
  295. }
  296. else // if we don't receive 'N' but still see '*'
  297. {
  298. if((strstr(cmdbuffer[bufindw], "*") != NULL))
  299. {
  300. SERIAL_ERROR_START;
  301. SERIAL_ERRORPGM("No Line Number with checksum, Last Line:");
  302. SERIAL_ERRORLN(gcode_LastN);
  303. serial_count = 0;
  304. return;
  305. }
  306. }
  307. if((strstr(cmdbuffer[bufindw], "G") != NULL)){
  308. strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
  309. switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
  310. case 0:
  311. case 1:
  312. case 2:
  313. case 3:
  314. #ifdef SDSUPPORT
  315. if(card.saving)
  316. break;
  317. #endif //SDSUPPORT
  318. SERIAL_PROTOCOLLNPGM("ok");
  319. break;
  320. default:
  321. break;
  322. }
  323. }
  324. bufindw = (bufindw + 1)%BUFSIZE;
  325. buflen += 1;
  326. }
  327. comment_mode = false; //for new command
  328. serial_count = 0; //clear buffer
  329. }
  330. else
  331. {
  332. if(serial_char == ';') comment_mode = true;
  333. if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
  334. }
  335. }
  336. #ifdef SDSUPPORT
  337. if(!card.sdprinting || serial_count!=0){
  338. return;
  339. }
  340. while( !card.eof() && buflen < BUFSIZE) {
  341. int16_t n=card.get();
  342. serial_char = (char)n;
  343. if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1)||n==-1)
  344. {
  345. if(card.eof()){
  346. SERIAL_PROTOCOLLNPGM("Done printing file");
  347. stoptime=millis();
  348. char time[30];
  349. unsigned long t=(stoptime-starttime)/1000;
  350. int sec,min;
  351. min=t/60;
  352. sec=t%60;
  353. sprintf(time,"%i min, %i sec",min,sec);
  354. SERIAL_ECHO_START;
  355. SERIAL_ECHOLN(time);
  356. LCD_MESSAGE(time);
  357. card.printingHasFinished();
  358. card.checkautostart(true);
  359. }
  360. if(serial_char=='\n')
  361. comment_mode = false; //for new command
  362. if(!serial_count)
  363. {
  364. return; //if empty line
  365. }
  366. cmdbuffer[bufindw][serial_count] = 0; //terminate string
  367. if(!comment_mode){
  368. fromsd[bufindw] = true;
  369. buflen += 1;
  370. bufindw = (bufindw + 1)%BUFSIZE;
  371. }
  372. serial_count = 0; //clear buffer
  373. }
  374. else
  375. {
  376. if(serial_char == ';') comment_mode = true;
  377. if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
  378. }
  379. }
  380. #endif //SDSUPPORT
  381. }
  382. FORCE_INLINE float code_value()
  383. {
  384. return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
  385. }
  386. FORCE_INLINE long code_value_long()
  387. {
  388. return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
  389. }
  390. FORCE_INLINE bool code_seen(char code_string[]) //Return True if the string was found
  391. {
  392. return (strstr(cmdbuffer[bufindr], code_string) != NULL);
  393. }
  394. FORCE_INLINE bool code_seen(char code)
  395. {
  396. strchr_pointer = strchr(cmdbuffer[bufindr], code);
  397. return (strchr_pointer != NULL); //Return True if a character was found
  398. }
  399. #define HOMEAXIS(LETTER) \
  400. if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\
  401. { \
  402. current_position[LETTER##_AXIS] = 0; \
  403. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
  404. destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
  405. feedrate = homing_feedrate[LETTER##_AXIS]; \
  406. prepare_move(); \
  407. \
  408. current_position[LETTER##_AXIS] = 0;\
  409. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
  410. destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
  411. prepare_move(); \
  412. \
  413. destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
  414. feedrate = homing_feedrate[LETTER##_AXIS]/2 ; \
  415. prepare_move(); \
  416. \
  417. current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
  418. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
  419. destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
  420. feedrate = 0.0;\
  421. st_synchronize();\
  422. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
  423. endstops_hit_on_purpose();\
  424. }
  425. FORCE_INLINE void process_commands()
  426. {
  427. unsigned long codenum; //throw away variable
  428. char *starpos = NULL;
  429. if(code_seen('G'))
  430. {
  431. switch((int)code_value())
  432. {
  433. case 0: // G0 -> G1
  434. case 1: // G1
  435. get_coordinates(); // For X Y Z E F
  436. prepare_move();
  437. previous_millis_cmd = millis();
  438. //ClearToSend();
  439. return;
  440. //break;
  441. case 2: // G2 - CW ARC
  442. get_arc_coordinates();
  443. prepare_arc_move(true);
  444. previous_millis_cmd = millis();
  445. return;
  446. case 3: // G3 - CCW ARC
  447. get_arc_coordinates();
  448. prepare_arc_move(false);
  449. previous_millis_cmd = millis();
  450. return;
  451. case 4: // G4 dwell
  452. LCD_MESSAGEPGM("DWELL...");
  453. codenum = 0;
  454. if(code_seen('P')) codenum = code_value(); // milliseconds to wait
  455. if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
  456. st_synchronize();
  457. codenum += millis(); // keep track of when we started waiting
  458. while(millis() < codenum ){
  459. manage_heater();
  460. }
  461. break;
  462. case 28: //G28 Home all Axis one at a time
  463. saved_feedrate = feedrate;
  464. saved_feedmultiply = feedmultiply;
  465. feedmultiply = 100;
  466. for(int8_t i=0; i < NUM_AXIS; i++) {
  467. destination[i] = current_position[i];
  468. }
  469. feedrate = 0.0;
  470. home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
  471. #ifdef QUICK_HOME
  472. if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) ) //first diagonal move
  473. {
  474. current_position[X_AXIS] = 0; current_position[Y_AXIS] = 0;
  475. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  476. destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;
  477. destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;
  478. feedrate =homing_feedrate[X_AXIS];
  479. if(homing_feedrate[Y_AXIS]<feedrate)
  480. feedrate =homing_feedrate[Y_AXIS];
  481. prepare_move();
  482. current_position[X_AXIS] = 0; current_position[Y_AXIS] = 0;
  483. }
  484. #endif
  485. if((home_all_axis) || (code_seen(axis_codes[X_AXIS])))
  486. {
  487. HOMEAXIS(X);
  488. current_position[0]=code_value()+add_homeing[0];
  489. }
  490. if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) {
  491. HOMEAXIS(Y);
  492. current_position[1]=code_value()+add_homeing[1];
  493. }
  494. if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
  495. HOMEAXIS(Z);
  496. current_position[2]=code_value()+add_homeing[2];
  497. }
  498. feedrate = saved_feedrate;
  499. feedmultiply = saved_feedmultiply;
  500. previous_millis_cmd = millis();
  501. endstops_hit_on_purpose();
  502. break;
  503. case 90: // G90
  504. relative_mode = false;
  505. break;
  506. case 91: // G91
  507. relative_mode = true;
  508. break;
  509. case 92: // G92
  510. if(!code_seen(axis_codes[E_AXIS]))
  511. st_synchronize();
  512. for(int8_t i=0; i < NUM_AXIS; i++) {
  513. if(code_seen(axis_codes[i])) {
  514. current_position[i] = code_value()+add_homeing[i];
  515. if(i == E_AXIS) {
  516. plan_set_e_position(current_position[E_AXIS]);
  517. }
  518. else {
  519. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  520. }
  521. }
  522. }
  523. break;
  524. }
  525. }
  526. else if(code_seen('M'))
  527. {
  528. switch( (int)code_value() )
  529. {
  530. case 17:
  531. LCD_MESSAGEPGM("No move.");
  532. enable_x();
  533. enable_y();
  534. enable_z();
  535. enable_e();
  536. break;
  537. #ifdef SDSUPPORT
  538. case 20: // M20 - list SD card
  539. SERIAL_PROTOCOLLNPGM("Begin file list");
  540. card.ls();
  541. SERIAL_PROTOCOLLNPGM("End file list");
  542. break;
  543. case 21: // M21 - init SD card
  544. card.initsd();
  545. break;
  546. case 22: //M22 - release SD card
  547. card.release();
  548. break;
  549. case 23: //M23 - Select file
  550. starpos = (strchr(strchr_pointer + 4,'*'));
  551. if(starpos!=NULL)
  552. *(starpos-1)='\0';
  553. card.openFile(strchr_pointer + 4,true);
  554. break;
  555. case 24: //M24 - Start SD print
  556. card.startFileprint();
  557. starttime=millis();
  558. break;
  559. case 25: //M25 - Pause SD print
  560. card.pauseSDPrint();
  561. break;
  562. case 26: //M26 - Set SD index
  563. if(card.cardOK && code_seen('S')){
  564. card.setIndex(code_value_long());
  565. }
  566. break;
  567. case 27: //M27 - Get SD status
  568. card.getStatus();
  569. break;
  570. case 28: //M28 - Start SD write
  571. starpos = (strchr(strchr_pointer + 4,'*'));
  572. if(starpos != NULL){
  573. char* npos = strchr(cmdbuffer[bufindr], 'N');
  574. strchr_pointer = strchr(npos,' ') + 1;
  575. *(starpos-1) = '\0';
  576. }
  577. card.openFile(strchr_pointer+4,false);
  578. break;
  579. case 29: //M29 - Stop SD write
  580. //processed in write to file routine above
  581. //card,saving = false;
  582. break;
  583. #endif //SDSUPPORT
  584. case 30: //M30 take time since the start of the SD print or an M109 command
  585. {
  586. stoptime=millis();
  587. char time[30];
  588. unsigned long t=(stoptime-starttime)/1000;
  589. int sec,min;
  590. min=t/60;
  591. sec=t%60;
  592. sprintf(time,"%i min, %i sec",min,sec);
  593. SERIAL_ECHO_START;
  594. SERIAL_ECHOLN(time);
  595. LCD_MESSAGE(time);
  596. autotempShutdown();
  597. }
  598. break;
  599. case 42: //M42 -Change pin status via gcode
  600. if (code_seen('S'))
  601. {
  602. int pin_status = code_value();
  603. if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
  604. {
  605. int pin_number = code_value();
  606. for(int8_t i = 0; i < (int8_t)sizeof(sensitive_pins); i++)
  607. {
  608. if (sensitive_pins[i] == pin_number)
  609. {
  610. pin_number = -1;
  611. break;
  612. }
  613. }
  614. if (pin_number > -1)
  615. {
  616. pinMode(pin_number, OUTPUT);
  617. digitalWrite(pin_number, pin_status);
  618. analogWrite(pin_number, pin_status);
  619. }
  620. }
  621. }
  622. break;
  623. case 104: // M104
  624. tmp_extruder = active_extruder;
  625. if(code_seen('T')) {
  626. tmp_extruder = code_value();
  627. if(tmp_extruder >= EXTRUDERS) {
  628. SERIAL_ECHO_START;
  629. SERIAL_ECHO("M104 Invalid extruder ");
  630. SERIAL_ECHOLN(tmp_extruder);
  631. break;
  632. }
  633. }
  634. if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
  635. setWatch();
  636. break;
  637. case 140: // M140 set bed temp
  638. if (code_seen('S')) setTargetBed(code_value());
  639. break;
  640. case 105 : // M105
  641. tmp_extruder = active_extruder;
  642. if(code_seen('T')) {
  643. tmp_extruder = code_value();
  644. if(tmp_extruder >= EXTRUDERS) {
  645. SERIAL_ECHO_START;
  646. SERIAL_ECHO("M105 Invalid extruder ");
  647. SERIAL_ECHOLN(tmp_extruder);
  648. break;
  649. }
  650. }
  651. #if (TEMP_0_PIN > -1) || (TEMP_2_PIN > -1)
  652. SERIAL_PROTOCOLPGM("ok T:");
  653. SERIAL_PROTOCOL( degHotend(tmp_extruder));
  654. #if TEMP_1_PIN > -1
  655. SERIAL_PROTOCOLPGM(" B:");
  656. SERIAL_PROTOCOL(degBed());
  657. #endif //TEMP_1_PIN
  658. #else
  659. SERIAL_ERROR_START;
  660. SERIAL_ERRORLNPGM("No thermistors - no temp");
  661. #endif
  662. #ifdef PIDTEMP
  663. SERIAL_PROTOCOLPGM(" @:");
  664. SERIAL_PROTOCOL( HeaterPower);
  665. #endif
  666. SERIAL_PROTOCOLLN("");
  667. return;
  668. break;
  669. case 109:
  670. {// M109 - Wait for extruder heater to reach target.
  671. tmp_extruder = active_extruder;
  672. if(code_seen('T')) {
  673. tmp_extruder = code_value();
  674. if(tmp_extruder >= EXTRUDERS) {
  675. SERIAL_ECHO_START;
  676. SERIAL_ECHO("M109 Invalid extruder ");
  677. SERIAL_ECHOLN(tmp_extruder);
  678. break;
  679. }
  680. }
  681. LCD_MESSAGEPGM("Heating...");
  682. #ifdef AUTOTEMP
  683. autotemp_enabled=false;
  684. #endif
  685. if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
  686. #ifdef AUTOTEMP
  687. if (code_seen('S')) autotemp_min=code_value();
  688. if (code_seen('G')) autotemp_max=code_value();
  689. if (code_seen('F'))
  690. {
  691. autotemp_factor=code_value();
  692. autotemp_enabled=true;
  693. }
  694. #endif
  695. setWatch();
  696. codenum = millis();
  697. /* See if we are heating up or cooling down */
  698. bool target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling
  699. #ifdef TEMP_RESIDENCY_TIME
  700. long residencyStart;
  701. residencyStart = -1;
  702. /* continue to loop until we have reached the target temp
  703. _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
  704. while((target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder))) ||
  705. (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
  706. #else
  707. while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
  708. #endif //TEMP_RESIDENCY_TIME
  709. if( (millis() - codenum) > 1000 )
  710. { //Print Temp Reading every 1 second while heating up/cooling down
  711. SERIAL_PROTOCOLPGM("T:");
  712. SERIAL_PROTOCOLLN( degHotend(tmp_extruder) );
  713. codenum = millis();
  714. }
  715. manage_heater();
  716. LCD_STATUS;
  717. #ifdef TEMP_RESIDENCY_TIME
  718. /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
  719. or when current temp falls outside the hysteresis after target temp was reached */
  720. if ((residencyStart == -1 && target_direction && !isHeatingHotend(tmp_extruder)) ||
  721. (residencyStart == -1 && !target_direction && !isCoolingHotend(tmp_extruder)) ||
  722. (residencyStart > -1 && labs(degHotend(tmp_extruder) - degTargetHotend(tmp_extruder)) > TEMP_HYSTERESIS) )
  723. {
  724. residencyStart = millis();
  725. }
  726. #endif //TEMP_RESIDENCY_TIME
  727. }
  728. LCD_MESSAGEPGM("Heating done.");
  729. starttime=millis();
  730. }
  731. break;
  732. case 190: // M190 - Wait bed for heater to reach target.
  733. #if TEMP_1_PIN > -1
  734. LCD_MESSAGEPGM("Bed Heating.");
  735. if (code_seen('S')) setTargetBed(code_value());
  736. codenum = millis();
  737. while(isHeatingBed())
  738. {
  739. if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
  740. {
  741. float tt=degHotend0();
  742. SERIAL_PROTOCOLPGM("T:");
  743. SERIAL_PROTOCOLLN(tt );
  744. SERIAL_PROTOCOLPGM("ok T:");
  745. SERIAL_PROTOCOL(tt );
  746. SERIAL_PROTOCOLPGM(" B:");
  747. SERIAL_PROTOCOLLN(degBed() );
  748. codenum = millis();
  749. }
  750. manage_heater();
  751. }
  752. LCD_MESSAGEPGM("Bed done.");
  753. #endif
  754. break;
  755. #if FAN_PIN > -1
  756. case 106: //M106 Fan On
  757. if (code_seen('S')){
  758. WRITE(FAN_PIN,HIGH);
  759. fanpwm=constrain(code_value(),0,255);
  760. analogWrite(FAN_PIN, fanpwm);
  761. }
  762. else {
  763. WRITE(FAN_PIN,HIGH);
  764. fanpwm=255;
  765. analogWrite(FAN_PIN, fanpwm);
  766. }
  767. break;
  768. case 107: //M107 Fan Off
  769. WRITE(FAN_PIN,LOW);
  770. analogWrite(FAN_PIN, 0);
  771. break;
  772. #endif //FAN_PIN
  773. #if (PS_ON_PIN > -1)
  774. case 80: // M80 - ATX Power On
  775. SET_OUTPUT(PS_ON_PIN); //GND
  776. break;
  777. case 81: // M81 - ATX Power Off
  778. SET_INPUT(PS_ON_PIN); //Floating
  779. break;
  780. #endif
  781. case 82:
  782. axis_relative_modes[3] = false;
  783. break;
  784. case 83:
  785. axis_relative_modes[3] = true;
  786. break;
  787. case 18: //compatibility
  788. case 84: // M84
  789. if(code_seen('S')){
  790. stepper_inactive_time = code_value() * 1000;
  791. }
  792. else
  793. {
  794. #if ((E_ENABLE_PIN != X_ENABLE_PIN) && (E_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
  795. if(code_seen('E')) {
  796. st_synchronize();
  797. LCD_MESSAGEPGM("Free Move");
  798. disable_e();
  799. }
  800. else {
  801. finishAndDisableSteppers();
  802. }
  803. #else
  804. finishAndDisableSteppers();
  805. #endif
  806. }
  807. break;
  808. case 85: // M85
  809. code_seen('S');
  810. max_inactive_time = code_value() * 1000;
  811. break;
  812. case 92: // M92
  813. for(int8_t i=0; i < NUM_AXIS; i++)
  814. {
  815. if(code_seen(axis_codes[i]))
  816. axis_steps_per_unit[i] = code_value();
  817. }
  818. break;
  819. case 115: // M115
  820. SerialprintPGM("FIRMWARE_NAME:Marlin; Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1");
  821. break;
  822. case 117: // M117 display message
  823. LCD_MESSAGE(cmdbuffer[bufindr]+5);
  824. break;
  825. case 114: // M114
  826. SERIAL_PROTOCOLPGM("X:");
  827. SERIAL_PROTOCOL(current_position[X_AXIS]);
  828. SERIAL_PROTOCOLPGM("Y:");
  829. SERIAL_PROTOCOL(current_position[Y_AXIS]);
  830. SERIAL_PROTOCOLPGM("Z:");
  831. SERIAL_PROTOCOL(current_position[Z_AXIS]);
  832. SERIAL_PROTOCOLPGM("E:");
  833. SERIAL_PROTOCOL(current_position[E_AXIS]);
  834. SERIAL_PROTOCOLPGM(" Count X:");
  835. SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]);
  836. SERIAL_PROTOCOLPGM("Y:");
  837. SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]);
  838. SERIAL_PROTOCOLPGM("Z:");
  839. SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);
  840. SERIAL_PROTOCOLLN("");
  841. break;
  842. case 119: // M119
  843. #if (X_MIN_PIN > -1)
  844. SERIAL_PROTOCOLPGM("x_min:");
  845. SERIAL_PROTOCOL(((READ(X_MIN_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L "));
  846. #endif
  847. #if (X_MAX_PIN > -1)
  848. SERIAL_PROTOCOLPGM("x_max:");
  849. SERIAL_PROTOCOL(((READ(X_MAX_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L "));
  850. #endif
  851. #if (Y_MIN_PIN > -1)
  852. SERIAL_PROTOCOLPGM("y_min:");
  853. SERIAL_PROTOCOL(((READ(Y_MIN_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L "));
  854. #endif
  855. #if (Y_MAX_PIN > -1)
  856. SERIAL_PROTOCOLPGM("y_max:");
  857. SERIAL_PROTOCOL(((READ(Y_MAX_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L "));
  858. #endif
  859. #if (Z_MIN_PIN > -1)
  860. SERIAL_PROTOCOLPGM("z_min:");
  861. SERIAL_PROTOCOL(((READ(Z_MIN_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L "));
  862. #endif
  863. #if (Z_MAX_PIN > -1)
  864. SERIAL_PROTOCOLPGM("z_max:");
  865. SERIAL_PROTOCOL(((READ(Z_MAX_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L "));
  866. #endif
  867. SERIAL_PROTOCOLLN("");
  868. break;
  869. //TODO: update for all axis, use for loop
  870. case 201: // M201
  871. for(int8_t i=0; i < NUM_AXIS; i++)
  872. {
  873. if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
  874. }
  875. break;
  876. #if 0 // Not used for Sprinter/grbl gen6
  877. case 202: // M202
  878. for(int8_t i=0; i < NUM_AXIS; i++) {
  879. if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
  880. }
  881. break;
  882. #endif
  883. case 203: // M203 max feedrate mm/sec
  884. for(int8_t i=0; i < NUM_AXIS; i++) {
  885. if(code_seen(axis_codes[i])) max_feedrate[i] = code_value();
  886. }
  887. break;
  888. case 204: // M204 acclereration S normal moves T filmanent only moves
  889. {
  890. if(code_seen('S')) acceleration = code_value() ;
  891. if(code_seen('T')) retract_acceleration = code_value() ;
  892. }
  893. break;
  894. 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
  895. {
  896. if(code_seen('S')) minimumfeedrate = code_value();
  897. if(code_seen('T')) mintravelfeedrate = code_value();
  898. if(code_seen('B')) minsegmenttime = code_value() ;
  899. if(code_seen('X')) max_xy_jerk = code_value() ;
  900. if(code_seen('Z')) max_z_jerk = code_value() ;
  901. }
  902. break;
  903. case 206: // M206 additional homeing offset
  904. for(int8_t i=0; i < 3; i++)
  905. {
  906. if(code_seen(axis_codes[i])) add_homeing[i] = code_value();
  907. }
  908. break;
  909. case 220: // M220 S<factor in percent>- set speed factor override percentage
  910. {
  911. if(code_seen('S'))
  912. {
  913. feedmultiply = code_value() ;
  914. feedmultiplychanged=true;
  915. }
  916. }
  917. break;
  918. #ifdef PIDTEMP
  919. case 301: // M301
  920. {
  921. if(code_seen('P')) Kp = code_value();
  922. if(code_seen('I')) Ki = code_value()*PID_dT;
  923. if(code_seen('D')) Kd = code_value()/PID_dT;
  924. #ifdef PID_ADD_EXTRUSION_RATE
  925. if(code_seen('C')) Kc = code_value();
  926. #endif
  927. updatePID();
  928. SERIAL_PROTOCOL("ok p:");
  929. SERIAL_PROTOCOL(Kp);
  930. SERIAL_PROTOCOL(" i:");
  931. SERIAL_PROTOCOL(Ki/PID_dT);
  932. SERIAL_PROTOCOL(" d:");
  933. SERIAL_PROTOCOL(Kd*PID_dT);
  934. #ifdef PID_ADD_EXTRUSION_RATE
  935. SERIAL_PROTOCOL(" c:");
  936. SERIAL_PROTOCOL(Kc*PID_dT);
  937. #endif
  938. SERIAL_PROTOCOLLN("");
  939. }
  940. break;
  941. #endif //PIDTEMP
  942. case 400: // finish all moves
  943. {
  944. st_synchronize();
  945. }
  946. break;
  947. case 500: // Store settings in EEPROM
  948. {
  949. StoreSettings();
  950. }
  951. break;
  952. case 501: // Read settings from EEPROM
  953. {
  954. RetrieveSettings();
  955. }
  956. break;
  957. case 502: // Revert to default settings
  958. {
  959. RetrieveSettings(true);
  960. }
  961. break;
  962. }
  963. }
  964. else if(code_seen('T')) {
  965. tmp_extruder = code_value();
  966. if(tmp_extruder >= EXTRUDERS) {
  967. SERIAL_ECHO_START;
  968. SERIAL_ECHO("T");
  969. SERIAL_ECHO(tmp_extruder);
  970. SERIAL_ECHOLN("Invalid extruder");
  971. }
  972. else {
  973. active_extruder = tmp_extruder;
  974. }
  975. }
  976. else
  977. {
  978. SERIAL_ECHO_START;
  979. SERIAL_ECHOPGM("Unknown command:\"");
  980. SERIAL_ECHO(cmdbuffer[bufindr]);
  981. SERIAL_ECHOLNPGM("\"");
  982. }
  983. ClearToSend();
  984. }
  985. void FlushSerialRequestResend()
  986. {
  987. //char cmdbuffer[bufindr][100]="Resend:";
  988. MSerial.flush();
  989. SERIAL_PROTOCOLPGM("Resend:");
  990. SERIAL_PROTOCOLLN(gcode_LastN + 1);
  991. ClearToSend();
  992. }
  993. void ClearToSend()
  994. {
  995. previous_millis_cmd = millis();
  996. #ifdef SDSUPPORT
  997. if(fromsd[bufindr])
  998. return;
  999. #endif //SDSUPPORT
  1000. SERIAL_PROTOCOLLNPGM("ok");
  1001. }
  1002. FORCE_INLINE void get_coordinates()
  1003. {
  1004. for(int8_t i=0; i < NUM_AXIS; i++) {
  1005. if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
  1006. else destination[i] = current_position[i]; //Are these else lines really needed?
  1007. }
  1008. if(code_seen('F')) {
  1009. next_feedrate = code_value();
  1010. if(next_feedrate > 0.0) feedrate = next_feedrate;
  1011. }
  1012. }
  1013. FORCE_INLINE void get_arc_coordinates()
  1014. {
  1015. get_coordinates();
  1016. if(code_seen('I')) offset[0] = code_value();
  1017. if(code_seen('J')) offset[1] = code_value();
  1018. }
  1019. void prepare_move()
  1020. {
  1021. if (min_software_endstops) {
  1022. if (destination[X_AXIS] < 0) destination[X_AXIS] = 0.0;
  1023. if (destination[Y_AXIS] < 0) destination[Y_AXIS] = 0.0;
  1024. if (destination[Z_AXIS] < 0) destination[Z_AXIS] = 0.0;
  1025. }
  1026. if (max_software_endstops) {
  1027. if (destination[X_AXIS] > X_MAX_LENGTH) destination[X_AXIS] = X_MAX_LENGTH;
  1028. if (destination[Y_AXIS] > Y_MAX_LENGTH) destination[Y_AXIS] = Y_MAX_LENGTH;
  1029. if (destination[Z_AXIS] > Z_MAX_LENGTH) destination[Z_AXIS] = Z_MAX_LENGTH;
  1030. }
  1031. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
  1032. for(int8_t i=0; i < NUM_AXIS; i++) {
  1033. current_position[i] = destination[i];
  1034. }
  1035. }
  1036. void prepare_arc_move(char isclockwise) {
  1037. float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
  1038. // Trace the arc
  1039. mc_arc(current_position, destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60/100.0, r, isclockwise, active_extruder);
  1040. // As far as the parser is concerned, the position is now == target. In reality the
  1041. // motion control system might still be processing the action and the real tool position
  1042. // in any intermediate location.
  1043. for(int8_t i=0; i < NUM_AXIS; i++) {
  1044. current_position[i] = destination[i];
  1045. }
  1046. }
  1047. void manage_inactivity(byte debug)
  1048. {
  1049. if( (millis()-previous_millis_cmd) > max_inactive_time )
  1050. if(max_inactive_time)
  1051. kill();
  1052. if( (millis()-previous_millis_cmd) > stepper_inactive_time )
  1053. if(stepper_inactive_time)
  1054. {
  1055. disable_x();
  1056. disable_y();
  1057. disable_z();
  1058. disable_e();
  1059. }
  1060. check_axes_activity();
  1061. }
  1062. void kill()
  1063. {
  1064. disable_heater();
  1065. disable_x();
  1066. disable_y();
  1067. disable_z();
  1068. disable_e();
  1069. if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
  1070. SERIAL_ERROR_START;
  1071. SERIAL_ERRORLNPGM("Printer halted. kill() called !!");
  1072. LCD_MESSAGEPGM("KILLED. ");
  1073. while(1); // Wait for reset
  1074. }