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

configuration_store.cpp 27KB

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