My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Marlin.pde 36KB

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