My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Marlin.pde 36KB

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