My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

configuration_store.cpp 29KB

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