My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

configuration_store.cpp 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /**
  2. * configuration_store.cpp
  3. *
  4. * Configuration and EEPROM storage
  5. *
  6. * IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
  7. * in the functions below, also increment the version number. This makes sure that
  8. * the default values are used whenever there is a change to the data, to prevent
  9. * wrong data being written to the variables.
  10. *
  11. * ALSO: Variables in the Store and Retrieve sections must be in the same order.
  12. * If a feature is disabled, some data must still be written that, when read,
  13. * either sets a Sane Default, or results in No Change to the existing value.
  14. *
  15. */
  16. #define EEPROM_VERSION "V20"
  17. /**
  18. * V19 EEPROM Layout:
  19. *
  20. * ver
  21. * M92 XYZE axis_steps_per_unit (x4)
  22. * M203 XYZE max_feedrate (x4)
  23. * M201 XYZE max_acceleration_units_per_sq_second (x4)
  24. * M204 P acceleration
  25. * M204 R retract_acceleration
  26. * M204 T travel_acceleration
  27. * M205 S minimumfeedrate
  28. * M205 T mintravelfeedrate
  29. * M205 B minsegmenttime
  30. * M205 X max_xy_jerk
  31. * M205 Z max_z_jerk
  32. * M205 E max_e_jerk
  33. * M206 XYZ home_offset (x3)
  34. *
  35. * Mesh bed leveling:
  36. * M420 S active
  37. * mesh_num_x (set in firmware)
  38. * mesh_num_y (set in firmware)
  39. * M421 XYZ z_values[][]
  40. * M851 zprobe_zoffset
  41. *
  42. * DELTA:
  43. * M666 XYZ endstop_adj (x3)
  44. * M665 R delta_radius
  45. * M665 L delta_diagonal_rod
  46. * M665 S delta_segments_per_second
  47. *
  48. * ULTIPANEL:
  49. * M145 S0 H plaPreheatHotendTemp
  50. * M145 S0 B plaPreheatHPBTemp
  51. * M145 S0 F plaPreheatFanSpeed
  52. * M145 S1 H absPreheatHotendTemp
  53. * M145 S1 B absPreheatHPBTemp
  54. * M145 S1 F absPreheatFanSpeed
  55. *
  56. * PIDTEMP:
  57. * M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0]
  58. * M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1]
  59. * M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2]
  60. * M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3]
  61. *
  62. * PIDTEMPBED:
  63. * M304 PID bedKp, bedKi, bedKd
  64. *
  65. * DOGLCD:
  66. * M250 C lcd_contrast
  67. *
  68. * SCARA:
  69. * M365 XYZ axis_scaling (x3)
  70. *
  71. * FWRETRACT:
  72. * M209 S autoretract_enabled
  73. * M207 S retract_length
  74. * M207 W retract_length_swap
  75. * M207 F retract_feedrate
  76. * M207 Z retract_zlift
  77. * M208 S retract_recover_length
  78. * M208 W retract_recover_length_swap
  79. * M208 F retract_recover_feedrate
  80. *
  81. * M200 D volumetric_enabled (D>0 makes this enabled)
  82. *
  83. * M200 T D filament_size (x4) (T0..3)
  84. *
  85. * Z_DUAL_ENDSTOPS:
  86. * M666 Z z_endstop_adj
  87. *
  88. */
  89. #include "Marlin.h"
  90. #include "language.h"
  91. #include "planner.h"
  92. #include "temperature.h"
  93. #include "ultralcd.h"
  94. #include "configuration_store.h"
  95. #ifdef MESH_BED_LEVELING
  96. #include "mesh_bed_leveling.h"
  97. #endif
  98. void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
  99. uint8_t c;
  100. while(size--) {
  101. eeprom_write_byte((unsigned char*)pos, *value);
  102. c = eeprom_read_byte((unsigned char*)pos);
  103. if (c != *value) {
  104. SERIAL_ECHO_START;
  105. SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
  106. }
  107. pos++;
  108. value++;
  109. };
  110. }
  111. void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
  112. do {
  113. *value = eeprom_read_byte((unsigned char*)pos);
  114. pos++;
  115. value++;
  116. } while (--size);
  117. }
  118. #define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value))
  119. #define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value))
  120. /**
  121. * Store Configuration Settings - M500
  122. */
  123. #define DUMMY_PID_VALUE 3000.0f
  124. #define EEPROM_OFFSET 100
  125. #ifdef EEPROM_SETTINGS
  126. void Config_StoreSettings() {
  127. float dummy = 0.0f;
  128. char ver[4] = "000";
  129. int i = EEPROM_OFFSET;
  130. EEPROM_WRITE_VAR(i, ver); // invalidate data first
  131. EEPROM_WRITE_VAR(i, axis_steps_per_unit);
  132. EEPROM_WRITE_VAR(i, max_feedrate);
  133. EEPROM_WRITE_VAR(i, max_acceleration_units_per_sq_second);
  134. EEPROM_WRITE_VAR(i, acceleration);
  135. EEPROM_WRITE_VAR(i, retract_acceleration);
  136. EEPROM_WRITE_VAR(i, travel_acceleration);
  137. EEPROM_WRITE_VAR(i, minimumfeedrate);
  138. EEPROM_WRITE_VAR(i, mintravelfeedrate);
  139. EEPROM_WRITE_VAR(i, minsegmenttime);
  140. EEPROM_WRITE_VAR(i, max_xy_jerk);
  141. EEPROM_WRITE_VAR(i, max_z_jerk);
  142. EEPROM_WRITE_VAR(i, max_e_jerk);
  143. EEPROM_WRITE_VAR(i, home_offset);
  144. uint8_t mesh_num_x = 3;
  145. uint8_t mesh_num_y = 3;
  146. #ifdef MESH_BED_LEVELING
  147. // Compile time test that sizeof(mbl.z_values) is as expected
  148. typedef char c_assert[(sizeof(mbl.z_values) == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS*sizeof(dummy)) ? 1 : -1];
  149. mesh_num_x = MESH_NUM_X_POINTS;
  150. mesh_num_y = MESH_NUM_Y_POINTS;
  151. EEPROM_WRITE_VAR(i, mbl.active);
  152. EEPROM_WRITE_VAR(i, mesh_num_x);
  153. EEPROM_WRITE_VAR(i, mesh_num_y);
  154. EEPROM_WRITE_VAR(i, mbl.z_values);
  155. #else
  156. uint8_t dummy_uint8 = 0;
  157. EEPROM_WRITE_VAR(i, dummy_uint8);
  158. EEPROM_WRITE_VAR(i, mesh_num_x);
  159. EEPROM_WRITE_VAR(i, mesh_num_y);
  160. dummy = 0.0f;
  161. for (int q=0; q<mesh_num_x*mesh_num_y; q++) EEPROM_WRITE_VAR(i, dummy);
  162. #endif // MESH_BED_LEVELING
  163. #ifndef ENABLE_AUTO_BED_LEVELING
  164. float zprobe_zoffset = 0;
  165. #endif
  166. EEPROM_WRITE_VAR(i, zprobe_zoffset);
  167. #ifdef DELTA
  168. EEPROM_WRITE_VAR(i, endstop_adj); // 3 floats
  169. EEPROM_WRITE_VAR(i, delta_radius); // 1 float
  170. EEPROM_WRITE_VAR(i, delta_diagonal_rod); // 1 float
  171. EEPROM_WRITE_VAR(i, delta_segments_per_second); // 1 float
  172. #elif defined(Z_DUAL_ENDSTOPS)
  173. EEPROM_WRITE_VAR(i, z_endstop_adj); // 1 floats
  174. dummy = 0.0f;
  175. for (int q=5; q--;) EEPROM_WRITE_VAR(i, dummy);
  176. #else
  177. dummy = 0.0f;
  178. for (int q=6; q--;) EEPROM_WRITE_VAR(i, dummy);
  179. #endif
  180. #ifndef ULTIPANEL
  181. int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED,
  182. absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  183. #endif // !ULTIPANEL
  184. EEPROM_WRITE_VAR(i, plaPreheatHotendTemp);
  185. EEPROM_WRITE_VAR(i, plaPreheatHPBTemp);
  186. EEPROM_WRITE_VAR(i, plaPreheatFanSpeed);
  187. EEPROM_WRITE_VAR(i, absPreheatHotendTemp);
  188. EEPROM_WRITE_VAR(i, absPreheatHPBTemp);
  189. EEPROM_WRITE_VAR(i, absPreheatFanSpeed);
  190. for (int e = 0; e < 4; e++) {
  191. #ifdef PIDTEMP
  192. if (e < EXTRUDERS) {
  193. EEPROM_WRITE_VAR(i, PID_PARAM(Kp, e));
  194. EEPROM_WRITE_VAR(i, PID_PARAM(Ki, e));
  195. EEPROM_WRITE_VAR(i, PID_PARAM(Kd, e));
  196. #ifdef PID_ADD_EXTRUSION_RATE
  197. EEPROM_WRITE_VAR(i, PID_PARAM(Kc, e));
  198. #else
  199. dummy = 1.0f; // 1.0 = default kc
  200. EEPROM_WRITE_VAR(i, dummy);
  201. #endif
  202. }
  203. else
  204. #endif // !PIDTEMP
  205. {
  206. dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
  207. EEPROM_WRITE_VAR(i, dummy);
  208. dummy = 0.0f;
  209. for (int q = 3; q--;) EEPROM_WRITE_VAR(i, dummy);
  210. }
  211. } // Extruders Loop
  212. #ifndef PIDTEMPBED
  213. float bedKp = DUMMY_PID_VALUE, bedKi = DUMMY_PID_VALUE, bedKd = DUMMY_PID_VALUE;
  214. #endif
  215. EEPROM_WRITE_VAR(i, bedKp);
  216. EEPROM_WRITE_VAR(i, bedKi);
  217. EEPROM_WRITE_VAR(i, bedKd);
  218. #ifndef HAS_LCD_CONTRAST
  219. int lcd_contrast = 32;
  220. #endif
  221. EEPROM_WRITE_VAR(i, lcd_contrast);
  222. #ifdef SCARA
  223. EEPROM_WRITE_VAR(i, axis_scaling); // 3 floats
  224. #else
  225. dummy = 1.0f;
  226. EEPROM_WRITE_VAR(i, dummy);
  227. #endif
  228. #ifdef FWRETRACT
  229. EEPROM_WRITE_VAR(i, autoretract_enabled);
  230. EEPROM_WRITE_VAR(i, retract_length);
  231. #if EXTRUDERS > 1
  232. EEPROM_WRITE_VAR(i, retract_length_swap);
  233. #else
  234. dummy = 0.0f;
  235. EEPROM_WRITE_VAR(i, dummy);
  236. #endif
  237. EEPROM_WRITE_VAR(i, retract_feedrate);
  238. EEPROM_WRITE_VAR(i, retract_zlift);
  239. EEPROM_WRITE_VAR(i, retract_recover_length);
  240. #if EXTRUDERS > 1
  241. EEPROM_WRITE_VAR(i, retract_recover_length_swap);
  242. #else
  243. dummy = 0.0f;
  244. EEPROM_WRITE_VAR(i, dummy);
  245. #endif
  246. EEPROM_WRITE_VAR(i, retract_recover_feedrate);
  247. #endif // FWRETRACT
  248. EEPROM_WRITE_VAR(i, volumetric_enabled);
  249. // Save filament sizes
  250. for (int q = 0; q < 4; q++) {
  251. if (q < EXTRUDERS) dummy = filament_size[q];
  252. EEPROM_WRITE_VAR(i, dummy);
  253. }
  254. char ver2[4] = EEPROM_VERSION;
  255. int j = EEPROM_OFFSET;
  256. EEPROM_WRITE_VAR(j, ver2); // validate data
  257. // Report storage size
  258. SERIAL_ECHO_START;
  259. SERIAL_ECHOPAIR("Settings Stored (", (unsigned long)i);
  260. SERIAL_ECHOLNPGM(" bytes)");
  261. }
  262. /**
  263. * Retrieve Configuration Settings - M501
  264. */
  265. void Config_RetrieveSettings() {
  266. int i = EEPROM_OFFSET;
  267. char stored_ver[4];
  268. char ver[4] = EEPROM_VERSION;
  269. EEPROM_READ_VAR(i, stored_ver); //read stored version
  270. // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  271. if (strncmp(ver, stored_ver, 3) != 0) {
  272. Config_ResetDefault();
  273. }
  274. else {
  275. float dummy = 0;
  276. // version number match
  277. EEPROM_READ_VAR(i, axis_steps_per_unit);
  278. EEPROM_READ_VAR(i, max_feedrate);
  279. EEPROM_READ_VAR(i, max_acceleration_units_per_sq_second);
  280. // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
  281. reset_acceleration_rates();
  282. EEPROM_READ_VAR(i, acceleration);
  283. EEPROM_READ_VAR(i, retract_acceleration);
  284. EEPROM_READ_VAR(i, travel_acceleration);
  285. EEPROM_READ_VAR(i, minimumfeedrate);
  286. EEPROM_READ_VAR(i, mintravelfeedrate);
  287. EEPROM_READ_VAR(i, minsegmenttime);
  288. EEPROM_READ_VAR(i, max_xy_jerk);
  289. EEPROM_READ_VAR(i, max_z_jerk);
  290. EEPROM_READ_VAR(i, max_e_jerk);
  291. EEPROM_READ_VAR(i, home_offset);
  292. uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
  293. EEPROM_READ_VAR(i, dummy_uint8);
  294. EEPROM_READ_VAR(i, mesh_num_x);
  295. EEPROM_READ_VAR(i, mesh_num_y);
  296. #ifdef MESH_BED_LEVELING
  297. mbl.active = dummy_uint8;
  298. if (mesh_num_x == MESH_NUM_X_POINTS && mesh_num_y == MESH_NUM_Y_POINTS) {
  299. EEPROM_READ_VAR(i, mbl.z_values);
  300. } else {
  301. mbl.reset();
  302. for (int q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ_VAR(i, dummy);
  303. }
  304. #else
  305. for (int q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ_VAR(i, dummy);
  306. #endif // MESH_BED_LEVELING
  307. #ifndef ENABLE_AUTO_BED_LEVELING
  308. float zprobe_zoffset = 0;
  309. #endif
  310. EEPROM_READ_VAR(i, zprobe_zoffset);
  311. #ifdef DELTA
  312. EEPROM_READ_VAR(i, endstop_adj); // 3 floats
  313. EEPROM_READ_VAR(i, delta_radius); // 1 float
  314. EEPROM_READ_VAR(i, delta_diagonal_rod); // 1 float
  315. EEPROM_READ_VAR(i, delta_segments_per_second); // 1 float
  316. #elif defined(Z_DUAL_ENDSTOPS)
  317. EEPROM_READ_VAR(i, z_endstop_adj);
  318. dummy = 0.0f;
  319. for (int q=5; q--;) EEPROM_READ_VAR(i, dummy);
  320. #else
  321. dummy = 0.0f;
  322. for (int q=6; q--;) EEPROM_READ_VAR(i, dummy);
  323. #endif
  324. #ifndef ULTIPANEL
  325. int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed,
  326. absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
  327. #endif
  328. EEPROM_READ_VAR(i, plaPreheatHotendTemp);
  329. EEPROM_READ_VAR(i, plaPreheatHPBTemp);
  330. EEPROM_READ_VAR(i, plaPreheatFanSpeed);
  331. EEPROM_READ_VAR(i, absPreheatHotendTemp);
  332. EEPROM_READ_VAR(i, absPreheatHPBTemp);
  333. EEPROM_READ_VAR(i, absPreheatFanSpeed);
  334. #ifdef PIDTEMP
  335. for (int e = 0; e < 4; e++) { // 4 = max extruders currently supported by Marlin
  336. EEPROM_READ_VAR(i, dummy); // Kp
  337. if (e < EXTRUDERS && dummy != DUMMY_PID_VALUE) {
  338. // do not need to scale PID values as the values in EEPROM are already scaled
  339. PID_PARAM(Kp, e) = dummy;
  340. EEPROM_READ_VAR(i, PID_PARAM(Ki, e));
  341. EEPROM_READ_VAR(i, PID_PARAM(Kd, e));
  342. #ifdef PID_ADD_EXTRUSION_RATE
  343. EEPROM_READ_VAR(i, PID_PARAM(Kc, e));
  344. #else
  345. EEPROM_READ_VAR(i, dummy);
  346. #endif
  347. }
  348. else {
  349. for (int q=3; q--;) EEPROM_READ_VAR(i, dummy); // Ki, Kd, Kc
  350. }
  351. }
  352. #else // !PIDTEMP
  353. // 4 x 4 = 16 slots for PID parameters
  354. for (int q=16; q--;) EEPROM_READ_VAR(i, dummy); // 4x Kp, Ki, Kd, Kc
  355. #endif // !PIDTEMP
  356. #ifndef PIDTEMPBED
  357. float bedKp, bedKi, bedKd;
  358. #endif
  359. EEPROM_READ_VAR(i, dummy); // bedKp
  360. if (dummy != DUMMY_PID_VALUE) {
  361. bedKp = dummy;
  362. EEPROM_READ_VAR(i, bedKi);
  363. EEPROM_READ_VAR(i, bedKd);
  364. }
  365. else {
  366. for (int q=2; q--;) EEPROM_READ_VAR(i, dummy); // bedKi, bedKd
  367. }
  368. #ifndef HAS_LCD_CONTRAST
  369. int lcd_contrast;
  370. #endif
  371. EEPROM_READ_VAR(i, lcd_contrast);
  372. #ifdef SCARA
  373. EEPROM_READ_VAR(i, axis_scaling); // 3 floats
  374. #else
  375. EEPROM_READ_VAR(i, dummy);
  376. #endif
  377. #ifdef FWRETRACT
  378. EEPROM_READ_VAR(i, autoretract_enabled);
  379. EEPROM_READ_VAR(i, retract_length);
  380. #if EXTRUDERS > 1
  381. EEPROM_READ_VAR(i, retract_length_swap);
  382. #else
  383. EEPROM_READ_VAR(i, dummy);
  384. #endif
  385. EEPROM_READ_VAR(i, retract_feedrate);
  386. EEPROM_READ_VAR(i, retract_zlift);
  387. EEPROM_READ_VAR(i, retract_recover_length);
  388. #if EXTRUDERS > 1
  389. EEPROM_READ_VAR(i, retract_recover_length_swap);
  390. #else
  391. EEPROM_READ_VAR(i, dummy);
  392. #endif
  393. EEPROM_READ_VAR(i, retract_recover_feedrate);
  394. #endif // FWRETRACT
  395. EEPROM_READ_VAR(i, volumetric_enabled);
  396. for (int q = 0; q < 4; q++) {
  397. EEPROM_READ_VAR(i, dummy);
  398. if (q < EXTRUDERS) filament_size[q] = dummy;
  399. }
  400. calculate_volumetric_multipliers();
  401. // Call updatePID (similar to when we have processed M301)
  402. updatePID();
  403. // Report settings retrieved and length
  404. SERIAL_ECHO_START;
  405. SERIAL_ECHO(ver);
  406. SERIAL_ECHOPAIR(" stored settings retrieved (", (unsigned long)i);
  407. SERIAL_ECHOLNPGM(" bytes)");
  408. }
  409. #ifdef EEPROM_CHITCHAT
  410. Config_PrintSettings();
  411. #endif
  412. }
  413. #endif // EEPROM_SETTINGS
  414. /**
  415. * Reset Configuration Settings - M502
  416. */
  417. void Config_ResetDefault() {
  418. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  419. float tmp2[] = DEFAULT_MAX_FEEDRATE;
  420. long tmp3[] = DEFAULT_MAX_ACCELERATION;
  421. for (uint16_t i = 0; i < NUM_AXIS; i++) {
  422. axis_steps_per_unit[i] = tmp1[i];
  423. max_feedrate[i] = tmp2[i];
  424. max_acceleration_units_per_sq_second[i] = tmp3[i];
  425. #ifdef SCARA
  426. if (i < sizeof(axis_scaling) / sizeof(*axis_scaling))
  427. axis_scaling[i] = 1;
  428. #endif
  429. }
  430. // steps per sq second need to be updated to agree with the units per sq second
  431. reset_acceleration_rates();
  432. acceleration = DEFAULT_ACCELERATION;
  433. retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  434. travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  435. minimumfeedrate = DEFAULT_MINIMUMFEEDRATE;
  436. minsegmenttime = DEFAULT_MINSEGMENTTIME;
  437. mintravelfeedrate = DEFAULT_MINTRAVELFEEDRATE;
  438. max_xy_jerk = DEFAULT_XYJERK;
  439. max_z_jerk = DEFAULT_ZJERK;
  440. max_e_jerk = DEFAULT_EJERK;
  441. home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
  442. #ifdef MESH_BED_LEVELING
  443. mbl.active = 0;
  444. #endif
  445. #ifdef ENABLE_AUTO_BED_LEVELING
  446. zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
  447. #endif
  448. #ifdef DELTA
  449. endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0;
  450. delta_radius = DELTA_RADIUS;
  451. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  452. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  453. recalc_delta_settings(delta_radius, delta_diagonal_rod);
  454. #elif defined(Z_DUAL_ENDSTOPS)
  455. z_endstop_adj = 0;
  456. #endif
  457. #ifdef ULTIPANEL
  458. plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
  459. plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
  460. plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  461. absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
  462. absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
  463. absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  464. #endif
  465. #ifdef HAS_LCD_CONTRAST
  466. lcd_contrast = DEFAULT_LCD_CONTRAST;
  467. #endif
  468. #ifdef PIDTEMP
  469. #ifdef PID_PARAMS_PER_EXTRUDER
  470. for (int e = 0; e < EXTRUDERS; e++)
  471. #else
  472. int e = 0; // only need to write once
  473. #endif
  474. {
  475. PID_PARAM(Kp, e) = DEFAULT_Kp;
  476. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  477. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  478. #ifdef PID_ADD_EXTRUSION_RATE
  479. PID_PARAM(Kc, e) = DEFAULT_Kc;
  480. #endif
  481. }
  482. // call updatePID (similar to when we have processed M301)
  483. updatePID();
  484. #endif // PIDTEMP
  485. #ifdef PIDTEMPBED
  486. bedKp = DEFAULT_bedKp;
  487. bedKi = scalePID_i(DEFAULT_bedKi);
  488. bedKd = scalePID_d(DEFAULT_bedKd);
  489. #endif
  490. #ifdef FWRETRACT
  491. autoretract_enabled = false;
  492. retract_length = RETRACT_LENGTH;
  493. #if EXTRUDERS > 1
  494. retract_length_swap = RETRACT_LENGTH_SWAP;
  495. #endif
  496. retract_feedrate = RETRACT_FEEDRATE;
  497. retract_zlift = RETRACT_ZLIFT;
  498. retract_recover_length = RETRACT_RECOVER_LENGTH;
  499. #if EXTRUDERS > 1
  500. retract_recover_length_swap = RETRACT_RECOVER_LENGTH_SWAP;
  501. #endif
  502. retract_recover_feedrate = RETRACT_RECOVER_FEEDRATE;
  503. #endif
  504. volumetric_enabled = false;
  505. filament_size[0] = DEFAULT_NOMINAL_FILAMENT_DIA;
  506. #if EXTRUDERS > 1
  507. filament_size[1] = DEFAULT_NOMINAL_FILAMENT_DIA;
  508. #if EXTRUDERS > 2
  509. filament_size[2] = DEFAULT_NOMINAL_FILAMENT_DIA;
  510. #if EXTRUDERS > 3
  511. filament_size[3] = DEFAULT_NOMINAL_FILAMENT_DIA;
  512. #endif
  513. #endif
  514. #endif
  515. calculate_volumetric_multipliers();
  516. SERIAL_ECHO_START;
  517. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  518. }
  519. #ifndef DISABLE_M503
  520. /**
  521. * Print Configuration Settings - M503
  522. */
  523. #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START; }while(0)
  524. void Config_PrintSettings(bool forReplay) {
  525. // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
  526. CONFIG_ECHO_START;
  527. if (!forReplay) {
  528. SERIAL_ECHOLNPGM("Steps per unit:");
  529. CONFIG_ECHO_START;
  530. }
  531. SERIAL_ECHOPAIR(" M92 X", axis_steps_per_unit[X_AXIS]);
  532. SERIAL_ECHOPAIR(" Y", axis_steps_per_unit[Y_AXIS]);
  533. SERIAL_ECHOPAIR(" Z", axis_steps_per_unit[Z_AXIS]);
  534. SERIAL_ECHOPAIR(" E", axis_steps_per_unit[E_AXIS]);
  535. SERIAL_EOL;
  536. CONFIG_ECHO_START;
  537. #ifdef SCARA
  538. if (!forReplay) {
  539. SERIAL_ECHOLNPGM("Scaling factors:");
  540. CONFIG_ECHO_START;
  541. }
  542. SERIAL_ECHOPAIR(" M365 X", axis_scaling[X_AXIS]);
  543. SERIAL_ECHOPAIR(" Y", axis_scaling[Y_AXIS]);
  544. SERIAL_ECHOPAIR(" Z", axis_scaling[Z_AXIS]);
  545. SERIAL_EOL;
  546. CONFIG_ECHO_START;
  547. #endif // SCARA
  548. if (!forReplay) {
  549. SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
  550. CONFIG_ECHO_START;
  551. }
  552. SERIAL_ECHOPAIR(" M203 X", max_feedrate[X_AXIS]);
  553. SERIAL_ECHOPAIR(" Y", max_feedrate[Y_AXIS]);
  554. SERIAL_ECHOPAIR(" Z", max_feedrate[Z_AXIS]);
  555. SERIAL_ECHOPAIR(" E", max_feedrate[E_AXIS]);
  556. SERIAL_EOL;
  557. CONFIG_ECHO_START;
  558. if (!forReplay) {
  559. SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
  560. CONFIG_ECHO_START;
  561. }
  562. SERIAL_ECHOPAIR(" M201 X", max_acceleration_units_per_sq_second[X_AXIS]);
  563. SERIAL_ECHOPAIR(" Y", max_acceleration_units_per_sq_second[Y_AXIS]);
  564. SERIAL_ECHOPAIR(" Z", max_acceleration_units_per_sq_second[Z_AXIS]);
  565. SERIAL_ECHOPAIR(" E", max_acceleration_units_per_sq_second[E_AXIS]);
  566. SERIAL_EOL;
  567. CONFIG_ECHO_START;
  568. if (!forReplay) {
  569. SERIAL_ECHOLNPGM("Accelerations: P=printing, R=retract and T=travel");
  570. CONFIG_ECHO_START;
  571. }
  572. SERIAL_ECHOPAIR(" M204 P", acceleration);
  573. SERIAL_ECHOPAIR(" R", retract_acceleration);
  574. SERIAL_ECHOPAIR(" T", travel_acceleration);
  575. SERIAL_EOL;
  576. CONFIG_ECHO_START;
  577. if (!forReplay) {
  578. SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)");
  579. CONFIG_ECHO_START;
  580. }
  581. SERIAL_ECHOPAIR(" M205 S", minimumfeedrate);
  582. SERIAL_ECHOPAIR(" T", mintravelfeedrate);
  583. SERIAL_ECHOPAIR(" B", minsegmenttime);
  584. SERIAL_ECHOPAIR(" X", max_xy_jerk);
  585. SERIAL_ECHOPAIR(" Z", max_z_jerk);
  586. SERIAL_ECHOPAIR(" E", max_e_jerk);
  587. SERIAL_EOL;
  588. CONFIG_ECHO_START;
  589. if (!forReplay) {
  590. SERIAL_ECHOLNPGM("Home offset (mm):");
  591. CONFIG_ECHO_START;
  592. }
  593. SERIAL_ECHOPAIR(" M206 X", home_offset[X_AXIS]);
  594. SERIAL_ECHOPAIR(" Y", home_offset[Y_AXIS]);
  595. SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
  596. SERIAL_EOL;
  597. #ifdef MESH_BED_LEVELING
  598. if (!forReplay) {
  599. SERIAL_ECHOLNPGM("Mesh bed leveling:");
  600. CONFIG_ECHO_START;
  601. }
  602. SERIAL_ECHOPAIR(" M420 S", (unsigned long)mbl.active);
  603. SERIAL_ECHOPAIR(" X", (unsigned long)MESH_NUM_X_POINTS);
  604. SERIAL_ECHOPAIR(" Y", (unsigned long)MESH_NUM_Y_POINTS);
  605. SERIAL_EOL;
  606. for (int y=0; y<MESH_NUM_Y_POINTS; y++) {
  607. for (int x=0; x<MESH_NUM_X_POINTS; x++) {
  608. CONFIG_ECHO_START;
  609. SERIAL_ECHOPAIR(" M421 X", mbl.get_x(x));
  610. SERIAL_ECHOPAIR(" Y", mbl.get_y(y));
  611. SERIAL_ECHOPAIR(" Z", mbl.z_values[y][x]);
  612. SERIAL_EOL;
  613. }
  614. }
  615. #endif
  616. #ifdef DELTA
  617. CONFIG_ECHO_START;
  618. if (!forReplay) {
  619. SERIAL_ECHOLNPGM("Endstop adjustment (mm):");
  620. CONFIG_ECHO_START;
  621. }
  622. SERIAL_ECHOPAIR(" M666 X", endstop_adj[X_AXIS]);
  623. SERIAL_ECHOPAIR(" Y", endstop_adj[Y_AXIS]);
  624. SERIAL_ECHOPAIR(" Z", endstop_adj[Z_AXIS]);
  625. SERIAL_EOL;
  626. CONFIG_ECHO_START;
  627. SERIAL_ECHOLNPGM("Delta settings: L=delta_diagonal_rod, R=delta_radius, S=delta_segments_per_second");
  628. CONFIG_ECHO_START;
  629. SERIAL_ECHOPAIR(" M665 L", delta_diagonal_rod);
  630. SERIAL_ECHOPAIR(" R", delta_radius);
  631. SERIAL_ECHOPAIR(" S", delta_segments_per_second);
  632. SERIAL_EOL;
  633. #elif defined(Z_DUAL_ENDSTOPS)
  634. CONFIG_ECHO_START;
  635. if (!forReplay) {
  636. SERIAL_ECHOLNPGM("Z2 Endstop adjustment (mm):");
  637. CONFIG_ECHO_START;
  638. }
  639. SERIAL_ECHOPAIR(" M666 Z", z_endstop_adj);
  640. SERIAL_EOL;
  641. #endif // DELTA
  642. #ifdef ULTIPANEL
  643. CONFIG_ECHO_START;
  644. if (!forReplay) {
  645. SERIAL_ECHOLNPGM("Material heatup parameters:");
  646. CONFIG_ECHO_START;
  647. }
  648. SERIAL_ECHOPAIR(" M145 M0 H", (unsigned long)plaPreheatHotendTemp);
  649. SERIAL_ECHOPAIR(" B", (unsigned long)plaPreheatHPBTemp);
  650. SERIAL_ECHOPAIR(" F", (unsigned long)plaPreheatFanSpeed);
  651. SERIAL_EOL;
  652. CONFIG_ECHO_START;
  653. SERIAL_ECHOPAIR(" M145 M1 H", (unsigned long)absPreheatHotendTemp);
  654. SERIAL_ECHOPAIR(" B", (unsigned long)absPreheatHPBTemp);
  655. SERIAL_ECHOPAIR(" F", (unsigned long)absPreheatFanSpeed);
  656. SERIAL_EOL;
  657. #endif // ULTIPANEL
  658. #if defined(PIDTEMP) || defined(PIDTEMPBED)
  659. CONFIG_ECHO_START;
  660. if (!forReplay) {
  661. SERIAL_ECHOLNPGM("PID settings:");
  662. }
  663. #ifdef PIDTEMP
  664. #if EXTRUDERS > 1
  665. if (forReplay) {
  666. for (uint8_t i = 0; i < EXTRUDERS; i++) {
  667. CONFIG_ECHO_START;
  668. SERIAL_ECHOPAIR(" M301 E", (unsigned long)i);
  669. SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, i));
  670. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, i)));
  671. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, i)));
  672. #ifdef PID_ADD_EXTRUSION_RATE
  673. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, i));
  674. #endif
  675. SERIAL_EOL;
  676. }
  677. }
  678. else
  679. #endif // EXTRUDERS > 1
  680. // !forReplay || EXTRUDERS == 1
  681. {
  682. CONFIG_ECHO_START;
  683. SERIAL_ECHOPAIR(" M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echo values for E0
  684. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
  685. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
  686. #ifdef PID_ADD_EXTRUSION_RATE
  687. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
  688. #endif
  689. SERIAL_EOL;
  690. }
  691. #endif // PIDTEMP
  692. #ifdef PIDTEMPBED
  693. CONFIG_ECHO_START;
  694. SERIAL_ECHOPAIR(" M304 P", bedKp);
  695. SERIAL_ECHOPAIR(" I", unscalePID_i(bedKi));
  696. SERIAL_ECHOPAIR(" D", unscalePID_d(bedKd));
  697. SERIAL_EOL;
  698. #endif
  699. #endif // PIDTEMP || PIDTEMPBED
  700. #ifdef HAS_LCD_CONTRAST
  701. CONFIG_ECHO_START;
  702. if (!forReplay) {
  703. SERIAL_ECHOLNPGM("LCD Contrast:");
  704. CONFIG_ECHO_START;
  705. }
  706. SERIAL_ECHOPAIR(" M250 C", (unsigned long)lcd_contrast);
  707. SERIAL_EOL;
  708. #endif
  709. #ifdef FWRETRACT
  710. CONFIG_ECHO_START;
  711. if (!forReplay) {
  712. SERIAL_ECHOLNPGM("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)");
  713. CONFIG_ECHO_START;
  714. }
  715. SERIAL_ECHOPAIR(" M207 S", retract_length);
  716. #if EXTRUDERS > 1
  717. SERIAL_ECHOPAIR(" W", retract_length_swap);
  718. #endif
  719. SERIAL_ECHOPAIR(" F", retract_feedrate*60);
  720. SERIAL_ECHOPAIR(" Z", retract_zlift);
  721. SERIAL_EOL;
  722. CONFIG_ECHO_START;
  723. if (!forReplay) {
  724. SERIAL_ECHOLNPGM("Recover: S=Extra length (mm) F:Speed (mm/m)");
  725. CONFIG_ECHO_START;
  726. }
  727. SERIAL_ECHOPAIR(" M208 S", retract_recover_length);
  728. #if EXTRUDERS > 1
  729. SERIAL_ECHOPAIR(" W", retract_recover_length_swap);
  730. #endif
  731. SERIAL_ECHOPAIR(" F", retract_recover_feedrate*60);
  732. SERIAL_EOL;
  733. CONFIG_ECHO_START;
  734. if (!forReplay) {
  735. SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret extrude-only moves as retracts or recoveries");
  736. CONFIG_ECHO_START;
  737. }
  738. SERIAL_ECHOPAIR(" M209 S", (unsigned long)(autoretract_enabled ? 1 : 0));
  739. SERIAL_EOL;
  740. #endif // FWRETRACT
  741. if (volumetric_enabled) {
  742. if (!forReplay) {
  743. CONFIG_ECHO_START;
  744. SERIAL_ECHOLNPGM("Filament settings:");
  745. }
  746. CONFIG_ECHO_START;
  747. SERIAL_ECHOPAIR(" M200 D", filament_size[0]);
  748. SERIAL_EOL;
  749. #if EXTRUDERS > 1
  750. CONFIG_ECHO_START;
  751. SERIAL_ECHOPAIR(" M200 T1 D", filament_size[1]);
  752. SERIAL_EOL;
  753. #if EXTRUDERS > 2
  754. CONFIG_ECHO_START;
  755. SERIAL_ECHOPAIR(" M200 T2 D", filament_size[2]);
  756. SERIAL_EOL;
  757. #if EXTRUDERS > 3
  758. CONFIG_ECHO_START;
  759. SERIAL_ECHOPAIR(" M200 T3 D", filament_size[3]);
  760. SERIAL_EOL;
  761. #endif
  762. #endif
  763. #endif
  764. } else {
  765. if (!forReplay) {
  766. CONFIG_ECHO_START;
  767. SERIAL_ECHOLNPGM("Filament settings: Disabled");
  768. }
  769. }
  770. #ifdef ENABLE_AUTO_BED_LEVELING
  771. #ifdef CUSTOM_M_CODES
  772. if (!forReplay) {
  773. CONFIG_ECHO_START;
  774. SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
  775. }
  776. CONFIG_ECHO_START;
  777. SERIAL_ECHOPAIR(" M" STRINGIFY(CUSTOM_M_CODE_SET_Z_PROBE_OFFSET) " Z", zprobe_zoffset);
  778. #else
  779. if (!forReplay) {
  780. CONFIG_ECHO_START;
  781. SERIAL_ECHOPAIR("Z-Probe Offset (mm):", zprobe_zoffset);
  782. }
  783. #endif
  784. SERIAL_EOL;
  785. #endif
  786. }
  787. #endif // !DISABLE_M503