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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  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 "EEPROMwrite.h"
  23. #include "fastio.h"
  24. #include "Configuration.h"
  25. #include "pins.h"
  26. #include "Marlin.h"
  27. #include "ultralcd.h"
  28. #include "streaming.h"
  29. #include "planner.h"
  30. #include "stepper.h"
  31. #include "temperature.h"
  32. #ifdef SIMPLE_LCD
  33. #include "Simplelcd.h"
  34. #endif
  35. char version_string[] = "1.0.0 Alpha 1";
  36. #ifdef SDSUPPORT
  37. #include "SdFat.h"
  38. #endif //SDSUPPORT
  39. // look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html
  40. // http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
  41. //Implemented Codes
  42. //-------------------
  43. // G0 -> G1
  44. // G1 - Coordinated Movement X Y Z E
  45. // G4 - Dwell S<seconds> or P<milliseconds>
  46. // G28 - Home all Axis
  47. // G90 - Use Absolute Coordinates
  48. // G91 - Use Relative Coordinates
  49. // G92 - Set current position to cordinates given
  50. //RepRap M Codes
  51. // M104 - Set extruder target temp
  52. // M105 - Read current temp
  53. // M106 - Fan on
  54. // M107 - Fan off
  55. // M109 - Wait for extruder current temp to reach target temp.
  56. // M114 - Display current position
  57. //Custom M Codes
  58. // M20 - List SD card
  59. // M21 - Init SD card
  60. // M22 - Release SD card
  61. // M23 - Select SD file (M23 filename.g)
  62. // M24 - Start/resume SD print
  63. // M25 - Pause SD print
  64. // M26 - Set SD position in bytes (M26 S12345)
  65. // M27 - Report SD print status
  66. // M28 - Start SD write (M28 filename.g)
  67. // M29 - Stop SD write
  68. // M42 - Change pin status via gcode
  69. // M80 - Turn on Power Supply
  70. // M81 - Turn off Power Supply
  71. // M82 - Set E codes absolute (default)
  72. // M83 - Set E codes relative while in Absolute Coordinates (G90) mode
  73. // M84 - Disable steppers until next move,
  74. // or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled. S0 to disable the timeout.
  75. // M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
  76. // M92 - Set axis_steps_per_unit - same syntax as G92
  77. // M115 - Capabilities string
  78. // M140 - Set bed target temp
  79. // M190 - Wait for bed current temp to reach target temp.
  80. // M200 - Set filament diameter
  81. // M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
  82. // M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!
  83. // M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec
  84. // 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
  85. // M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
  86. // M220 - set speed factor override percentage S:factor in percent
  87. // M301 - Set PID parameters P I and D
  88. // M500 - stores paramters in EEPROM
  89. // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). D
  90. // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
  91. //Stepper Movement Variables
  92. char axis_codes[NUM_AXIS] = {
  93. 'X', 'Y', 'Z', 'E'};
  94. float destination[NUM_AXIS] = {
  95. 0.0, 0.0, 0.0, 0.0};
  96. float current_position[NUM_AXIS] = {
  97. 0.0, 0.0, 0.0, 0.0};
  98. bool home_all_axis = true;
  99. float feedrate = 1500.0, next_feedrate, saved_feedrate;
  100. long gcode_N, gcode_LastN;
  101. float homing_feedrate[] = HOMING_FEEDRATE;
  102. bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
  103. bool relative_mode = false; //Determines Absolute or Relative Coordinates
  104. bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
  105. uint8_t fanpwm=0;
  106. volatile int feedmultiply=100; //100->1 200->2
  107. int saved_feedmultiply;
  108. volatile bool feedmultiplychanged=false;
  109. // comm variables
  110. #define MAX_CMD_SIZE 96
  111. #define BUFSIZE 4
  112. char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
  113. bool fromsd[BUFSIZE];
  114. int bufindr = 0;
  115. int bufindw = 0;
  116. int buflen = 0;
  117. int i = 0;
  118. char serial_char;
  119. int serial_count = 0;
  120. boolean comment_mode = false;
  121. char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
  122. extern float HeaterPower;
  123. #include "EEPROM.h"
  124. const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
  125. float tt = 0, bt = 0;
  126. #ifdef WATCHPERIOD
  127. int watch_raw = -1000;
  128. unsigned long watchmillis = 0;
  129. #endif //WATCHPERIOD
  130. //Inactivity shutdown variables
  131. unsigned long previous_millis_cmd = 0;
  132. unsigned long max_inactive_time = 0;
  133. unsigned long stepper_inactive_time = 0;
  134. unsigned long starttime=0;
  135. unsigned long stoptime=0;
  136. #ifdef SDSUPPORT
  137. Sd2Card card;
  138. SdVolume volume;
  139. SdFile root;
  140. SdFile file;
  141. uint32_t filesize = 0;
  142. uint32_t sdpos = 0;
  143. bool sdmode = false;
  144. bool sdactive = false;
  145. bool savetosd = false;
  146. int16_t n;
  147. unsigned long autostart_atmillis=0;
  148. void initsd(){
  149. sdactive = false;
  150. #if SDSS >- 1
  151. if(root.isOpen())
  152. root.close();
  153. if (!card.init(SPI_FULL_SPEED,SDSS)){
  154. //if (!card.init(SPI_HALF_SPEED,SDSS))
  155. Serial.println("SD init fail");
  156. }
  157. else if (!volume.init(&card))
  158. Serial.println("volume.init failed");
  159. else if (!root.openRoot(&volume))
  160. Serial.println("openRoot failed");
  161. else
  162. {
  163. sdactive = true;
  164. Serial.println("SD card ok");
  165. }
  166. #endif //SDSS
  167. }
  168. void quickinitsd(){
  169. sdactive=false;
  170. autostart_atmillis=millis()+5000;
  171. }
  172. inline void write_command(char *buf){
  173. char* begin = buf;
  174. char* npos = 0;
  175. char* end = buf + strlen(buf) - 1;
  176. file.writeError = false;
  177. if((npos = strchr(buf, 'N')) != NULL){
  178. begin = strchr(npos, ' ') + 1;
  179. end = strchr(npos, '*') - 1;
  180. }
  181. end[1] = '\r';
  182. end[2] = '\n';
  183. end[3] = '\0';
  184. //Serial.println(begin);
  185. file.write(begin);
  186. if (file.writeError){
  187. Serial.println("error writing to file");
  188. }
  189. }
  190. #endif //SDSUPPORT
  191. ///adds an command to the main command buffer
  192. void enquecommand(const char *cmd)
  193. {
  194. if(buflen < BUFSIZE)
  195. {
  196. //this is dangerous if a mixing of serial and this happsens
  197. strcpy(&(cmdbuffer[bufindw][0]),cmd);
  198. Serial.print("en:");Serial.println(cmdbuffer[bufindw]);
  199. bufindw= (bufindw + 1)%BUFSIZE;
  200. buflen += 1;
  201. }
  202. }
  203. void setup()
  204. {
  205. Serial.begin(BAUDRATE);
  206. ECHOLN("Marlin "<<version_string);
  207. Serial.println("start");
  208. #if defined FANCY_LCD || defined SIMPLE_LCD
  209. lcd_init();
  210. #endif
  211. for(int i = 0; i < BUFSIZE; i++){
  212. fromsd[i] = false;
  213. }
  214. RetrieveSettings(); // loads data from EEPROM if available
  215. for(int i=0; i < NUM_AXIS; i++){
  216. axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
  217. }
  218. #ifdef SDSUPPORT
  219. //power to SD reader
  220. #if SDPOWER > -1
  221. SET_OUTPUT(SDPOWER);
  222. WRITE(SDPOWER,HIGH);
  223. #endif //SDPOWER
  224. quickinitsd();
  225. #endif //SDSUPPORT
  226. plan_init(); // Initialize planner;
  227. st_init(); // Initialize stepper;
  228. tp_init(); // Initialize temperature loop
  229. //checkautostart();
  230. }
  231. #ifdef SDSUPPORT
  232. bool autostart_stilltocheck=true;
  233. void checkautostart(bool force)
  234. {
  235. //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
  236. if(!force)
  237. {
  238. if(!autostart_stilltocheck)
  239. return;
  240. if(autostart_atmillis<millis())
  241. return;
  242. }
  243. autostart_stilltocheck=false;
  244. if(!sdactive)
  245. {
  246. initsd();
  247. if(!sdactive) //fail
  248. return;
  249. }
  250. static int lastnr=0;
  251. char autoname[30];
  252. sprintf(autoname,"auto%i.g",lastnr);
  253. for(int i=0;i<(int)strlen(autoname);i++)
  254. autoname[i]=tolower(autoname[i]);
  255. dir_t p;
  256. root.rewind();
  257. //char filename[11];
  258. //int cnt=0;
  259. bool found=false;
  260. while (root.readDir(p) > 0)
  261. {
  262. for(int i=0;i<(int)strlen((char*)p.name);i++)
  263. p.name[i]=tolower(p.name[i]);
  264. //Serial.print((char*)p.name);
  265. //Serial.print(" ");
  266. //Serial.println(autoname);
  267. if(p.name[9]!='~') //skip safety copies
  268. if(strncmp((char*)p.name,autoname,5)==0)
  269. {
  270. char cmd[30];
  271. sprintf(cmd,"M23 %s",autoname);
  272. //sprintf(cmd,"M115");
  273. //enquecommand("G92 Z0");
  274. //enquecommand("G1 Z10 F2000");
  275. //enquecommand("G28 X-105 Y-105");
  276. enquecommand(cmd);
  277. enquecommand("M24");
  278. found=true;
  279. }
  280. }
  281. if(!found)
  282. lastnr=-1;
  283. else
  284. lastnr++;
  285. }
  286. #else
  287. inline void checkautostart(bool x)
  288. {
  289. }
  290. #endif
  291. void loop()
  292. {
  293. if(buflen<3)
  294. get_command();
  295. checkautostart(false);
  296. if(buflen)
  297. {
  298. #ifdef SDSUPPORT
  299. if(savetosd){
  300. if(strstr(cmdbuffer[bufindr],"M29") == NULL){
  301. write_command(cmdbuffer[bufindr]);
  302. Serial.println("ok");
  303. }
  304. else{
  305. file.sync();
  306. file.close();
  307. savetosd = false;
  308. Serial.println("Done saving file.");
  309. }
  310. }
  311. else{
  312. process_commands();
  313. }
  314. #else
  315. process_commands();
  316. #endif //SDSUPPORT
  317. buflen = (buflen-1);
  318. bufindr = (bufindr + 1)%BUFSIZE;
  319. }
  320. //check heater every n milliseconds
  321. manage_heater();
  322. manage_inactivity(1);
  323. LCD_STATUS;
  324. }
  325. inline void get_command()
  326. {
  327. while( Serial.available() > 0 && buflen < BUFSIZE) {
  328. serial_char = Serial.read();
  329. if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) )
  330. {
  331. if(!serial_count) return; //if empty line
  332. cmdbuffer[bufindw][serial_count] = 0; //terminate string
  333. if(!comment_mode){
  334. fromsd[bufindw] = false;
  335. if(strstr(cmdbuffer[bufindw], "N") != NULL)
  336. {
  337. strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
  338. gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
  339. if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) {
  340. Serial.print("Serial Error: Line Number is not Last Line Number+1, Last Line:");
  341. Serial.println(gcode_LastN);
  342. //Serial.println(gcode_N);
  343. FlushSerialRequestResend();
  344. serial_count = 0;
  345. return;
  346. }
  347. if(strstr(cmdbuffer[bufindw], "*") != NULL)
  348. {
  349. byte checksum = 0;
  350. byte count = 0;
  351. while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
  352. strchr_pointer = strchr(cmdbuffer[bufindw], '*');
  353. if( (int)(strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) {
  354. Serial.print("Error: checksum mismatch, Last Line:");
  355. Serial.println(gcode_LastN);
  356. FlushSerialRequestResend();
  357. serial_count = 0;
  358. return;
  359. }
  360. //if no errors, continue parsing
  361. }
  362. else
  363. {
  364. Serial.print("Error: No Checksum with line number, Last Line:");
  365. Serial.println(gcode_LastN);
  366. FlushSerialRequestResend();
  367. serial_count = 0;
  368. return;
  369. }
  370. gcode_LastN = gcode_N;
  371. //if no errors, continue parsing
  372. }
  373. else // if we don't receive 'N' but still see '*'
  374. {
  375. if((strstr(cmdbuffer[bufindw], "*") != NULL))
  376. {
  377. Serial.print("Error: No Line Number with checksum, Last Line:");
  378. Serial.println(gcode_LastN);
  379. serial_count = 0;
  380. return;
  381. }
  382. }
  383. if((strstr(cmdbuffer[bufindw], "G") != NULL)){
  384. strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
  385. switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
  386. case 0:
  387. case 1:
  388. #ifdef SDSUPPORT
  389. if(savetosd)
  390. break;
  391. #endif //SDSUPPORT
  392. Serial.println("ok");
  393. break;
  394. default:
  395. break;
  396. }
  397. }
  398. bufindw = (bufindw + 1)%BUFSIZE;
  399. buflen += 1;
  400. }
  401. comment_mode = false; //for new command
  402. serial_count = 0; //clear buffer
  403. }
  404. else
  405. {
  406. if(serial_char == ';') comment_mode = true;
  407. if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
  408. }
  409. }
  410. #ifdef SDSUPPORT
  411. if(!sdmode || serial_count!=0){
  412. return;
  413. }
  414. while( filesize > sdpos && buflen < BUFSIZE) {
  415. n = file.read();
  416. serial_char = (char)n;
  417. if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) || n == -1)
  418. {
  419. sdpos = file.curPosition();
  420. if(sdpos >= filesize){
  421. sdmode = false;
  422. Serial.println("Done printing file");
  423. stoptime=millis();
  424. char time[30];
  425. unsigned long t=(stoptime-starttime)/1000;
  426. int sec,min;
  427. min=t/60;
  428. sec=t%60;
  429. sprintf(time,"%i min, %i sec",min,sec);
  430. Serial.println(time);
  431. LCD_MESSAGE(time);
  432. checkautostart(true);
  433. }
  434. if(!serial_count) return; //if empty line
  435. cmdbuffer[bufindw][serial_count] = 0; //terminate string
  436. if(!comment_mode){
  437. fromsd[bufindw] = true;
  438. buflen += 1;
  439. bufindw = (bufindw + 1)%BUFSIZE;
  440. }
  441. comment_mode = false; //for new command
  442. serial_count = 0; //clear buffer
  443. }
  444. else
  445. {
  446. if(serial_char == ';') comment_mode = true;
  447. if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
  448. }
  449. }
  450. #endif //SDSUPPORT
  451. }
  452. inline float code_value() {
  453. return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
  454. }
  455. inline long code_value_long() {
  456. return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
  457. }
  458. inline bool code_seen(char code_string[]) {
  459. return (strstr(cmdbuffer[bufindr], code_string) != NULL);
  460. } //Return True if the string was found
  461. inline bool code_seen(char code)
  462. {
  463. strchr_pointer = strchr(cmdbuffer[bufindr], code);
  464. return (strchr_pointer != NULL); //Return True if a character was found
  465. }
  466. inline void process_commands()
  467. {
  468. unsigned long codenum; //throw away variable
  469. char *starpos = NULL;
  470. if(code_seen('G'))
  471. {
  472. switch((int)code_value())
  473. {
  474. case 0: // G0 -> G1
  475. case 1: // G1
  476. get_coordinates(); // For X Y Z E F
  477. prepare_move();
  478. previous_millis_cmd = millis();
  479. //ClearToSend();
  480. return;
  481. //break;
  482. case 4: // G4 dwell
  483. codenum = 0;
  484. if(code_seen('P')) codenum = code_value(); // milliseconds to wait
  485. if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
  486. codenum += millis(); // keep track of when we started waiting
  487. while(millis() < codenum ){
  488. manage_heater();
  489. }
  490. break;
  491. case 28: //G28 Home all Axis one at a time
  492. saved_feedrate = feedrate;
  493. saved_feedmultiply = feedmultiply;
  494. feedmultiply = 100;
  495. for(int i=0; i < NUM_AXIS; i++) {
  496. destination[i] = current_position[i];
  497. }
  498. feedrate = 0.0;
  499. home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
  500. if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) {
  501. if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)){
  502. // st_synchronize();
  503. current_position[X_AXIS] = 0;
  504. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  505. destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;
  506. feedrate = homing_feedrate[X_AXIS];
  507. prepare_move();
  508. // st_synchronize();
  509. current_position[X_AXIS] = 0;
  510. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  511. destination[X_AXIS] = -5 * X_HOME_DIR;
  512. prepare_move();
  513. // st_synchronize();
  514. destination[X_AXIS] = 10 * X_HOME_DIR;
  515. feedrate = homing_feedrate[X_AXIS]/2 ;
  516. prepare_move();
  517. // st_synchronize();
  518. current_position[X_AXIS] = (X_HOME_DIR == -1) ? 0 : X_MAX_LENGTH;
  519. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  520. destination[X_AXIS] = current_position[X_AXIS];
  521. feedrate = 0.0;
  522. }
  523. }
  524. if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) {
  525. if ((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1)){
  526. current_position[Y_AXIS] = 0;
  527. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  528. destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;
  529. feedrate = homing_feedrate[Y_AXIS];
  530. prepare_move();
  531. // st_synchronize();
  532. current_position[Y_AXIS] = 0;
  533. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  534. destination[Y_AXIS] = -5 * Y_HOME_DIR;
  535. prepare_move();
  536. // st_synchronize();
  537. destination[Y_AXIS] = 10 * Y_HOME_DIR;
  538. feedrate = homing_feedrate[Y_AXIS]/2;
  539. prepare_move();
  540. // st_synchronize();
  541. current_position[Y_AXIS] = (Y_HOME_DIR == -1) ? 0 : Y_MAX_LENGTH;
  542. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  543. destination[Y_AXIS] = current_position[Y_AXIS];
  544. feedrate = 0.0;
  545. }
  546. }
  547. if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
  548. if ((Z_MIN_PIN > -1 && Z_HOME_DIR==-1) || (Z_MAX_PIN > -1 && Z_HOME_DIR==1)){
  549. current_position[Z_AXIS] = 0;
  550. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  551. destination[Z_AXIS] = 1.5 * Z_MAX_LENGTH * Z_HOME_DIR;
  552. feedrate = homing_feedrate[Z_AXIS];
  553. prepare_move();
  554. // st_synchronize();
  555. current_position[Z_AXIS] = 0;
  556. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  557. destination[Z_AXIS] = -2 * Z_HOME_DIR;
  558. prepare_move();
  559. // st_synchronize();
  560. destination[Z_AXIS] = 3 * Z_HOME_DIR;
  561. feedrate = homing_feedrate[Z_AXIS]/2;
  562. prepare_move();
  563. // st_synchronize();
  564. current_position[Z_AXIS] = (Z_HOME_DIR == -1) ? 0 : Z_MAX_LENGTH;
  565. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  566. destination[Z_AXIS] = current_position[Z_AXIS];
  567. feedrate = 0.0;
  568. }
  569. }
  570. feedrate = saved_feedrate;
  571. feedmultiply = saved_feedmultiply;
  572. previous_millis_cmd = millis();
  573. break;
  574. case 90: // G90
  575. relative_mode = false;
  576. break;
  577. case 91: // G91
  578. relative_mode = true;
  579. break;
  580. case 92: // G92
  581. if(!code_seen(axis_codes[E_AXIS]))
  582. st_synchronize();
  583. for(int i=0; i < NUM_AXIS; i++) {
  584. if(code_seen(axis_codes[i])) current_position[i] = code_value();
  585. }
  586. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  587. break;
  588. }
  589. }
  590. else if(code_seen('M'))
  591. {
  592. switch( (int)code_value() )
  593. {
  594. #ifdef SDSUPPORT
  595. case 20: // M20 - list SD card
  596. Serial.println("Begin file list");
  597. root.ls();
  598. Serial.println("End file list");
  599. break;
  600. case 21: // M21 - init SD card
  601. sdmode = false;
  602. initsd();
  603. break;
  604. case 22: //M22 - release SD card
  605. sdmode = false;
  606. sdactive = false;
  607. break;
  608. case 23: //M23 - Select file
  609. if(sdactive){
  610. sdmode = false;
  611. file.close();
  612. starpos = (strchr(strchr_pointer + 4,'*'));
  613. if(starpos!=NULL)
  614. *(starpos-1)='\0';
  615. if (file.open(&root, strchr_pointer + 4, O_READ)) {
  616. Serial.print("File opened:");
  617. Serial.print(strchr_pointer + 4);
  618. Serial.print(" Size:");
  619. Serial.println(file.fileSize());
  620. sdpos = 0;
  621. filesize = file.fileSize();
  622. Serial.println("File selected");
  623. }
  624. else{
  625. Serial.println("file.open failed");
  626. }
  627. }
  628. break;
  629. case 24: //M24 - Start SD print
  630. if(sdactive){
  631. sdmode = true;
  632. starttime=millis();
  633. }
  634. break;
  635. case 25: //M25 - Pause SD print
  636. if(sdmode){
  637. sdmode = false;
  638. }
  639. break;
  640. case 26: //M26 - Set SD index
  641. if(sdactive && code_seen('S')){
  642. sdpos = code_value_long();
  643. file.seekSet(sdpos);
  644. }
  645. break;
  646. case 27: //M27 - Get SD status
  647. if(sdactive){
  648. Serial.print("SD printing byte ");
  649. Serial.print(sdpos);
  650. Serial.print("/");
  651. Serial.println(filesize);
  652. }
  653. else{
  654. Serial.println("Not SD printing");
  655. }
  656. break;
  657. case 28: //M28 - Start SD write
  658. if(sdactive){
  659. char* npos = 0;
  660. file.close();
  661. sdmode = false;
  662. starpos = (strchr(strchr_pointer + 4,'*'));
  663. if(starpos != NULL){
  664. npos = strchr(cmdbuffer[bufindr], 'N');
  665. strchr_pointer = strchr(npos,' ') + 1;
  666. *(starpos-1) = '\0';
  667. }
  668. if (!file.open(&root, strchr_pointer+4, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
  669. {
  670. Serial.print("open failed, File: ");
  671. Serial.print(strchr_pointer + 4);
  672. Serial.print(".");
  673. }
  674. else{
  675. savetosd = true;
  676. Serial.print("Writing to file: ");
  677. Serial.println(strchr_pointer + 4);
  678. }
  679. }
  680. break;
  681. case 29: //M29 - Stop SD write
  682. //processed in write to file routine above
  683. //savetosd = false;
  684. break;
  685. case 30:
  686. {
  687. stoptime=millis();
  688. char time[30];
  689. unsigned long t=(stoptime-starttime)/1000;
  690. int sec,min;
  691. min=t/60;
  692. sec=t%60;
  693. sprintf(time,"%i min, %i sec",min,sec);
  694. Serial.println(time);
  695. LCD_MESSAGE(time);
  696. }
  697. break;
  698. #endif //SDSUPPORT
  699. case 42: //M42 -Change pin status via gcode
  700. if (code_seen('S'))
  701. {
  702. int pin_status = code_value();
  703. if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
  704. {
  705. int pin_number = code_value();
  706. for(int i = 0; i < (int)sizeof(sensitive_pins); i++)
  707. {
  708. if (sensitive_pins[i] == pin_number)
  709. {
  710. pin_number = -1;
  711. break;
  712. }
  713. }
  714. if (pin_number > -1)
  715. {
  716. pinMode(pin_number, OUTPUT);
  717. digitalWrite(pin_number, pin_status);
  718. analogWrite(pin_number, pin_status);
  719. }
  720. }
  721. }
  722. break;
  723. case 104: // M104
  724. if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
  725. #ifdef PIDTEMP
  726. pid_setpoint = code_value();
  727. #endif //PIDTEM
  728. #ifdef WATCHPERIOD
  729. if(target_raw[TEMPSENSOR_HOTEND] > current_raw[TEMPSENSOR_HOTEND]){
  730. watchmillis = max(1,millis());
  731. watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
  732. }else{
  733. watchmillis = 0;
  734. }
  735. #endif
  736. break;
  737. case 140: // M140 set bed temp
  738. if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value());
  739. break;
  740. case 105: // M105
  741. #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
  742. tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
  743. #endif
  744. #if TEMP_1_PIN > -1
  745. bt = analog2tempBed(current_raw[TEMPSENSOR_BED]);
  746. #endif
  747. #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
  748. Serial.print("ok T:");
  749. Serial.print(tt);
  750. // Serial.print(", raw:");
  751. // Serial.print(current_raw);
  752. #if TEMP_1_PIN > -1
  753. #ifdef PIDTEMP
  754. Serial.print(" B:");
  755. #if TEMP_1_PIN > -1
  756. Serial.println(bt);
  757. #else
  758. Serial.println(HeaterPower);
  759. #endif
  760. #else
  761. Serial.println();
  762. #endif
  763. #else
  764. Serial.println();
  765. #endif
  766. #else
  767. Serial.println("No thermistors - no temp");
  768. #endif
  769. return;
  770. //break;
  771. case 109: {// M109 - Wait for extruder heater to reach target.
  772. LCD_MESSAGE("Heating...");
  773. if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
  774. #ifdef PIDTEMP
  775. pid_setpoint = code_value();
  776. #endif //PIDTEM
  777. #ifdef WATCHPERIOD
  778. if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){
  779. watchmillis = max(1,millis());
  780. watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
  781. } else {
  782. watchmillis = 0;
  783. }
  784. #endif //WATCHPERIOD
  785. codenum = millis();
  786. /* See if we are heating up or cooling down */
  787. bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling
  788. #ifdef TEMP_RESIDENCY_TIME
  789. long residencyStart;
  790. residencyStart = -1;
  791. /* continue to loop until we have reached the target temp
  792. _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
  793. while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) ||
  794. (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
  795. #else
  796. while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) {
  797. #endif //TEMP_RESIDENCY_TIME
  798. if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
  799. Serial.print("T:");
  800. Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) );
  801. codenum = millis();
  802. }
  803. manage_heater();
  804. LCD_STATUS;
  805. #ifdef TEMP_RESIDENCY_TIME
  806. /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
  807. or when current temp falls outside the hysteresis after target temp was reached */
  808. if ((residencyStart == -1 && target_direction && current_raw[0] >= target_raw[0]) ||
  809. (residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) ||
  810. (residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) {
  811. residencyStart = millis();
  812. }
  813. #endif //TEMP_RESIDENCY_TIME
  814. }
  815. LCD_MESSAGE("Marlin ready.");
  816. }
  817. break;
  818. case 190: // M190 - Wait bed for heater to reach target.
  819. #if TEMP_1_PIN > -1
  820. if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value());
  821. codenum = millis();
  822. while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED])
  823. {
  824. if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
  825. {
  826. float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]);
  827. Serial.print("T:");
  828. Serial.println( tt );
  829. Serial.print("ok T:");
  830. Serial.print( tt );
  831. Serial.print(" B:");
  832. Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) );
  833. codenum = millis();
  834. }
  835. manage_heater();
  836. }
  837. #endif
  838. break;
  839. #if FAN_PIN > -1
  840. case 106: //M106 Fan On
  841. if (code_seen('S')){
  842. WRITE(FAN_PIN,HIGH);
  843. fanpwm=constrain(code_value(),0,255);
  844. analogWrite(FAN_PIN, fanpwm);
  845. }
  846. else {
  847. WRITE(FAN_PIN,HIGH);
  848. fanpwm=255;
  849. analogWrite(FAN_PIN, fanpwm);
  850. }
  851. break;
  852. case 107: //M107 Fan Off
  853. WRITE(FAN_PIN,LOW);
  854. analogWrite(FAN_PIN, 0);
  855. break;
  856. #endif
  857. #if (PS_ON_PIN > -1)
  858. case 80: // M80 - ATX Power On
  859. SET_OUTPUT(PS_ON_PIN); //GND
  860. break;
  861. case 81: // M81 - ATX Power Off
  862. SET_INPUT(PS_ON_PIN); //Floating
  863. break;
  864. #endif
  865. case 82:
  866. axis_relative_modes[3] = false;
  867. break;
  868. case 83:
  869. axis_relative_modes[3] = true;
  870. break;
  871. case 18:
  872. case 84:
  873. if(code_seen('S')){
  874. stepper_inactive_time = code_value() * 1000;
  875. }
  876. else{
  877. st_synchronize();
  878. disable_x();
  879. disable_y();
  880. disable_z();
  881. disable_e();
  882. }
  883. break;
  884. case 85: // M85
  885. code_seen('S');
  886. max_inactive_time = code_value() * 1000;
  887. break;
  888. case 92: // M92
  889. for(int i=0; i < NUM_AXIS; i++) {
  890. if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value();
  891. }
  892. break;
  893. case 115: // M115
  894. Serial.println("FIRMWARE_NAME:Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1");
  895. break;
  896. case 114: // M114
  897. Serial.print("X:");
  898. Serial.print(current_position[X_AXIS]);
  899. Serial.print("Y:");
  900. Serial.print(current_position[Y_AXIS]);
  901. Serial.print("Z:");
  902. Serial.print(current_position[Z_AXIS]);
  903. Serial.print("E:");
  904. Serial.print(current_position[E_AXIS]);
  905. #ifdef DEBUG_STEPS
  906. Serial.print(" Count X:");
  907. Serial.print(float(count_position[X_AXIS])/axis_steps_per_unit[X_AXIS]);
  908. Serial.print("Y:");
  909. Serial.print(float(count_position[Y_AXIS])/axis_steps_per_unit[Y_AXIS]);
  910. Serial.print("Z:");
  911. Serial.println(float(count_position[Z_AXIS])/axis_steps_per_unit[Z_AXIS]);
  912. #endif
  913. Serial.println("");
  914. break;
  915. case 119: // M119
  916. #if (X_MIN_PIN > -1)
  917. Serial.print("x_min:");
  918. Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
  919. #endif
  920. #if (X_MAX_PIN > -1)
  921. Serial.print("x_max:");
  922. Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
  923. #endif
  924. #if (Y_MIN_PIN > -1)
  925. Serial.print("y_min:");
  926. Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
  927. #endif
  928. #if (Y_MAX_PIN > -1)
  929. Serial.print("y_max:");
  930. Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
  931. #endif
  932. #if (Z_MIN_PIN > -1)
  933. Serial.print("z_min:");
  934. Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
  935. #endif
  936. #if (Z_MAX_PIN > -1)
  937. Serial.print("z_max:");
  938. Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
  939. #endif
  940. Serial.println("");
  941. break;
  942. //TODO: update for all axis, use for loop
  943. case 201: // M201
  944. for(int i=0; i < NUM_AXIS; i++) {
  945. if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
  946. }
  947. break;
  948. #if 0 // Not used for Sprinter/grbl gen6
  949. case 202: // M202
  950. for(int i=0; i < NUM_AXIS; i++) {
  951. if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
  952. }
  953. break;
  954. #endif
  955. case 203: // M203 max feedrate mm/sec
  956. for(int i=0; i < NUM_AXIS; i++) {
  957. if(code_seen(axis_codes[i])) max_feedrate[i] = code_value()*60 ;
  958. }
  959. break;
  960. case 204: // M204 acclereration S normal moves T filmanent only moves
  961. {
  962. if(code_seen('S')) acceleration = code_value() ;
  963. if(code_seen('T')) retract_acceleration = code_value() ;
  964. }
  965. break;
  966. 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
  967. {
  968. if(code_seen('S')) minimumfeedrate = code_value()*60 ;
  969. if(code_seen('T')) mintravelfeedrate = code_value()*60 ;
  970. if(code_seen('B')) minsegmenttime = code_value() ;
  971. if(code_seen('X')) max_xy_jerk = code_value()*60 ;
  972. if(code_seen('Z')) max_z_jerk = code_value()*60 ;
  973. }
  974. break;
  975. case 220: // M220 S<factor in percent>- set speed factor override percentage
  976. {
  977. if(code_seen('S'))
  978. {
  979. feedmultiply = code_value() ;
  980. feedmultiplychanged=true;
  981. }
  982. }
  983. break;
  984. #ifdef PIDTEMP
  985. case 301: // M301
  986. if(code_seen('P')) Kp = code_value();
  987. if(code_seen('I')) Ki = code_value()*PID_dT;
  988. if(code_seen('D')) Kd = code_value()/PID_dT;
  989. // ECHOLN("Kp "<<_FLOAT(Kp,2));
  990. // ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
  991. // ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
  992. // temp_iState_min = 0.0;
  993. // if (Ki!=0) {
  994. // temp_iState_max = PID_INTEGRAL_DRIVE_MAX / (Ki/100.0);
  995. // }
  996. // else temp_iState_max = 1.0e10;
  997. break;
  998. #endif //PIDTEMP
  999. case 500: // Store settings in EEPROM
  1000. {
  1001. StoreSettings();
  1002. }
  1003. break;
  1004. case 501: // Read settings from EEPROM
  1005. {
  1006. RetrieveSettings();
  1007. }
  1008. break;
  1009. case 502: // Revert to default settings
  1010. {
  1011. RetrieveSettings(true);
  1012. }
  1013. break;
  1014. }
  1015. }
  1016. else{
  1017. Serial.println("Unknown command:");
  1018. Serial.println(cmdbuffer[bufindr]);
  1019. }
  1020. ClearToSend();
  1021. }
  1022. void FlushSerialRequestResend()
  1023. {
  1024. //char cmdbuffer[bufindr][100]="Resend:";
  1025. Serial.flush();
  1026. Serial.print("Resend:");
  1027. Serial.println(gcode_LastN + 1);
  1028. ClearToSend();
  1029. }
  1030. void ClearToSend()
  1031. {
  1032. previous_millis_cmd = millis();
  1033. #ifdef SDSUPPORT
  1034. if(fromsd[bufindr])
  1035. return;
  1036. #endif //SDSUPPORT
  1037. Serial.println("ok");
  1038. }
  1039. inline void get_coordinates()
  1040. {
  1041. for(int i=0; i < NUM_AXIS; i++) {
  1042. if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
  1043. else destination[i] = current_position[i]; //Are these else lines really needed?
  1044. }
  1045. if(code_seen('F')) {
  1046. next_feedrate = code_value();
  1047. if(next_feedrate > 0.0) feedrate = next_feedrate;
  1048. }
  1049. }
  1050. void prepare_move()
  1051. {
  1052. plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60.0/100.0);
  1053. for(int i=0; i < NUM_AXIS; i++) {
  1054. current_position[i] = destination[i];
  1055. }
  1056. }
  1057. #ifdef USE_WATCHDOG
  1058. #include <avr/wdt.h>
  1059. #include <avr/interrupt.h>
  1060. volatile uint8_t timeout_seconds=0;
  1061. void(* ctrlaltdelete) (void) = 0;
  1062. ISR(WDT_vect) { //Watchdog timer interrupt, called if main program blocks >1sec
  1063. if(timeout_seconds++ >= WATCHDOG_TIMEOUT)
  1064. {
  1065. kill();
  1066. #ifdef RESET_MANUAL
  1067. LCD_MESSAGE("Please Reset!");
  1068. ECHOLN("echo_: Something is wrong, please turn off the printer.");
  1069. #else
  1070. LCD_MESSAGE("Timeout, resetting!");
  1071. #endif
  1072. //disable watchdog, it will survife reboot.
  1073. WDTCSR |= (1<<WDCE) | (1<<WDE);
  1074. WDTCSR = 0;
  1075. #ifdef RESET_MANUAL
  1076. while(1); //wait for user or serial reset
  1077. #else
  1078. ctrlaltdelete();
  1079. #endif
  1080. }
  1081. }
  1082. /// intialise watch dog with a 1 sec interrupt time
  1083. void wd_init() {
  1084. WDTCSR = (1<<WDCE )|(1<<WDE ); //allow changes
  1085. WDTCSR = (1<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )| (1<<WDP2 )|(1<<WDP1)|(0<<WDP0);
  1086. }
  1087. /// reset watchdog. MUST be called every 1s after init or avr will reset.
  1088. void wd_reset() {
  1089. wdt_reset();
  1090. timeout_seconds=0; //reset counter for resets
  1091. }
  1092. #endif /* USE_WATCHDOG */
  1093. inline void kill()
  1094. {
  1095. #if TEMP_0_PIN > -1
  1096. target_raw[0]=0;
  1097. #if HEATER_0_PIN > -1
  1098. WRITE(HEATER_0_PIN,LOW);
  1099. #endif
  1100. #endif
  1101. #if TEMP_1_PIN > -1
  1102. target_raw[1]=0;
  1103. #if HEATER_1_PIN > -1
  1104. WRITE(HEATER_1_PIN,LOW);
  1105. #endif
  1106. #endif
  1107. #if TEMP_2_PIN > -1
  1108. target_raw[2]=0;
  1109. #if HEATER_2_PIN > -1
  1110. WRITE(HEATER_2_PIN,LOW);
  1111. #endif
  1112. #endif
  1113. disable_x();
  1114. disable_y();
  1115. disable_z();
  1116. disable_e();
  1117. if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
  1118. Serial.println("!! Printer halted. kill() called!!");
  1119. while(1); // Wait for reset
  1120. }
  1121. void manage_inactivity(byte debug) {
  1122. if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time) kill();
  1123. if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) {
  1124. disable_x();
  1125. disable_y();
  1126. disable_z();
  1127. disable_e();
  1128. }
  1129. check_axes_activity();
  1130. }